Skip to content

Commit

Permalink
Merge pull request #5194 from HyiKi/main
Browse files Browse the repository at this point in the history
fix: baidu error_code 336006
  • Loading branch information
lloydzhou authored Aug 6, 2024
2 parents 94c4cf0 + 0902efc commit 6905421
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
18 changes: 13 additions & 5 deletions app/client/platforms/baidu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,24 @@ 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 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 = {
Expand Down
5 changes: 3 additions & 2 deletions app/client/platforms/tencent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}));

Expand Down

0 comments on commit 6905421

Please sign in to comment.