Feat/added chattBaiduWenxin chat model (#2752)
* added cahtBaiduWenxin model * fix linting * fixed linting * added baidu secret key
This commit is contained in:
parent
cacbfa8162
commit
dfdeb02b3a
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { INodeParams, INodeCredential } from '../src/Interface'
|
||||||
|
|
||||||
|
class BaiduApi implements INodeCredential {
|
||||||
|
label: string
|
||||||
|
name: string
|
||||||
|
version: number
|
||||||
|
inputs: INodeParams[]
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.label = 'Baidu API'
|
||||||
|
this.name = 'baiduApi'
|
||||||
|
this.version = 1.0
|
||||||
|
this.inputs = [
|
||||||
|
{
|
||||||
|
label: 'Baidu Api Key',
|
||||||
|
name: 'baiduApiKey',
|
||||||
|
type: 'password'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Baidu Secret Key',
|
||||||
|
name: 'baiduSecretKey',
|
||||||
|
type: 'password'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { credClass: BaiduApi }
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
import { BaseCache } from '@langchain/core/caches'
|
||||||
|
import { ChatBaiduWenxin } from '@langchain/community/chat_models/baiduwenxin'
|
||||||
|
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||||
|
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||||
|
|
||||||
|
class ChatBaiduWenxin_ChatModels implements INode {
|
||||||
|
label: string
|
||||||
|
name: string
|
||||||
|
version: number
|
||||||
|
type: string
|
||||||
|
icon: string
|
||||||
|
category: string
|
||||||
|
description: string
|
||||||
|
baseClasses: string[]
|
||||||
|
credential: INodeParams
|
||||||
|
inputs: INodeParams[]
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.label = 'ChatBaiduWenxin'
|
||||||
|
this.name = 'chatBaiduWenxin'
|
||||||
|
this.version = 1.0
|
||||||
|
this.type = 'ChatBaiduWenxin'
|
||||||
|
this.icon = 'baiduwenxin.svg'
|
||||||
|
this.category = 'Chat Models'
|
||||||
|
this.description = 'Wrapper around BaiduWenxin Chat Endpoints'
|
||||||
|
this.baseClasses = [this.type, ...getBaseClasses(ChatBaiduWenxin)]
|
||||||
|
this.credential = {
|
||||||
|
label: 'Connect Credential',
|
||||||
|
name: 'credential',
|
||||||
|
type: 'credential',
|
||||||
|
credentialNames: ['baiduApi']
|
||||||
|
}
|
||||||
|
this.inputs = [
|
||||||
|
{
|
||||||
|
label: 'Cache',
|
||||||
|
name: 'cache',
|
||||||
|
type: 'BaseCache',
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Model',
|
||||||
|
name: 'modelName',
|
||||||
|
type: 'string',
|
||||||
|
placeholder: 'ERNIE-Bot-turbo'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Temperature',
|
||||||
|
name: 'temperature',
|
||||||
|
type: 'number',
|
||||||
|
step: 0.1,
|
||||||
|
default: 0.9,
|
||||||
|
optional: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||||
|
const cache = nodeData.inputs?.cache as BaseCache
|
||||||
|
const temperature = nodeData.inputs?.temperature as string
|
||||||
|
const modelName = nodeData.inputs?.modelName as string
|
||||||
|
|
||||||
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||||
|
const baiduApiKey = getCredentialParam('baiduApiKey', credentialData, nodeData)
|
||||||
|
const baiduSecretKey = getCredentialParam('baiduSecretKey', credentialData, nodeData)
|
||||||
|
|
||||||
|
const obj: Partial<ChatBaiduWenxin> = {
|
||||||
|
streaming: true,
|
||||||
|
baiduApiKey,
|
||||||
|
baiduSecretKey,
|
||||||
|
modelName,
|
||||||
|
temperature: temperature ? parseFloat(temperature) : undefined
|
||||||
|
}
|
||||||
|
if (cache) obj.cache = cache
|
||||||
|
|
||||||
|
const model = new ChatBaiduWenxin(obj)
|
||||||
|
return model
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { nodeClass: ChatBaiduWenxin_ChatModels }
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg"
|
||||||
|
aria-label="Baidu" role="img"
|
||||||
|
viewBox="0 0 512 512"><rect
|
||||||
|
width="512" height="512"
|
||||||
|
rx="15%"
|
||||||
|
fill="#ffffff"/><path d="m131 251c41-9 35-58 34-68-2-17-21-45-48-43-33 3-37 50-37 50-5 22 10 70 51 61m76-82c22 0 40-26 40-58s-18-58-40-58c-23 0-41 26-41 58s18 58 41 58m96 4c31 4 50-28 54-53 4-24-16-52-37-57s-48 29-50 52c-3 27 3 54 33 58m120 41c0-12-10-47-46-47s-41 33-41 57c0 22 2 53 47 52s40-51 40-62m-46 102s-46-36-74-75c-36-57-89-34-106-5-18 29-45 48-49 53-4 4-56 33-44 84 11 52 52 51 52 51s30 3 65-5 65 2 65 2 81 27 104-25c22-53-13-80-13-80" fill="#2319dc"/><path d="m214 266v34h-28s-29 3-39 35c-3 21 4 34 5 36 1 3 10 19 33 23h53v-128zm-1 107h-21s-15-1-19-18c-3-7 0-16 1-20 1-3 6-11 17-14h22zm38-70v68s1 17 24 23h61v-91h-26v68h-25s-8-1-10-7v-61z" fill="#ffffff"/></svg>
|
||||||
|
After Width: | Height: | Size: 924 B |
|
|
@ -1096,7 +1096,8 @@ export const isFlowValidForStream = (reactFlowNodes: IReactFlowNode[], endingNod
|
||||||
'chatGoogleGenerativeAI',
|
'chatGoogleGenerativeAI',
|
||||||
'chatTogetherAI',
|
'chatTogetherAI',
|
||||||
'chatTogetherAI_LlamaIndex',
|
'chatTogetherAI_LlamaIndex',
|
||||||
'chatFireworks'
|
'chatFireworks',
|
||||||
|
'chatBaiduWenxin'
|
||||||
],
|
],
|
||||||
LLMs: ['azureOpenAI', 'openAI', 'ollama']
|
LLMs: ['azureOpenAI', 'openAI', 'ollama']
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue