forked from XiaoMo/ChatGPT-Next-Web
chroe: support error reason for gemini pro
This commit is contained in:
parent
7026bd926a
commit
75057f9a91
@ -12,6 +12,7 @@ import { getServerSideConfig } from "@/app/config/server";
|
||||
export class GeminiProApi implements LLMApi {
|
||||
extractMessage(res: any) {
|
||||
console.log("[Response] gemini-pro response: ", res);
|
||||
|
||||
return (
|
||||
res?.candidates?.at(0)?.content?.parts.at(0)?.text ||
|
||||
res?.error?.message ||
|
||||
@ -176,6 +177,16 @@ export class GeminiProApi implements LLMApi {
|
||||
clearTimeout(requestTimeoutId);
|
||||
|
||||
const resJson = await res.json();
|
||||
|
||||
if (resJson?.promptFeedback?.blockReason) {
|
||||
// being blocked
|
||||
options.onError?.(
|
||||
new Error(
|
||||
"Message is being blocked for reason: " +
|
||||
resJson.promptFeedback.blockReason,
|
||||
),
|
||||
);
|
||||
}
|
||||
const message = this.extractMessage(resJson);
|
||||
options.onFinish(message);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user