From 0fae49d5d16cf1d69f6fe42fadc6343b54c12f7f Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Mon, 17 Feb 2025 22:45:39 +0800 Subject: [PATCH] fix: adjust website tools; trim gemini intermediate response --- client/CustomGoogleGeminiClient.js | 6 +- utils/tools/WebsiteTool.js | 111 ++++++++++++++--------------- 2 files changed, 56 insertions(+), 61 deletions(-) diff --git a/client/CustomGoogleGeminiClient.js b/client/CustomGoogleGeminiClient.js index 86ddd85..efe76bf 100644 --- a/client/CustomGoogleGeminiClient.js +++ b/client/CustomGoogleGeminiClient.js @@ -281,10 +281,10 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient { // functionCall const functionCall = responseContent.parts.filter(i => i.functionCall).map(i => i.functionCall) const text = responseContent.parts.find(i => i.text)?.text - if (text) { + if (text && text.trim()) { // send reply first - logger.info('send message: ' + text) - opt.replyPureTextCallback && await opt.replyPureTextCallback(text) + logger.info('send message: ' + text.trim()) + opt.replyPureTextCallback && await opt.replyPureTextCallback(text.trim()) } let /** @type {FunctionResponse[]} **/ fcResults = [] for (let fc of functionCall) { diff --git a/utils/tools/WebsiteTool.js b/utils/tools/WebsiteTool.js index 34a11b9..0f509d6 100644 --- a/utils/tools/WebsiteTool.js +++ b/utils/tools/WebsiteTool.js @@ -6,6 +6,58 @@ import proxy from 'https-proxy-agent' import { getMaxModelTokens } from '../common.js' import { ChatGPTPuppeteer } from '../browser.js' import { CustomGoogleGeminiClient } from '../../client/CustomGoogleGeminiClient.js' + +/** + * Generated by GPT-4o + * @param html + * @returns {*} + */ +function cleanHTML (html) { + // 1. 移除