From d0e296adf82ffd169554ef8ab97f1005dabd0bbb Mon Sep 17 00:00:00 2001 From: HyiKi Date: Mon, 5 Aug 2024 15:41:13 +0800 Subject: [PATCH 1/3] fix: baidu error_code 336006 --- app/client/platforms/baidu.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/client/platforms/baidu.ts b/app/client/platforms/baidu.ts index 188b78bf963..29c020df416 100644 --- a/app/client/platforms/baidu.ts +++ b/app/client/platforms/baidu.ts @@ -77,7 +77,8 @@ export class ErnieApi implements LLMApi { async chat(options: ChatOptions) { const messages = options.messages.map((v) => ({ - role: v.role, + // "error_code": 336006, "error_msg": "the role of message with odd index in the messages must be assistant", + role: v.role === "system" ? "assistant" : v.role, content: getMessageTextContent(v), })); From 9ab45c396919d37221521a737f41b5591c52c856 Mon Sep 17 00:00:00 2001 From: HyiKi Date: Mon, 5 Aug 2024 20:50:36 +0800 Subject: [PATCH 2/3] fix: baidu error_code 336006 change the summary role from system to user --- app/client/platforms/baidu.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/client/platforms/baidu.ts b/app/client/platforms/baidu.ts index 29c020df416..3be147f4985 100644 --- a/app/client/platforms/baidu.ts +++ b/app/client/platforms/baidu.ts @@ -77,17 +77,24 @@ export class ErnieApi implements LLMApi { async chat(options: ChatOptions) { const messages = options.messages.map((v) => ({ - // "error_code": 336006, "error_msg": "the role of message with odd index in the messages must be assistant", - role: v.role === "system" ? "assistant" : v.role, + // "error_code": 336006, "error_msg": "the role of message with even index in the messages must be user or function", + role: v.role === "system" ? "user" : v.role, content: getMessageTextContent(v), })); // "error_code": 336006, "error_msg": "the length of messages must be an odd number", if (messages.length % 2 === 0) { - messages.unshift({ - role: "user", - content: " ", - }); + if (messages.at(0)?.role === "user") { + messages.splice(1, 0, { + role: "assistant", + content: " ", + }); + } else { + messages.unshift({ + role: "user", + content: " ", + }); + } } const modelConfig = { From d7e2ee63d87bb713231e11d3ff2dabb3b1904e0c Mon Sep 17 00:00:00 2001 From: HyiKi Date: Tue, 6 Aug 2024 10:45:25 +0800 Subject: [PATCH 3/3] fix: tencent InvalidParameter error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix "Messages 中 system 角色必须位于列表的最开始" --- app/client/platforms/tencent.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/client/platforms/tencent.ts b/app/client/platforms/tencent.ts index e9e49d3f0b0..579008a9b9d 100644 --- a/app/client/platforms/tencent.ts +++ b/app/client/platforms/tencent.ts @@ -91,8 +91,9 @@ export class HunyuanApi implements LLMApi { async chat(options: ChatOptions) { const visionModel = isVisionModel(options.config.model); - const messages = options.messages.map((v) => ({ - role: v.role, + const messages = options.messages.map((v, index) => ({ + // "Messages 中 system 角色必须位于列表的最开始" + role: index !== 0 && v.role === "system" ? "user" : v.role, content: visionModel ? v.content : getMessageTextContent(v), }));