Gemini: Fix cross-chunk parsing of multipart replies

39cfb35c1a4d1ae56811ef5c5afb4190bc2fc041

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +7 -7Ignore whitespace
public/scripts/openai.js+4 -4
@@ -2098,7 +2098,7 @@ function getStreamingReply(data) {
20982098 if (oai_settings.chat_completion_source === chat_completion_sources.CLAUDE) {
20992099 return data?.delta?.text || '';
21002100 } else if (oai_settings.chat_completion_source === chat_completion_sources.MAKERSUITE) {
21012101 return data?.candidates?.[0]?.content?.parts?.[0]?map(x => x.text)?.join('\n\n') || '';
21022102 } else if (oai_settings.chat_completion_source === chat_completion_sources.COHERE) {
21032103 return data?.delta?.message?.content?.text || data?.delta?.message?.tool_plan || '';
21042104 } else {
@@ -2110,7 +2110,7 @@ function getStreamingReply(data) {
21102110 * parseChatCompletionLogprobs converts the response data returned from a chat
21112111 * completions-like source into an array of TokenLogprobs found in the response.
21122112 * @param {Object} data - response data from a chat completions-like source
21132113 * @returns {import('./logprobs.js').TokenLogprobs[] | null} converted logprobs
21142114 */
21152115function parseChatCompletionLogprobs(data) {
21162116 if (!data) {
@@ -2139,7 +2139,7 @@ function parseChatCompletionLogprobs(data) {
21392139 * completion API and converts into the structure used by the Token Probabilities
21402140 * view.
21412141 * @param {{content: { token: string, logprob: number, top_logprobs: { token: string, logprob: number }[] }[]}} logprobs
21422142 * @returns {import('./logprobs.js').TokenLogprobs[] | null} converted logprobs
21432143 */
21442144function parseOpenAIChatLogprobs(logprobs) {
21452145 const { content } = logprobs ?? {};
@@ -2167,7 +2167,7 @@ function parseOpenAIChatLogprobs(logprobs) {
21672167 * completion API and converts into the structure used by the Token Probabilities
21682168 * view.
21692169 * @param {{tokens: string[], token_logprobs: number[], top_logprobs: { token: string, logprob: number }[][]}} logprobs
21702170 * @returns {import('./logprobs.js').TokenLogprobs[] | null} converted logprobs
21712171 */
21722172function parseOpenAITextLogprobs(logprobs) {
21732173 const { tokens, token_logprobs, top_logprobs } = logprobs ?? {};
src/endpoints/backends/chat-completions.js+3 -3
@@ -367,15 +367,15 @@ async function sendMakerSuiteRequest(request, response) {
367367 }
368368
369369 const responseContent = candidates[0].content ?? candidates[0].output;
370- const responseText = typeof responseContent === 'string' ? responseContent : responseContent?.parts?.[0]?.text;
370+ console.log('Google AI Studio response:', responseContent);
371+
372+ const responseText = typeof responseContent === 'string' ? responseContent : responseContent?.parts?.map(part => part.text)?.join('\n\n');
371373 if (!responseText) {
372374 let message = 'Google AI Studio Candidate text empty';
373375 console.log(message, generateResponseJson);
374376 return response.send({ error: { message } });
375377 }
376378
377- console.log('Google AI Studio response:', responseText);
378-
379379 // Wrap it back to OAI format
380380 const reply = { choices: [{ 'message': { 'content': responseText } }] };
381381 return response.send(reply);