Skip to content

Commit d1adc4f

Browse files
feat: Add Alibaba API credential and ChatAlibabaTongyi node (#3360)
* feat: Add Alibaba API credential and ChatAlibabaTongyi node * lint fix * Add chatAlibabaTongyi model to models.json and chat models --------- Co-authored-by: Henry Heng <[email protected]>
1 parent 1d193b4 commit d1adc4f

File tree

5 files changed

+120
-0
lines changed

5 files changed

+120
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { INodeParams, INodeCredential } from '../src/Interface'
2+
3+
class AlibabaApi implements INodeCredential {
4+
label: string
5+
name: string
6+
version: number
7+
inputs: INodeParams[]
8+
9+
constructor() {
10+
this.label = 'Alibaba API'
11+
this.name = 'AlibabaApi'
12+
this.version = 1.0
13+
this.inputs = [
14+
{
15+
label: 'Alibaba Api Key',
16+
name: 'alibabaApiKey',
17+
type: 'password'
18+
}
19+
]
20+
}
21+
}
22+
23+
module.exports = { credClass: AlibabaApi }

Diff for: packages/components/models.json

+9
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,15 @@
411411
}
412412
]
413413
},
414+
{
415+
"name": "chatAlibabaTongyi",
416+
"models": [
417+
{
418+
"label": "qwen-plus",
419+
"name": "qwen-plus"
420+
}
421+
]
422+
},
414423
{
415424
"name": "chatGoogleVertexAI",
416425
"models": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { BaseCache } from '@langchain/core/caches'
2+
import { ChatAlibabaTongyi } from '@langchain/community/chat_models/alibaba_tongyi'
3+
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
4+
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
5+
import { BaseChatModelParams } from '@langchain/core/language_models/chat_models'
6+
7+
class ChatAlibabaTongyi_ChatModels implements INode {
8+
label: string
9+
name: string
10+
version: number
11+
type: string
12+
icon: string
13+
category: string
14+
description: string
15+
baseClasses: string[]
16+
credential: INodeParams
17+
inputs: INodeParams[]
18+
19+
constructor() {
20+
this.label = 'ChatAlibabaTongyi'
21+
this.name = 'chatAlibabaTongyi'
22+
this.version = 1.0
23+
this.type = 'ChatAlibabaTongyi'
24+
this.icon = 'alibaba-svgrepo-com.svg'
25+
this.category = 'Chat Models'
26+
this.description = 'Wrapper around Alibaba Tongyi Chat Endpoints'
27+
this.baseClasses = [this.type, ...getBaseClasses(ChatAlibabaTongyi)]
28+
this.credential = {
29+
label: 'Connect Credential',
30+
name: 'credential',
31+
type: 'credential',
32+
credentialNames: ['AlibabaApi']
33+
}
34+
this.inputs = [
35+
{
36+
label: 'Cache',
37+
name: 'cache',
38+
type: 'BaseCache',
39+
optional: true
40+
},
41+
{
42+
label: 'Model',
43+
name: 'modelName',
44+
type: 'string',
45+
placeholder: 'qwen-plus'
46+
},
47+
{
48+
label: 'Temperature',
49+
name: 'temperature',
50+
type: 'number',
51+
step: 0.1,
52+
default: 0.9,
53+
optional: true
54+
}
55+
]
56+
}
57+
58+
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
59+
const cache = nodeData.inputs?.cache as BaseCache
60+
const temperature = nodeData.inputs?.temperature as string
61+
const modelName = nodeData.inputs?.modelName as string
62+
63+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
64+
const alibabaApiKey = getCredentialParam('alibabaApiKey', credentialData, nodeData)
65+
66+
const obj: Partial<ChatAlibabaTongyi> & BaseChatModelParams = {
67+
streaming: true,
68+
alibabaApiKey,
69+
model: modelName,
70+
temperature: temperature ? parseFloat(temperature) : undefined
71+
}
72+
if (cache) obj.cache = cache
73+
74+
const model = new ChatAlibabaTongyi(obj)
75+
return model
76+
}
77+
}
78+
79+
module.exports = { nodeClass: ChatAlibabaTongyi_ChatModels }

Diff for: packages/components/nodes/chatmodels/ChatAlibabaTongyi/alibaba-svgrepo-com.svg

+8
Loading

Diff for: packages/server/src/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,7 @@ export const isFlowValidForStream = (reactFlowNodes: IReactFlowNode[], endingNod
11921192
'awsChatBedrock',
11931193
'chatMistralAI',
11941194
'chatMistral_LlamaIndex',
1195+
'chatAlibabaTongyi',
11951196
'groqChat',
11961197
'chatGroq_LlamaIndex',
11971198
'chatCohere',

0 commit comments

Comments
 (0)