Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions app/client/platforms/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
""
);
Expand Down Expand Up @@ -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");
Comment on lines +235 to +238
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Align streaming text extraction with getTextFromParts for consistency.

The streaming response handling uses a different approach for text extraction compared to getTextFromParts. This inconsistency could potentially lead to different handling of empty parts or whitespace.

Consider reusing the getTextFromParts function here:

-return chunkJson?.candidates
-  ?.at(0)
-  ?.content.parts?.map((part: { text: string }) => part.text)
-  .join("\n\n");
+return getTextFromParts(chunkJson?.candidates?.at(0)?.content?.parts || []);

Committable suggestion skipped: line range outside the PR's diff.

},
// processToolMessage, include tool_calls message and tool call results
(
Expand Down
Loading