Skip to content

[BUG] add Qianfan Model, and err : stream.getReader is not a function #2786

@iceycc

Description

@iceycc

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:
image

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingin-workIssue in work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions