Merge feature/update-bedrock-api into main

This commit is contained in:
glay 2024-11-05 20:20:20 +08:00
parent 1164e1bdf6
commit 1998cf5ced
2 changed files with 7 additions and 12 deletions

View File

@ -41,10 +41,7 @@ export interface ConverseRequest {
function supportsToolUse(modelId: string): boolean { function supportsToolUse(modelId: string): boolean {
// llama和mistral模型不支持工具调用 // llama和mistral模型不支持工具调用
return ( return modelId.toLowerCase().includes("claude-3");
modelId.toLowerCase().includes("claude-3") &&
modelId.toLowerCase().includes("claude-3-5")
);
} }
function formatRequestBody( function formatRequestBody(

View File

@ -38,11 +38,9 @@ export class BedrockApi implements LLMApi {
} }
extractMessage(res: any) { extractMessage(res: any) {
console.log("[Response] bedrock response: ", res); console.log("[Response] claude response: ", res);
if (Array.isArray(res?.content)) {
return res.content; return res?.content?.[0]?.text;
}
return res;
} }
async chat(options: ChatOptions): Promise<void> { async chat(options: ChatOptions): Promise<void> {
@ -173,7 +171,6 @@ export class BedrockApi implements LLMApi {
funcs, funcs,
controller, controller,
// parseSSE // parseSSE
// parseSSE
(text: string, runTools: ChatMessageTool[]) => { (text: string, runTools: ChatMessageTool[]) => {
// console.log("parseSSE", text, runTools); // console.log("parseSSE", text, runTools);
let chunkJson: let chunkJson:
@ -269,13 +266,14 @@ export class BedrockApi implements LLMApi {
}; };
try { try {
controller.signal.onabort = () => options.onFinish(""); controller.signal.onabort = () =>
options.onFinish("", new Response(null, { status: 400 }));
const res = await fetch(conversePath, payload); const res = await fetch(conversePath, payload);
const resJson = await res.json(); const resJson = await res.json();
const message = this.extractMessage(resJson); const message = this.extractMessage(resJson);
options.onFinish(message); options.onFinish(message, res);
} catch (e) { } catch (e) {
console.error("failed to chat", e); console.error("failed to chat", e);
options.onError?.(e as Error); options.onError?.(e as Error);