From 87b5e3bf6252be247b32385a19d9897bede5cdf0 Mon Sep 17 00:00:00 2001 From: zmhuanf Date: Sun, 22 Dec 2024 15:44:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/client/platforms/google.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index a7bce4fc2d0..5ca8e1071a7 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -60,9 +60,18 @@ export class GeminiProApi implements LLMApi { extractMessage(res: any) { console.log("[Response] gemini-pro response: ", res); + const getTextFromParts = (parts: any[]) => { + if (!Array.isArray(parts)) return ""; + + return parts + .map((part) => part?.text || "") + .filter((text) => text.trim() !== "") + .join("\n\n"); + }; + return ( - res?.candidates?.at(0)?.content?.parts.at(0)?.text || - res?.at(0)?.candidates?.at(0)?.content?.parts.at(0)?.text || + getTextFromParts(res?.candidates?.at(0)?.content?.parts) || + getTextFromParts(res?.at(0)?.candidates?.at(0)?.content?.parts) || res?.error?.message || "" ); @@ -223,7 +232,10 @@ export class GeminiProApi implements LLMApi { }, }); } - return chunkJson?.candidates?.at(0)?.content.parts.at(0)?.text; + return chunkJson?.candidates + ?.at(0) + ?.content.parts?.map((part: { text: string }) => part.text) + .join("\n\n"); }, // processToolMessage, include tool_calls message and tool call results (