Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
iceycc opened this issue Jul 10, 2024 · 6 comments
Open

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

iceycc opened this issue Jul 10, 2024 · 6 comments
Labels
bug Something isn't working in-work Issue in work

Comments

@iceycc
Copy link

iceycc commented Jul 10, 2024

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
Copy link
Contributor

I think we might have to upgrade the langchain package version to pickup the new changes, its updated here - #2798

@HenryHengZJ HenryHengZJ added bug Something isn't working in-work Issue in work labels Jul 12, 2024
@iceycc
Copy link
Author

iceycc commented Jul 15, 2024

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
Copy link
Contributor

@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
Copy link

Any chance this is related to langchain-ai/langchainjs#5970?

Can't test either 😅

@dl102306
Copy link

dl102306 commented Sep 3, 2024

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

@zpnaruto
Copy link

zpnaruto commented Sep 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in-work Issue in work
Projects
None yet
Development

No branches or pull requests

5 participants