Skip to content

Commit bed01e3

Browse files
authored
🐛 fix: fix cohere calling, exclude user and stream_options
1 parent 22ec8cd commit bed01e3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/libs/agent-runtime/cohere/index.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ export interface CohereModelCard {
1212

1313
export const LobeCohereAI = LobeOpenAICompatibleFactory({
1414
baseURL: 'https://api.cohere.ai/compatibility/v1',
15+
chatCompletion: {
16+
// https://docs.cohere.com/v2/docs/compatibility-api#unsupported-parameters
17+
excludeUsage: true,
18+
handlePayload: (payload) => {
19+
const { frequency_penalty, presence_penalty, top_p, ...rest } = payload;
20+
21+
return {
22+
...rest,
23+
frequency_penalty: frequency_penalty !== undefined ? Math.max(0, Math.min(1, frequency_penalty / 2)) : undefined,
24+
presence_penalty: presence_penalty !== undefined ? Math.max(0, Math.min(1, presence_penalty / 2)) : undefined,
25+
top_p: top_p !== undefined ? Math.max(0.01, Math.min(0.99, top_p)) : undefined,
26+
} as any;
27+
},
28+
noUserId: true,
29+
},
1530
debug: {
1631
chatCompletion: () => process.env.DEBUG_COHERE_CHAT_COMPLETION === '1',
1732
},
@@ -21,7 +36,7 @@ export const LobeCohereAI = LobeOpenAICompatibleFactory({
2136
client.baseURL = 'https://api.cohere.com/v1';
2237

2338
const modelsPage = await client.models.list() as any;
24-
const modelList: CohereModelCard[] = modelsPage.models;
39+
const modelList: CohereModelCard[] = modelsPage.body.models;
2540

2641
return modelList
2742
.map((model) => {

0 commit comments

Comments
 (0)