mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 22:07:10 +00:00
feat: 增加一个google搜索源
This commit is contained in:
parent
9c07b4fef7
commit
76008952b5
4 changed files with 86 additions and 35 deletions
27
apps/chat.js
27
apps/chat.js
|
|
@ -55,8 +55,9 @@ import { SearchVideoTool } from '../utils/tools/SearchBilibiliTool.js'
|
|||
import { SearchMusicTool } from '../utils/tools/SearchMusicTool.js'
|
||||
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 { WeatherTool } from '../utils/tools/WeatherTool.js'
|
||||
import { SerpTool } from '../utils/tools/SerpTool.js'
|
||||
import { SerpGoogleTool } from '../utils/tools/SerpGoogleTool.js'
|
||||
try {
|
||||
await import('emoji-strip')
|
||||
} catch (err) {
|
||||
|
|
@ -1929,6 +1930,26 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
let isAdmin = e.sender.role === 'admin' || e.sender.role === 'owner'
|
||||
let sender = e.sender.user_id
|
||||
let serpTool
|
||||
switch (Config.serpSource) {
|
||||
case 'google': {
|
||||
serpTool = new SerpGoogleTool()
|
||||
break
|
||||
}
|
||||
case 'bing': {
|
||||
if (!Config.azSerpKey) {
|
||||
logger.warn('未配置bing搜索密钥,转为使用google搜索')
|
||||
serpTool = new SerpGoogleTool()
|
||||
} else {
|
||||
serpTool = new SerpTool()
|
||||
}
|
||||
break
|
||||
}
|
||||
default: {
|
||||
serpTool = new SerpGoogleTool()
|
||||
}
|
||||
}
|
||||
|
||||
let tools = [
|
||||
new SearchVideoTool(),
|
||||
new SendVideoTool(),
|
||||
|
|
@ -1942,7 +1963,7 @@ export class chatgpt extends plugin {
|
|||
new JinyanTool(),
|
||||
new KickOutTool(),
|
||||
new WeatherTool(),
|
||||
new SerpTool(),
|
||||
serpTool
|
||||
]
|
||||
// if (e.sender.role === 'admin' || e.sender.role === 'owner') {
|
||||
// tools.push(...[new JinyanTool(), new KickOutTool()])
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ const defaultConfig = {
|
|||
enableGenerateContents: false,
|
||||
amapKey: '',
|
||||
azSerpKey: '',
|
||||
serpSource: 'google',
|
||||
version: 'v2.6.2'
|
||||
}
|
||||
const _path = process.cwd()
|
||||
|
|
|
|||
30
utils/tools/SerpGoogleTool.js
Normal file
30
utils/tools/SerpGoogleTool.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { AbstractTool } from './AbstractTool.js'
|
||||
|
||||
export class SerpGoogleTool extends AbstractTool {
|
||||
name = 'google'
|
||||
|
||||
parameters = {
|
||||
properties: {
|
||||
q: {
|
||||
type: 'string',
|
||||
description: 'search keyword'
|
||||
}
|
||||
},
|
||||
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`, {
|
||||
headers: {
|
||||
'X-From-Library': 'ikechan8370'
|
||||
}
|
||||
})
|
||||
serpRes = await serpRes.json()
|
||||
|
||||
let res = serpRes.data
|
||||
return `the search results are here in json format:\n${JSON.stringify(res)}`
|
||||
}
|
||||
|
||||
description = 'Useful when you want to search something from the internet. If you don\'t know much about the user\'s question, just search about it!'
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { AbstractTool } from './AbstractTool.js'
|
||||
import {Config} from "../config.js";
|
||||
import { Config } from '../config.js'
|
||||
|
||||
export class SerpTool extends AbstractTool {
|
||||
name = 'serp'
|
||||
|
|
@ -32,7 +32,6 @@ export class SerpTool extends AbstractTool {
|
|||
delete p.thumbnailUrl
|
||||
delete p.id
|
||||
delete p.isNavigational
|
||||
|
||||
})
|
||||
return `the search results are here in json format:\n${JSON.stringify(res)}`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue