[BUG] add Qianfan Model, and err : stream.getReader is not a function
node 18.20.4
Add qianfan Model like: https://js.langchain.com/v0.2/docs/integrations/chat/baidu_qianfan
import { BaseCache } from '@langchain/core/caches'
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { ChatBaiduQianfan } from '@langchain/baidu-qianfan'
class ChatBaiduQianfan_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 = 'ChatBaiduQianfan'
this.name = 'chatBaiduQianfan'
this.version = 1.0
this.type = 'ChatBaiduQianfan'
this.icon = 'baiduwenxin.svg'
this.category = 'Chat Models'
this.description = 'Wrapper around BaiduQianfan Chat Endpoints'
this.baseClasses = [this.type, ...getBaseClasses(ChatBaiduQianfan)]
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<ChatBaiduQianfan> = {
streaming: true,
qianfanAK: baiduApiKey,
qianfanSK: baiduSecretKey,
qianfanAccessKey: baiduApiKey,
qianfanSecretKey: baiduSecretKey,
model: modelName,
temperature: temperature ? parseFloat(temperature) : undefined
}
if (cache) obj.cache = cache
const model = new ChatBaiduQianfan(obj)
return model
}
}
module.exports = { nodeClass: ChatBaiduQianfan_ChatModels }
then use:
error:
2024-07-10 15:54:12 [INFO]: Starting Flowise...
2024-07-10 15:54:12 [INFO]: 📦 [server]: Data Source is initializing...
2024-07-10 15:54:15 [INFO]: 📦 [server]: Data Source has been initialized!
2024-07-10 15:54:15 [INFO]: ⚡️ [server]: Flowise Server is listening at :3030
2024-07-10 15:54:16 [INFO]: ⬆️ POST /api/v1/node-load-method/documentStore
2024-07-10 15:54:33 [INFO]: ❌ DELETE /api/v1/chatmessage/2d760c06-b0de-45ed-9b74-f9dfe36656a9?chatId=fcf818bd-98f0-4780-a6ae-d977b46c6d8c&chatType=INTERNAL
2024-07-10 15:54:36 [INFO]: ⬆️ POST /api/v1/internal-prediction/2d760c06-b0de-45ed-9b74-f9dfe36656a9
2024-07-10 15:54:37 [INFO]: [server]: Chatflow 2d760c06-b0de-45ed-9b74-f9dfe36656a9 added into ChatflowPool
2024-07-10 15:54:38 [ERROR]: [server]: Error: stream.getReader is not a function
TypeError: stream.getReader is not a function
at getBytes (/Users/didi/WebstormProjects/Flowise/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]_/node_modules/@langchain/core/dist/utils/event_source_parse.cjs:19:27)
at Object.start (/Users/didi/WebstormProjects/Flowise/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]_/node_modules/@langchain/core/dist/utils/event_source_parse.cjs:207:19)
at setupReadableStreamDefaultController (node:internal/webstreams/readablestream:2333:23)
at setupReadableStreamDefaultControllerFromSource (node:internal/webstreams/readablestream:2366:3)
at new ReadableStream (node:internal/webstreams/readablestream:289:7)
at convertEventStreamToIterableReadableDataStream (/Users/didi/WebstormProjects/Flowise/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]_/node_modules/@langchain/core/dist/utils/event_source_parse.cjs:188:24)
at ChatBaiduQianfan.createStream (/Users/didi/WebstormProjects/Flowise/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_kov6ixubsp_ccx72fmvccog47x7lvf257gdy4/node_modules/@langchain/baidu-qianfan/dist/chat_models.cjs:329:88)
at async RetryOperation._fn (/Users/didi/WebstormProjects/Flowise/node_modules/.pnpm/[email protected]/node_modules/p-retry/index.js:50:12)
I think we might have to upgrade the langchain package version to pickup the new changes, its updated here - https://github.com/FlowiseAI/Flowise/pull/2798
I think we might have to upgrade the langchain package version to pickup the new changes, its updated here - #2798
Thanks, It is ok。 But it has a new problem,like:
I'm not sure if it's an issue with langchain or an issue with flowiseAi。
@iceycc I dont have a qianfan credentials to try it out, if you do, can you email me @ [email protected], so I can test it out?
Any chance this is related to https://github.com/langchain-ai/langchainjs/pull/5970?
Can't test either 😅
@iceycc 请问你用的版本是什么版本?
@iceycc May I know which api did u call or what did u do with the model in this 'init' function?