mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
fix: MALFORMED_FUNCTION_CALL
This commit is contained in:
parent
b9ed12adb7
commit
bde81c0a17
1 changed files with 8 additions and 2 deletions
|
|
@ -111,9 +111,10 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient {
|
||||||
* search: boolean,
|
* search: boolean,
|
||||||
* codeExecution: boolean,
|
* codeExecution: boolean,
|
||||||
* }} opt
|
* }} opt
|
||||||
|
* @param {number} retryTime 重试次数
|
||||||
* @returns {Promise<{conversationId: string?, parentMessageId: string, text: string, id: string}>}
|
* @returns {Promise<{conversationId: string?, parentMessageId: string, text: string, id: string}>}
|
||||||
*/
|
*/
|
||||||
async sendMessage (text, opt = {}) {
|
async sendMessage (text, opt = {}, retryTime = 3) {
|
||||||
let history = await this.getHistory(opt.parentMessageId)
|
let history = await this.getHistory(opt.parentMessageId)
|
||||||
let systemMessage = opt.system
|
let systemMessage = opt.system
|
||||||
// if (systemMessage) {
|
// if (systemMessage) {
|
||||||
|
|
@ -269,7 +270,7 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient {
|
||||||
*/
|
*/
|
||||||
let responseContent
|
let responseContent
|
||||||
/**
|
/**
|
||||||
* @type {{candidates: Array<{content: Content, groundingMetadata: GroundingMetadata}>}}
|
* @type {{candidates: Array<{content: Content, groundingMetadata: GroundingMetadata, finishReason: string}>}}
|
||||||
*/
|
*/
|
||||||
let response = await result.json()
|
let response = await result.json()
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
|
|
@ -277,6 +278,11 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient {
|
||||||
}
|
}
|
||||||
responseContent = response.candidates[0].content
|
responseContent = response.candidates[0].content
|
||||||
let groundingMetadata = response.candidates[0].groundingMetadata
|
let groundingMetadata = response.candidates[0].groundingMetadata
|
||||||
|
if (response.candidates[0].finishReason === 'MALFORMED_FUNCTION_CALL') {
|
||||||
|
logger.warn('遇到MALFORMED_FUNCTION_CALL,进行重试。')
|
||||||
|
return this.sendMessage(text, opt, retryTime--)
|
||||||
|
}
|
||||||
|
// todo 空回复也可以重试
|
||||||
if (responseContent.parts.filter(i => i.functionCall).length > 0) {
|
if (responseContent.parts.filter(i => i.functionCall).length > 0) {
|
||||||
// functionCall
|
// functionCall
|
||||||
const functionCall = responseContent.parts.filter(i => i.functionCall).map(i => i.functionCall)
|
const functionCall = responseContent.parts.filter(i => i.functionCall).map(i => i.functionCall)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue