11import { BaseCache } from '@langchain/core/caches'
22import { ChatBaiduQianfan } from '@langchain/baidu-qianfan'
3- import { ICommonObject , INode , INodeData , INodeParams } from '../../../src/Interface'
3+ import { ICommonObject , INode , INodeData , INodeOptionsValue , INodeParams } from '../../../src/Interface'
4+ import { MODEL_TYPE , getModels } from '../../../src/modelLoader'
45import { getBaseClasses , getCredentialData , getCredentialParam } from '../../../src/utils'
56
67class ChatBaiduWenxin_ChatModels implements INode {
@@ -18,7 +19,7 @@ class ChatBaiduWenxin_ChatModels implements INode {
1819 constructor ( ) {
1920 this . label = 'Baidu Wenxin'
2021 this . name = 'chatBaiduWenxin'
21- this . version = 2 .0
22+ this . version = 3 .0
2223 this . type = 'ChatBaiduWenxin'
2324 this . icon = 'baiduwenxin.svg'
2425 this . category = 'Chat Models'
@@ -38,10 +39,20 @@ class ChatBaiduWenxin_ChatModels implements INode {
3839 optional : true
3940 } ,
4041 {
41- label : 'Model' ,
42+ label : 'Model Name ' ,
4243 name : 'modelName' ,
44+ type : 'asyncOptions' ,
45+ loadMethod : 'listModels' ,
46+ default : 'ernie-4.5-8k-preview'
47+ } ,
48+ {
49+ label : 'Custom Model Name' ,
50+ name : 'customModelName' ,
4351 type : 'string' ,
44- placeholder : 'ERNIE-Bot-turbo'
52+ placeholder : 'ernie-speed-128k' ,
53+ description : 'Custom model name to use. If provided, it will override the selected model.' ,
54+ additionalParams : true ,
55+ optional : true
4556 } ,
4657 {
4758 label : 'Temperature' ,
@@ -57,15 +68,52 @@ class ChatBaiduWenxin_ChatModels implements INode {
5768 type : 'boolean' ,
5869 default : true ,
5970 optional : true
71+ } ,
72+ {
73+ label : 'Top Probability' ,
74+ name : 'topP' ,
75+ type : 'number' ,
76+ description : 'Nucleus sampling. The model considers tokens whose cumulative probability mass reaches this value.' ,
77+ step : 0.1 ,
78+ optional : true ,
79+ additionalParams : true
80+ } ,
81+ {
82+ label : 'Penalty Score' ,
83+ name : 'penaltyScore' ,
84+ type : 'number' ,
85+ description : 'Penalizes repeated tokens according to frequency. Baidu Qianfan accepts values from 1.0 to 2.0.' ,
86+ step : 0.1 ,
87+ optional : true ,
88+ additionalParams : true
89+ } ,
90+ {
91+ label : 'User ID' ,
92+ name : 'userId' ,
93+ type : 'string' ,
94+ description : 'Optional unique identifier for the end user making the request.' ,
95+ optional : true ,
96+ additionalParams : true
6097 }
6198 ]
6299 }
63100
101+ //@ts -ignore
102+ loadMethods = {
103+ async listModels ( ) : Promise < INodeOptionsValue [ ] > {
104+ return await getModels ( MODEL_TYPE . CHAT , 'chatBaiduWenxin' )
105+ }
106+ }
107+
64108 async init ( nodeData : INodeData , _ : string , options : ICommonObject ) : Promise < any > {
65109 const cache = nodeData . inputs ?. cache as BaseCache
66110 const temperature = nodeData . inputs ?. temperature as string
67111 const modelName = nodeData . inputs ?. modelName as string
112+ const customModelName = nodeData . inputs ?. customModelName as string
68113 const streaming = nodeData . inputs ?. streaming as boolean
114+ const topP = nodeData . inputs ?. topP as string
115+ const penaltyScore = nodeData . inputs ?. penaltyScore as string
116+ const userId = nodeData . inputs ?. userId as string
69117
70118 const credentialData = await getCredentialData ( nodeData . credential ?? '' , options )
71119 const qianfanAccessKey = getCredentialParam ( 'qianfanAccessKey' , credentialData , nodeData )
@@ -75,9 +123,12 @@ class ChatBaiduWenxin_ChatModels implements INode {
75123 streaming : streaming ?? true ,
76124 qianfanAccessKey,
77125 qianfanSecretKey,
78- modelName,
126+ modelName : customModelName || modelName ,
79127 temperature : temperature ? parseFloat ( temperature ) : undefined
80128 }
129+ if ( topP ) obj . topP = parseFloat ( topP )
130+ if ( penaltyScore ) obj . penaltyScore = parseFloat ( penaltyScore )
131+ if ( userId ) obj . userId = userId
81132 if ( cache ) obj . cache = cache
82133
83134 const model = new ChatBaiduQianfan ( obj )
0 commit comments