From 75057f9a910a22032007db975d493a6cc02c0519 Mon Sep 17 00:00:00 2001 From: Fred Liang Date: Sun, 24 Dec 2023 04:32:25 +0800 Subject: [PATCH] chroe: support error reason for gemini pro --- app/client/platforms/google.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index e1e526637..3192d5d5f 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -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); }