mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 22:07:10 +00:00
feat: 增加搜索来源选项
This commit is contained in:
parent
592e18494b
commit
8d13145d2f
4 changed files with 33 additions and 14 deletions
14
apps/chat.js
14
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 () {
|
||||
|
|
|
|||
|
|
@ -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 = {}
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue