mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-23 22:20:23 +09:00
Merge feature/update-bedrock-api into main
This commit is contained in:
parent
1164e1bdf6
commit
1998cf5ced
@ -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(
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user