Skip to content

Commit

Permalink
refactor: 修改 bearerHeader 函数以支持可选的 stream 参数
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Dec 24, 2024
1 parent e0415e0 commit 284e897
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/lib/core/src/agent/cohere.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class Cohere implements ChatAgent {
}
return loadModelsList(context.COHERE_CHAT_MODELS_LIST, async (url): Promise<string[]> => {
const data = await fetch(url, {
headers: bearerHeader(context.COHERE_API_KEY, false),
headers: bearerHeader(context.COHERE_API_KEY),
}).then(res => res.json()) as any;
return data.models?.filter((model: any) => model.endpoints?.includes('chat')).map((model: any) => model.name) || [];
});
Expand Down
9 changes: 6 additions & 3 deletions packages/lib/core/src/agent/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ export async function loadModelsList(raw: string, remoteLoader?: RemoteParser):
return [];
}

export function bearerHeader(token: string | null, stream: boolean = false): Record<string, string> {
return {
export function bearerHeader(token: string | null, stream?: boolean): Record<string, string> {
const res: Record<string, string> = {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
'Accept': stream ? 'text/event-stream' : 'application/json',
};
if (stream !== undefined) {
res.Accept = stream ? 'text/event-stream' : 'application/json';
}
return res;
}

0 comments on commit 284e897

Please sign in to comment.