diff --git a/apps/chat.js b/apps/chat.js index 1082930..5aa9903 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -57,7 +57,7 @@ import { QueryStarRailTool } from '../utils/tools/QueryStarRailTool.js' import { WebsiteTool } from '../utils/tools/WebsiteTool.js' import { WeatherTool } from '../utils/tools/WeatherTool.js' import { SerpTool } from '../utils/tools/SerpTool.js' -import { SerpGoogleTool } from '../utils/tools/SerpGoogleTool.js' +import { SerpIkechan8370Tool } from '../utils/tools/SerpIkechan8370Tool.js' try { await import('emoji-strip') } catch (err) { @@ -1932,21 +1932,21 @@ export class chatgpt extends plugin { let sender = e.sender.user_id let serpTool switch (Config.serpSource) { - case 'google': { - serpTool = new SerpGoogleTool() + case 'ikechan8370': { + serpTool = new SerpIkechan8370Tool() break } - case 'bing': { + case 'azure': { if (!Config.azSerpKey) { - logger.warn('未配置bing搜索密钥,转为使用google搜索') - serpTool = new SerpGoogleTool() + logger.warn('未配置bing搜索密钥,转为使用ikechan8370搜索源') + serpTool = new SerpIkechan8370Tool() } else { serpTool = new SerpTool() } break } default: { - serpTool = new SerpGoogleTool() + serpTool = new SerpIkechan8370Tool() } } diff --git a/guoba.support.js b/guoba.support.js index c3fba38..719e914 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -800,7 +800,19 @@ export function supportGuoba () { label: 'Azure search key', bottomHelpMessage: 'https://www.microsoft.com/en-us/bing/apis/bing-web-search-api', component: 'Input' - } + }, + { + field: 'serpSource', + label: '搜索来源,azure需填写key,ikechan8370为作者自备源', + component: 'Select', + componentProps: { + options: [ + { label: 'Azure', value: 'azure' }, + { label: 'ikechan8370', value: 'ikechan8370' } + // { label: '数据', value: 'buffer' } + ] + } + }, ], // 获取配置数据方法(用于前端填充显示数据) getConfigData () { diff --git a/utils/config.js b/utils/config.js index a1b2f28..455abfb 100644 --- a/utils/config.js +++ b/utils/config.js @@ -127,8 +127,8 @@ const defaultConfig = { enableGenerateContents: false, amapKey: '', azSerpKey: '', - serpSource: 'google', - version: 'v2.6.2' + serpSource: 'ikechan8370', + version: 'v2.7.0' } const _path = process.cwd() let config = {} diff --git a/utils/tools/SerpGoogleTool.js b/utils/tools/SerpIkechan8370Tool.js similarity index 64% rename from utils/tools/SerpGoogleTool.js rename to utils/tools/SerpIkechan8370Tool.js index f95e038..f1e4b41 100644 --- a/utils/tools/SerpGoogleTool.js +++ b/utils/tools/SerpIkechan8370Tool.js @@ -1,21 +1,28 @@ import { AbstractTool } from './AbstractTool.js' -export class SerpGoogleTool extends AbstractTool { - name = 'google' +export class SerpIkechan8370Tool extends AbstractTool { + name = 'search' parameters = { properties: { q: { type: 'string', description: 'search keyword' + }, + source: { + type: 'string', + enum: ['google', 'bing', 'baidu'] } }, required: ['q'] } func = async function (opts) { - let { q } = opts - let serpRes = await fetch(`https://serp.ikechan8370.com/google?q=${encodeURIComponent(q)}&lang=zh-CN&limit=10`, { + let { q, source } = opts + if (!source) { + source = 'google' + } + let serpRes = await fetch(`https://serp.ikechan8370.com/${source}?q=${encodeURIComponent(q)}&lang=zh-CN&limit=10`, { headers: { 'X-From-Library': 'ikechan8370' }