diff --git a/docs/core_docs/docs/integrations/chat/baidu_qianfan.mdx b/docs/core_docs/docs/integrations/chat/baidu_qianfan.mdx index 246bb9db1a01..c3635bd9e4b6 100644 --- a/docs/core_docs/docs/integrations/chat/baidu_qianfan.mdx +++ b/docs/core_docs/docs/integrations/chat/baidu_qianfan.mdx @@ -18,7 +18,7 @@ import IntegrationInstallTooltip from "@mdx_components/integration_install_toolt npm install @langchain/baidu-qianfan ``` -Available models: `ERNIE-Bot`,`ERNIE-Bot-turbo`,`ERNIE-Bot-4`,`ERNIE-Speed-8K`,`ERNIE-Speed-128K`,`ERNIE-4.0-8K`, +Available models: `ERNIE-Bot`,`ERNIE-Lite-8K`,`ERNIE-Bot-4`,`ERNIE-Speed-8K`,`ERNIE-Speed-128K`,`ERNIE-4.0-8K`, `ERNIE-4.0-8K-Preview`,`ERNIE-3.5-8K`,`ERNIE-3.5-8K-Preview`,`ERNIE-Lite-8K`,`ERNIE-Tiny-8K`,`ERNIE-Character-8K`, `ERNIE Speed-AppBuilder` diff --git a/examples/src/models/chat/chat_baidu_qianfan.ts b/examples/src/models/chat/chat_baidu_qianfan.ts index 9163d1a5bbde..f0b0b70f06a4 100644 --- a/examples/src/models/chat/chat_baidu_qianfan.ts +++ b/examples/src/models/chat/chat_baidu_qianfan.ts @@ -4,7 +4,7 @@ import { HumanMessage } from "@langchain/core/messages"; const chat = new ChatBaiduQianfan({ qianfanAccessKey: process.env.QIANFAN_ACCESS_KEY, qianfanSecretKey: process.env.QIANFAN_SECRET_KEY, - model: "ERNIE-Bot-turbo", + model: "ERNIE-Lite-8K", }); const message = new HumanMessage("北京天气"); diff --git a/examples/src/models/chat/chat_stream_baidu_qianfan.ts b/examples/src/models/chat/chat_stream_baidu_qianfan.ts index bac05472eda3..4852fa7838fd 100644 --- a/examples/src/models/chat/chat_stream_baidu_qianfan.ts +++ b/examples/src/models/chat/chat_stream_baidu_qianfan.ts @@ -4,7 +4,7 @@ import { HumanMessage } from "@langchain/core/messages"; const chat = new ChatBaiduQianfan({ qianfanAccessKey: process.env.QIANFAN_ACCESS_KEY, qianfanSecretKey: process.env.QIANFAN_SECRET_KEY, - model: "ERNIE-Bot-turbo", + model: "ERNIE-Lite-8K", streaming: true, }); diff --git a/libs/langchain-baidu-qianfan/README.md b/libs/langchain-baidu-qianfan/README.md index 681c1d9fbdc0..985d714c92e1 100644 --- a/libs/langchain-baidu-qianfan/README.md +++ b/libs/langchain-baidu-qianfan/README.md @@ -27,7 +27,7 @@ import { ChatBaiduQianfan } from "@langchain/baidu-qianfan"; import { HumanMessage } from "@langchain/core/messages"; const chat = new ChatBaiduQianfan({ - model: 'ERNIE-Bot-turbo' + model: 'ERNIE-Lite-8K' }); const message = new HumanMessage("北京天气"); diff --git a/libs/langchain-baidu-qianfan/package.json b/libs/langchain-baidu-qianfan/package.json index a78ca4b7674c..2d94a8a18f51 100644 --- a/libs/langchain-baidu-qianfan/package.json +++ b/libs/langchain-baidu-qianfan/package.json @@ -31,7 +31,7 @@ "author": "LangChain", "license": "MIT", "dependencies": { - "@baiducloud/qianfan": "0.1.0", + "@baiducloud/qianfan": "^0.1.6", "@langchain/core": ">0.1.56 <0.3.0", "@langchain/openai": "~0.1.0", "zod": "^3.22.4", diff --git a/libs/langchain-baidu-qianfan/src/chat_models.ts b/libs/langchain-baidu-qianfan/src/chat_models.ts index 022535ed28e9..dd44ee2a43ba 100644 --- a/libs/langchain-baidu-qianfan/src/chat_models.ts +++ b/libs/langchain-baidu-qianfan/src/chat_models.ts @@ -18,8 +18,6 @@ import { getEnvironmentVariable } from "@langchain/core/utils/env"; import { convertEventStreamToIterableReadableDataStream } from "@langchain/core/utils/event_source_parse"; import { ChatCompletion } from "@baiducloud/qianfan"; -import { isValidModel } from "./utils.js"; - /** * Type representing the role of a message in the Qianfan chat model. */ @@ -72,13 +70,13 @@ interface ChatCompletionResponse { */ declare interface BaiduQianfanChatInput { /** - * Model name to use. Available options are: ERNIE-Bot, ERNIE-Bot-turbo, ERNIE-Bot-4 + * Model name to use. Available options are: ERNIE-Bot, ERNIE-Lite-8K, ERNIE-Bot-4 * Alias for `model` - * @default "ERNIE-Bot-turbo" + * @default "ERNIE-Lite-8K" */ modelName: string; - /** Model name to use. Available options are: ERNIE-Bot, ERNIE-Bot-turbo, ERNIE-Bot-4 - * @default "ERNIE-Bot-turbo" + /** Model name to use. Available options are: ERNIE-Bot, ERNIE-Lite-8K, ERNIE-Bot-4 + * @default "ERNIE-Lite-8K" */ model: string; @@ -217,9 +215,9 @@ export class ChatBaiduQianfan userId?: string; - modelName = "ERNIE-Bot-turbo"; + modelName = "ERNIE-Lite-8K"; - model = "ERNIE-Bot-turbo"; + model = "ERNIE-Lite-8K"; temperature?: number | undefined; @@ -244,10 +242,6 @@ export class ChatBaiduQianfan this.modelName = fields?.model ?? fields?.modelName ?? this.model; this.model = this.modelName; - if (!isValidModel(this.model)) { - throw new Error(`Invalid model name: ${this.model}`); - } - this.qianfanAK = fields?.qianfanAK ?? getEnvironmentVariable("QIANFAN_AK"); this.qianfanSK = fields?.qianfanSK ?? getEnvironmentVariable("QIANFAN_SK"); @@ -416,7 +410,7 @@ export class ChatBaiduQianfan if (!stream) { return response; } else { - let streamResponse = {} as { + let streamResponse = {result: ''} as { id: string; object: string; created: number; diff --git a/libs/langchain-baidu-qianfan/src/tests/chat_models.int.test.ts b/libs/langchain-baidu-qianfan/src/tests/chat_models.int.test.ts index b929a0061af7..edb7420b6fac 100644 --- a/libs/langchain-baidu-qianfan/src/tests/chat_models.int.test.ts +++ b/libs/langchain-baidu-qianfan/src/tests/chat_models.int.test.ts @@ -5,21 +5,21 @@ import { ChatBaiduQianfan } from "../chat_models.js"; test("invoke", async () => { const chat = new ChatBaiduQianfan({ - model: "ERNIE-Bot-turbo", + model: "ERNIE-Lite-8K", }); const message = new HumanMessage("北京天气"); const res = await chat.invoke([message]); - // console.log({ res }); + console.log(res.content); expect(res.content.length).toBeGreaterThan(10); }); test("invokeWithStream", async () => { const chat = new ChatBaiduQianfan({ - model: "ERNIE-Bot-turbo", + model: "ERNIE-Lite-8K", streaming: true, }); const message = new HumanMessage("等额本金和等额本息有什么区别?"); const res = await chat.invoke([message]); - // console.log({ res }); + console.log({ res }); expect(res.content.length).toBeGreaterThan(10); }); diff --git a/libs/langchain-baidu-qianfan/src/utils.ts b/libs/langchain-baidu-qianfan/src/utils.ts deleted file mode 100644 index 494ef12c75d7..000000000000 --- a/libs/langchain-baidu-qianfan/src/utils.ts +++ /dev/null @@ -1,73 +0,0 @@ -/** - * 对话请求公共服务模型列表 - */ -export type ChatModel = - | "ERNIE-4.0-8K" - | "ERNIE-3.5-8K" - | "ERNIE-3.5-8K-0205" - | "ERNIE-3.5-8K-1222" - | "ERNIE-3.5-4K-0205" - | "ERNIE-Speed-128K" - | "ERNIE-Lite-8K-0922" - | "ERNIE-Lite-8K-0308" - | "ERNIE Speed-AppBuilder" - | "Gemma-7B-it" - | "Mixtral-8x7B-Instruct" - | "ERNIE-Bot-turbo" - | "ERNIE-Bot" - | "ERNIE-Bot-4" - | "ERNIE-Bot-8k" - | "ERNIE-Speed" - | "EB-turbo-AppBuilder" - | "BLOOMZ-7B" - | "Llama-2-7b-chat" - | "Llama-2-13b-chat" - | "Llama-2-70b-chat" - | "Qianfan-BLOOMZ-7B-compressed" - | "Qianfan-Chinese-Llama-2-7B" - | "ChatGLM2-6B-32K" - | "AquilaChat-7B" - | "XuanYuan-70B-Chat-4bit" - | "Qianfan-Chinese-Llama-2-13B" - | "ChatLaw" - | "SQLCoder-7B" - | "CodeLlama-7b-Instruct" - | "Yi-34B-Chat"; - -export const CHAT_MODEL = [ - "ERNIE-4.0-8K", - "ERNIE-3.5-8K", - "ERNIE-3.5-8K-0205", - "ERNIE-3.5-8K-1222", - "ERNIE-3.5-4K-0205", - "ERNIE-Speed-128K", - "ERNIE-Lite-8K-0922", - "ERNIE-Lite-8K-0308", - "ERNIE Speed-AppBuilder", - "Gemma-7B-it", - "Mixtral-8x7B-Instruct", - "ERNIE-Bot-turbo", - "ERNIE-Bot", - "ERNIE-Bot-4", - "ERNIE-Bot-8k", - "ERNIE-Speed", - "EB-turbo-AppBuilder", - "BLOOMZ-7B", - "Llama-2-7b-chat", - "Llama-2-13b-chat", - "Llama-2-70b-chat", - "Qianfan-BLOOMZ-7B-compressed", - "Qianfan-Chinese-Llama-2-7B", - "ChatGLM2-6B-32K", - "AquilaChat-7B", - "XuanYuan-70B-Chat-4bit", - "Qianfan-Chinese-Llama-2-13B", - "ChatLaw", - "SQLCoder-7B", - "CodeLlama-7b-Instruct", - "Yi-34B-Chat", -]; - -export const isValidModel = (modelName: string): boolean => { - return CHAT_MODEL.includes(modelName); -}; diff --git a/libs/langchain-community/src/chat_models/tests/chatbaiduwenxin.int.test.ts b/libs/langchain-community/src/chat_models/tests/chatbaiduwenxin.int.test.ts index c286d29eb9b0..210caa2b80df 100644 --- a/libs/langchain-community/src/chat_models/tests/chatbaiduwenxin.int.test.ts +++ b/libs/langchain-community/src/chat_models/tests/chatbaiduwenxin.int.test.ts @@ -122,9 +122,9 @@ const testConfigs: TestConfig[] = [ }, shouldThrow: true, }, - { modelName: "ERNIE-Bot-turbo", config: {} }, + { modelName: "ERNIE-Lite-8K", config: {} }, { - modelName: "ERNIE-Bot-turbo", + modelName: "ERNIE-Lite-8K", config: { description: "in streaming mode", streaming: true, @@ -132,7 +132,7 @@ const testConfigs: TestConfig[] = [ message: "您好,请讲个长笑话", }, { - modelName: "ERNIE-Bot-turbo", + modelName: "ERNIE-Lite-8K", config: { description: "with system message", }, diff --git a/yarn.lock b/yarn.lock index 20617a68d1fb..62d276842b77 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8313,9 +8313,9 @@ __metadata: languageName: node linkType: hard -"@baiducloud/qianfan@npm:0.1.0": - version: 0.1.0 - resolution: "@baiducloud/qianfan@npm:0.1.0" +"@baiducloud/qianfan@npm:^0.1.6": + version: 0.1.6 + resolution: "@baiducloud/qianfan@npm:0.1.6" dependencies: "@babel/preset-react": ^7.24.6 "@rollup/plugin-inject": ^5.0.5 @@ -8325,11 +8325,12 @@ __metadata: bottleneck: ^2.19.5 crypto-js: ^4.2.0 dotenv: ^16.4.5 + express: ^4.19.2 node-fetch: 2.7.0 rollup: ^3.29.4 typescript: ^5.3.3 web-streams-polyfill: ^4.0.0 - checksum: 05a607846a8e4d2e86b7ad88c798eb9d8db15cbd8bdafd2606aee522c7fda2b1aa48c30b7cbca92ac17fd2228c8f3d786f6f0b420c5dc4ee05fd8dfa5a720c5e + checksum: 63e21d10f971303cb44bf4490086c5abf4603b97ef295efd399d56efaa34aaf90e00f6bbd5d07be3036318320efc71575db3d376b95468f9fef445b26e3fb21a languageName: node linkType: hard @@ -10973,7 +10974,7 @@ __metadata: version: 0.0.0-use.local resolution: "@langchain/baidu-qianfan@workspace:libs/langchain-baidu-qianfan" dependencies: - "@baiducloud/qianfan": 0.1.0 + "@baiducloud/qianfan": ^0.1.6 "@jest/globals": ^29.5.0 "@langchain/core": ">0.1.56 <0.3.0" "@langchain/openai": ~0.1.0 @@ -21221,6 +21222,26 @@ __metadata: languageName: node linkType: hard +"body-parser@npm:1.20.2": + version: 1.20.2 + resolution: "body-parser@npm:1.20.2" + dependencies: + bytes: 3.1.2 + content-type: ~1.0.5 + debug: 2.6.9 + depd: 2.0.0 + destroy: 1.2.0 + http-errors: 2.0.0 + iconv-lite: 0.4.24 + on-finished: 2.4.1 + qs: 6.11.0 + raw-body: 2.5.2 + type-is: ~1.6.18 + unpipe: 1.0.0 + checksum: 14d37ec638ab5c93f6099ecaed7f28f890d222c650c69306872e00b9efa081ff6c596cd9afb9930656aae4d6c4e1c17537bea12bb73c87a217cb3cfea8896737 + languageName: node + linkType: hard + "bonjour-service@npm:^1.0.11": version: 1.1.1 resolution: "bonjour-service@npm:1.1.1" @@ -22726,7 +22747,7 @@ __metadata: languageName: node linkType: hard -"content-type@npm:^1.0.5, content-type@npm:~1.0.4": +"content-type@npm:^1.0.5, content-type@npm:~1.0.4, content-type@npm:~1.0.5": version: 1.0.5 resolution: "content-type@npm:1.0.5" checksum: 566271e0a251642254cde0f845f9dd4f9856e52d988f4eb0d0dcffbb7a1f8ec98de7a5215fc628f3bce30fe2fb6fd2bc064b562d721658c59b544e2d34ea2766 @@ -22788,7 +22809,7 @@ __metadata: languageName: node linkType: hard -"cookie@npm:^0.6.0": +"cookie@npm:0.6.0, cookie@npm:^0.6.0": version: 0.6.0 resolution: "cookie@npm:0.6.0" checksum: f56a7d32a07db5458e79c726b77e3c2eff655c36792f2b6c58d351fb5f61531e5b1ab7f46987150136e366c65213cbe31729e02a3eaed630c3bf7334635fb410 @@ -26469,6 +26490,45 @@ __metadata: languageName: node linkType: hard +"express@npm:^4.19.2": + version: 4.19.2 + resolution: "express@npm:4.19.2" + dependencies: + accepts: ~1.3.8 + array-flatten: 1.1.1 + body-parser: 1.20.2 + content-disposition: 0.5.4 + content-type: ~1.0.4 + cookie: 0.6.0 + cookie-signature: 1.0.6 + debug: 2.6.9 + depd: 2.0.0 + encodeurl: ~1.0.2 + escape-html: ~1.0.3 + etag: ~1.8.1 + finalhandler: 1.2.0 + fresh: 0.5.2 + http-errors: 2.0.0 + merge-descriptors: 1.0.1 + methods: ~1.1.2 + on-finished: 2.4.1 + parseurl: ~1.3.3 + path-to-regexp: 0.1.7 + proxy-addr: ~2.0.7 + qs: 6.11.0 + range-parser: ~1.2.1 + safe-buffer: 5.2.1 + send: 0.18.0 + serve-static: 1.15.0 + setprototypeof: 1.2.0 + statuses: 2.0.1 + type-is: ~1.6.18 + utils-merge: 1.0.1 + vary: ~1.1.2 + checksum: 212dbd6c2c222a96a61bc927639c95970a53b06257080bb9e2838adb3bffdb966856551fdad1ab5dd654a217c35db94f987d0aa88d48fb04d306340f5f34dca5 + languageName: node + linkType: hard + "ext@npm:^1.1.2": version: 1.7.0 resolution: "ext@npm:1.7.0" @@ -36630,7 +36690,7 @@ __metadata: languageName: node linkType: hard -"raw-body@npm:^2.2.0": +"raw-body@npm:2.5.2, raw-body@npm:^2.2.0": version: 2.5.2 resolution: "raw-body@npm:2.5.2" dependencies: