mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
feat: 增加搜索来源选项
This commit is contained in:
parent
592e18494b
commit
8d13145d2f
4 changed files with 33 additions and 14 deletions
37
utils/tools/SerpIkechan8370Tool.js
Normal file
37
utils/tools/SerpIkechan8370Tool.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { AbstractTool } from './AbstractTool.js'
|
||||
|
||||
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, 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'
|
||||
}
|
||||
})
|
||||
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! If you want to know details of a result, you can use website tool'
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue