diff --git a/apps/bym.js b/apps/bym.js index 8546386..337524c 100644 --- a/apps/bym.js +++ b/apps/bym.js @@ -134,7 +134,7 @@ export class bym extends plugin { // 使用 specialUserNotice 更新提示词 opt.system = `你的名字是“${Config.assistantLabel}”,你在一个qq群里,群号是${group},当前和你说话的人群名片是${card}, qq号是${sender}${specialUserNotice}, 请你结合用户的发言和聊天记录作出回应,要求表现得随性一点,最好参与讨论,混入其中。${specialUserNotice ? '你要重视他的发言。' : ''}与你相关的话题时,你可以去回应一下,不相关你就随便应付就行了,不要过分插科打诨,不知道说什么可以复读群友的话。 - 当群友要求你做搜索、关键词搜索(也可以进行URL搜索摘要,当URL搜不到结果的时候,你可以尝试使用URL提取工具来获取结果)、发图、发视频、画图、禁言、踢人、改头衔和昵称等操作时,需要使用工具,不可以直接发文字来蒙混过关。你必须根据需要来调用各种工具,并回复相关问题。要求优先使用中文进行对话。你也可以自行根据当前话题内容选择性的调用这些工具,增加趣味性,以及对违规的群友使用禁言工具进行惩罚,等这种自我主张式的调用方法来进行合理且富有人性的聊天,在进行搜索时需要详细的给出工具摘要后的内容,也可以在对不懂的问题自行调用自定义搜索工具来解答你的疑惑! + 当群友要求你做搜索、关键词搜索、URL提取摘要、发图、发视频、画图、禁言、踢人、改头衔和昵称等操作时,需要使用工具,不可以直接发文字来蒙混过关。你必须根据需要来调用各种工具,并回复相关问题。要求优先使用中文进行对话。你也可以自行根据当前话题内容选择性的调用这些工具,增加趣味性,以及对违规的群友使用禁言工具进行惩罚,等这种自我主张式的调用方法来进行合理且富有人性的聊天,在进行搜索或URL提取时需要详细的给出工具返回的内容,也可以在对不懂的问题自行调用自定义搜索工具来解答你的疑惑! 以下是你可以使用的表情列表: ${Object.values(faceMap).map(face => `[/${face}]`).join(',')} 请在回复中适当使用以上表情,但是不要过度频繁使用这些表情。禁止使用表情列表之外的任何表情,比如[/思考]。` + diff --git a/utils/tools/CustomSearchTool.js b/utils/tools/CustomSearchTool.js index f6c0bb9..bb3896d 100644 --- a/utils/tools/CustomSearchTool.js +++ b/utils/tools/CustomSearchTool.js @@ -1,7 +1,7 @@ -import { AbstractTool } from './AbstractTool.js' -import fetch from 'node-fetch' -import { Config } from '../config.js' -import { UrlExtractionTool } from './UrlExtractionTool.js' // 1. 引入 UrlExtractionTool +import { AbstractTool } from './AbstractTool.js'; +import fetch from 'node-fetch'; +import { Config } from '../config.js'; +// import { UrlExtractionTool } from './UrlExtractionTool.js'; // 不再需要引入 UrlExtractionTool /** * 自定义搜索工具类 @@ -17,7 +17,7 @@ export class CustomSearchTool extends AbstractTool { properties: { query: { type: 'string', - description: 'Search keyword or URL', + description: 'Search keyword', // 修改描述,不再支持 URL }, length: { type: 'integer', @@ -40,48 +40,26 @@ export class CustomSearchTool extends AbstractTool { } try { - // 尝试使用OpenAI API进行搜索或摘要 - let result = await searchOrSummarize(query, length); - - // 2. 修改 func 方法: 判断是否为 URL 且 searchOrSummarize 结果不理想 - const isUrl = /^(https?:\/\/)/i.test(query); - if (isUrl && (!result || result.includes("failed") || result.trim() === '')) { // 假设不理想的结果包括空字符串或包含"failed" - console.log(`[CustomSearchTool] searchOrSummarize failed or returned empty for URL, trying UrlExtractionTool...`); - - // 创建 UrlExtractionTool 实例 - const urlTool = new UrlExtractionTool(); - - // 调用 UrlExtractionTool 的 func 方法提取 URL 内容 - const extractionResult = await urlTool.func({ message: query, appendContent: false }); - - // 3. 整合提取的内容: 如果提取成功,则将提取的内容作为 searchOrSummarize 的输入 - if (extractionResult && extractionResult.extractedContent) { - console.log(`[CustomSearchTool] Successfully extracted content using UrlExtractionTool, summarizing...`); - result = await searchOrSummarize(extractionResult.extractedContent, length); - } else { - // 如果 UrlExtractionTool 也失败了,则返回错误信息 - return `Failed to extract content from URL and summarize. ${extractionResult.message}`; - } - } + // 直接使用OpenAI API进行搜索或摘要 + const result = await searchOrSummarize(query, length); console.log(`Search or summarization result: ${result}`); // 返回搜索结果或摘要给AI return result; } catch (error) { - // 4. 优化错误处理: 捕获 UrlExtractionTool 可能抛出的错误 console.error('Search or summarization failed:', error); return `Search or summarization failed, please check the logs. ${error.message}`; } }; // 工具描述 - description = 'Use OpenAI API for custom search or summarize URL content, providing comprehensive search results or summaries. If a URL is provided and summarization fails, it will attempt to extract the content first and then summarize.'; + description = 'Use OpenAI API for custom search, providing comprehensive search results or summaries. This tool does not handle URLs.'; // 修改描述,明确不再处理 URL } /** * 使用OpenAI API进行搜索或摘要 - * @param {string} query - 搜索关键词或URL提取的内容 + * @param {string} query - 搜索关键词 * @param {number} length - 期望的摘要长度(以句子为单位) * @returns {Promise} - 搜索结果或摘要 */ @@ -102,11 +80,11 @@ async function searchOrSummarize(query, length) { messages: [ { role: 'system', - content: `You are a search and summarization assistant. Please use English to search based on the following keywords or summarize the provided text, and return a summary of ${length} sentences.`, + content: `You are a search and summarization assistant. Please use English to search based on the following keywords and return a summary of ${length} sentences.`, // 简化提示词 }, { role: 'user', - content: `Search or summarize: ${query}`, + content: `Search: ${query}`, // 简化提示词 }, ], max_tokens: 1000 * length, diff --git a/utils/tools/UrlExtractionTool.js b/utils/tools/UrlExtractionTool.js index 013453f..9f20dd4 100644 --- a/utils/tools/UrlExtractionTool.js +++ b/utils/tools/UrlExtractionTool.js @@ -23,33 +23,29 @@ export class UrlExtractionTool extends AbstractTool { type: 'string', description: 'The message containing URLs to be extracted.', }, - appendContent: { - type: 'boolean', - description: 'Whether to append the extracted content to the original message. Defaults to true.', - }, }, required: ['message'], }; // 工具描述 - description = 'Extracts URLs from a given message and optionally retrieves the content of those URLs, appending it to the original message.'; + description = 'Extracts URLs from a given message and retrieves the content of those URLs. Returns the extracted content to the AI.'; // 更新描述 /** * 工具执行函数 * @param {Object} opt - 工具参数 * @param {Object} ai - AI对象 (未使用) - * @returns {Promise<{message: string, extractedContent: string}>} - 包含处理后的消息和提取内容的JSON对象 + * @returns {Promise} - 提取的URL内容 */ func = async function (opt, ai) { - let { message, appendContent = true } = opt; + let { message } = opt; if (!message) { return 'The message parameter is required.'; } try { - const result = await processMessageWithUrls(message, appendContent); - logger.mark(`[URL Extraction] Processed message: ${result.message}, Extracted content: ${result.extractedContent}`); - return result; + const result = await processMessageWithUrls(message); + logger.mark(`[URL Extraction] Processed message: ${message}, Extracted content: ${result}`); + return result; // 直接返回提取的内容 } catch (error) { logger.error(`[URL Extraction] URL extraction failed: ${error.message}`); return `URL extraction failed, please check the logs. ${error.message}`; @@ -137,17 +133,15 @@ async function extractUrlContent(url) { /** * 处理消息中的URL并提取内容 * @param {string} message 用户消息 - * @param {boolean} appendContent 是否将提取的内容附加到消息中,默认为true - * @returns {Promise<{message: string, extractedContent: string}>} 处理后的消息和提取的内容 + * @returns {Promise} 提取的URL内容 */ -async function processMessageWithUrls(message, appendContent = true) { +async function processMessageWithUrls(message) { const urls = extractUrls(message); if (urls.length === 0) { - return { message, extractedContent: '' }; + return ''; // 没有 URL 则返回空字符串 } logger.mark(`[URL处理]从消息中提取到${urls.length}个URL`); - let processedMessage = message; let extractedContent = ''; // 使用 Promise.all 并发处理多个 URL @@ -174,11 +168,8 @@ async function processMessageWithUrls(message, appendContent = true) { if (item) { const urlContent = `\n\n提取的URL内容(${item.url}):\n内容: ${item.content}`; extractedContent += urlContent; - if (appendContent) { - processedMessage += urlContent; - } } }); - return { message: processedMessage, extractedContent }; + return extractedContent; // 返回提取的内容字符串 } \ No newline at end of file