FlowiseAI / Flowise

Drag & drop UI to build your customized LLM flow
https://flowiseai.com
Apache License 2.0
31.36k stars 16.32k forks source link

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

Open iceycc opened 4 months ago

iceycc commented 4 months ago

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/@langchain+core@0.1.63_langchain@0.1.37_kov6ixubspoxa2akjvxho2sune__openai@4.51.0_encoding@0.1.13_/node_modules/@langchain/core/dist/utils/event_source_parse.cjs:19:27)
    at Object.start (/Users/didi/WebstormProjects/Flowise/node_modules/.pnpm/@langchain+core@0.1.63_langchain@0.1.37_kov6ixubspoxa2akjvxho2sune__openai@4.51.0_encoding@0.1.13_/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/@langchain+core@0.1.63_langchain@0.1.37_kov6ixubspoxa2akjvxho2sune__openai@4.51.0_encoding@0.1.13_/node_modules/@langchain/core/dist/utils/event_source_parse.cjs:188:24)
    at ChatBaiduQianfan.createStream (/Users/didi/WebstormProjects/Flowise/node_modules/.pnpm/@langchain+baidu-qianfan@0.0.1_@babel+core@7.24.7_encoding@0.1.13_langchain@0.1.37_kov6ixubsp_ccx72fmvccog47x7lvf257gdy4/node_modules/@langchain/baidu-qianfan/dist/chat_models.cjs:329:88)
    at async RetryOperation._fn (/Users/didi/WebstormProjects/Flowise/node_modules/.pnpm/p-retry@4.6.2/node_modules/p-retry/index.js:50:12)
HenryHengZJ commented 4 months ago

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

iceycc commented 3 months ago

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:

image

I'm not sure if it's an issue with langchain or an issue with flowiseAi。

HenryHengZJ commented 3 months ago

@iceycc I dont have a qianfan credentials to try it out, if you do, can you email me @ henryheng@flowiseai.com, so I can test it out?

jacoblee93 commented 3 months ago

Any chance this is related to https://github.com/langchain-ai/langchainjs/pull/5970?

Can't test either 😅

dl102306 commented 2 months ago

@iceycc 请问你用的版本是什么版本?

zpnaruto commented 2 months ago

@iceycc May I know which api did u call or what did u do with the model in this 'init' function?

b94ada2f98c164a141b452fa626b0461