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