diff --git a/docs/core_docs/docs/integrations/chat/baidu_qianfan.mdx b/docs/core_docs/docs/integrations/chat/baidu_qianfan.mdx index a88b2f9edf1f..a4df5ccfa63a 100644 --- a/docs/core_docs/docs/integrations/chat/baidu_qianfan.mdx +++ b/docs/core_docs/docs/integrations/chat/baidu_qianfan.mdx @@ -18,10 +18,12 @@ 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` +Abandoned models: `ERNIE-Bot-turbo` + ## Usage import ChatBaiduQianfanExample from "@examples/models/chat/chat_baidu_qianfan.ts"; diff --git a/docs/core_docs/docs/integrations/chat/baidu_wenxin.mdx b/docs/core_docs/docs/integrations/chat/baidu_wenxin.mdx index f2cf626f4064..3a36bc738673 100644 --- a/docs/core_docs/docs/integrations/chat/baidu_wenxin.mdx +++ b/docs/core_docs/docs/integrations/chat/baidu_wenxin.mdx @@ -27,6 +27,8 @@ Available models: `ERNIE-Bot`,`ERNIE-Bot-turbo`,`ERNIE-Bot-4`,`ERNIE-Speed-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` +Abandoned models: `ERNIE-Bot-turbo` + import Wenxin from "@examples/models/chat/integration_baiduwenxin.ts"; {Wenxin} 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 d50964d5a72b..fc804f9c2269 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..e1f0a3469f3c 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,12 +70,12 @@ 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" */ modelName: string; - /** 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 * @default "ERNIE-Bot-turbo" */ model: string; @@ -244,8 +242,8 @@ 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}`); + if (!this.model) { + throw new Error(`Please provide modelName`); } this.qianfanAK = fields?.qianfanAK ?? getEnvironmentVariable("QIANFAN_AK"); @@ -416,7 +414,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..e85156379523 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,17 +5,17 @@ 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("等额本金和等额本息有什么区别?"); 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 c96e97605695..e9eb2d6d1ca0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8298,9 +8298,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 @@ -8310,11 +8310,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 @@ -10965,7 +10966,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 @@ -21125,6 +21126,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" @@ -22649,7 +22670,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 @@ -22711,7 +22732,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 @@ -26331,6 +26352,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" @@ -36125,6 +36185,18 @@ __metadata: languageName: node linkType: hard +"raw-body@npm:2.5.2": + version: 2.5.2 + resolution: "raw-body@npm:2.5.2" + dependencies: + bytes: 3.1.2 + http-errors: 2.0.0 + iconv-lite: 0.4.24 + unpipe: 1.0.0 + checksum: ba1583c8d8a48e8fbb7a873fdbb2df66ea4ff83775421bfe21ee120140949ab048200668c47d9ae3880012f6e217052690628cf679ddfbd82c9fc9358d574676 + languageName: node + linkType: hard + "rc@npm:1.2.8, rc@npm:^1.0.1, rc@npm:^1.1.6, rc@npm:^1.2.7, rc@npm:^1.2.8": version: 1.2.8 resolution: "rc@npm:1.2.8"