Skip to content

Commit dfdeb02

Browse files
Feat/added chattBaiduWenxin chat model (#2752)
* added cahtBaiduWenxin model * fix linting * fixed linting * added baidu secret key
1 parent cacbfa8 commit dfdeb02

File tree

4 files changed

+117
-1
lines changed

4 files changed

+117
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { INodeParams, INodeCredential } from '../src/Interface'
2+
3+
class BaiduApi implements INodeCredential {
4+
label: string
5+
name: string
6+
version: number
7+
inputs: INodeParams[]
8+
9+
constructor() {
10+
this.label = 'Baidu API'
11+
this.name = 'baiduApi'
12+
this.version = 1.0
13+
this.inputs = [
14+
{
15+
label: 'Baidu Api Key',
16+
name: 'baiduApiKey',
17+
type: 'password'
18+
},
19+
{
20+
label: 'Baidu Secret Key',
21+
name: 'baiduSecretKey',
22+
type: 'password'
23+
}
24+
]
25+
}
26+
}
27+
28+
module.exports = { credClass: BaiduApi }
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { BaseCache } from '@langchain/core/caches'
2+
import { ChatBaiduWenxin } from '@langchain/community/chat_models/baiduwenxin'
3+
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
4+
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
5+
6+
class ChatBaiduWenxin_ChatModels implements INode {
7+
label: string
8+
name: string
9+
version: number
10+
type: string
11+
icon: string
12+
category: string
13+
description: string
14+
baseClasses: string[]
15+
credential: INodeParams
16+
inputs: INodeParams[]
17+
18+
constructor() {
19+
this.label = 'ChatBaiduWenxin'
20+
this.name = 'chatBaiduWenxin'
21+
this.version = 1.0
22+
this.type = 'ChatBaiduWenxin'
23+
this.icon = 'baiduwenxin.svg'
24+
this.category = 'Chat Models'
25+
this.description = 'Wrapper around BaiduWenxin Chat Endpoints'
26+
this.baseClasses = [this.type, ...getBaseClasses(ChatBaiduWenxin)]
27+
this.credential = {
28+
label: 'Connect Credential',
29+
name: 'credential',
30+
type: 'credential',
31+
credentialNames: ['baiduApi']
32+
}
33+
this.inputs = [
34+
{
35+
label: 'Cache',
36+
name: 'cache',
37+
type: 'BaseCache',
38+
optional: true
39+
},
40+
{
41+
label: 'Model',
42+
name: 'modelName',
43+
type: 'string',
44+
placeholder: 'ERNIE-Bot-turbo'
45+
},
46+
{
47+
label: 'Temperature',
48+
name: 'temperature',
49+
type: 'number',
50+
step: 0.1,
51+
default: 0.9,
52+
optional: true
53+
}
54+
]
55+
}
56+
57+
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
58+
const cache = nodeData.inputs?.cache as BaseCache
59+
const temperature = nodeData.inputs?.temperature as string
60+
const modelName = nodeData.inputs?.modelName as string
61+
62+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
63+
const baiduApiKey = getCredentialParam('baiduApiKey', credentialData, nodeData)
64+
const baiduSecretKey = getCredentialParam('baiduSecretKey', credentialData, nodeData)
65+
66+
const obj: Partial<ChatBaiduWenxin> = {
67+
streaming: true,
68+
baiduApiKey,
69+
baiduSecretKey,
70+
modelName,
71+
temperature: temperature ? parseFloat(temperature) : undefined
72+
}
73+
if (cache) obj.cache = cache
74+
75+
const model = new ChatBaiduWenxin(obj)
76+
return model
77+
}
78+
}
79+
80+
module.exports = { nodeClass: ChatBaiduWenxin_ChatModels }
Lines changed: 7 additions & 0 deletions
Loading

packages/server/src/utils/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,8 @@ export const isFlowValidForStream = (reactFlowNodes: IReactFlowNode[], endingNod
10961096
'chatGoogleGenerativeAI',
10971097
'chatTogetherAI',
10981098
'chatTogetherAI_LlamaIndex',
1099-
'chatFireworks'
1099+
'chatFireworks',
1100+
'chatBaiduWenxin'
11001101
],
11011102
LLMs: ['azureOpenAI', 'openAI', 'ollama']
11021103
}

0 commit comments

Comments
 (0)