Skip to content

Commit

Permalink
🐛 fix: Update baichuan param (#3356)
Browse files Browse the repository at this point in the history
* Update index.ts

* Update index.ts

* Update index.ts

* Update index.ts
  • Loading branch information
sxjeru authored Sep 9, 2024
1 parent dd60e41 commit 29bced1
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/libs/agent-runtime/baichuan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,15 @@ export const LobeBaichuanAI = LobeOpenAICompatibleFactory({
baseURL: 'https://api.baichuan-ai.com/v1',
chatCompletion: {
handlePayload: (payload: ChatStreamPayload) => {
const { frequency_penalty, ...rest } = payload;
const { temperature, ...rest } = payload;

let adjustedFrequencyPenalty = frequency_penalty ?? 1;

if (frequency_penalty !== undefined) {
if (frequency_penalty < 1) {
// If less than 1 (including negative values), add 1 to bring it into the 1-2 range
adjustedFrequencyPenalty = Math.min(Math.max(frequency_penalty + 1, 1), 2);
} else if (frequency_penalty > 2) {
// If greater than 2, cap it at 2
adjustedFrequencyPenalty = 2;
}
// If between 1 and 2, keep the original value
}

return { ...rest, frequency_penalty: adjustedFrequencyPenalty } as OpenAI.ChatCompletionCreateParamsStreaming;
return {
...rest,
temperature:
temperature !== undefined
? temperature / 2
: undefined,
} as OpenAI.ChatCompletionCreateParamsStreaming;
},
},
debug: {
Expand Down

0 comments on commit 29bced1

Please sign in to comment.