From 1682b715fdb15ee50971ee08098148546ac2a6cf Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Mon, 29 Jul 2024 17:24:02 +0800 Subject: [PATCH] fix: gemini mode text & FunctionCall --- client/CustomGoogleGeminiClient.js | 12 +++++++++--- model/core.js | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/client/CustomGoogleGeminiClient.js b/client/CustomGoogleGeminiClient.js index bf426d1..671674c 100644 --- a/client/CustomGoogleGeminiClient.js +++ b/client/CustomGoogleGeminiClient.js @@ -79,7 +79,8 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient { * maxOutputTokens: number?, * temperature: number?, * topP: number?, - * tokK: number? + * tokK: number?, + * replyPureTextCallback: Function * }} opt * @returns {Promise<{conversationId: string?, parentMessageId: string, text: string, id: string}>} */ @@ -200,9 +201,14 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient { console.log(JSON.stringify(response)) } responseContent = response.candidates[0].content - if (responseContent.parts[0].functionCall) { + if (responseContent.parts.find(i => i.functionCall)) { // functionCall - const functionCall = responseContent.parts[0].functionCall + const functionCall = responseContent.parts.find(i => i.functionCall).functionCall + const text = responseContent.parts.find(i => i.text).text + if (text) { + // send reply first + opt.replyPureTextCallback && await opt.replyPureTextCallback(text) + } // Gemini有时候只回复一个空的functionCall,无语死了 if (functionCall.name) { logger.info(JSON.stringify(functionCall)) diff --git a/model/core.js b/model/core.js index 4060ed2..7d1b997 100644 --- a/model/core.js +++ b/model/core.js @@ -824,6 +824,11 @@ class Core { system += 'If I ask you to generate music or write songs, you need to reply with information suitable for Suno to generate music. Please use keywords such as Verse, Chorus, Bridge, Outro, and End to segment the lyrics, such as [Verse 1], The returned message is in JSON format, with a structure of ```json{"option": "Suno", "tags": "style", "title": "title of the song", "lyrics": "lyrics"}```.' } option.system = system + option.replyPureTextCallback = async (msg) => { + if (msg) { + await e.reply(msg, true) + } + } return await client.sendMessage(prompt, option) } else if (use === 'chatglm4') { const client = new ChatGLM4Client({