mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-18 06:17:06 +00:00
feat: serp tool
This commit is contained in:
parent
ed337275d5
commit
9c07b4fef7
4 changed files with 51 additions and 1 deletions
|
|
@ -56,6 +56,7 @@ import { SearchMusicTool } from '../utils/tools/SearchMusicTool.js'
|
||||||
import { QueryStarRailTool } from '../utils/tools/QueryStarRailTool.js'
|
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";
|
||||||
try {
|
try {
|
||||||
await import('emoji-strip')
|
await import('emoji-strip')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -1940,7 +1941,8 @@ export class chatgpt extends plugin {
|
||||||
new WebsiteTool(),
|
new WebsiteTool(),
|
||||||
new JinyanTool(),
|
new JinyanTool(),
|
||||||
new KickOutTool(),
|
new KickOutTool(),
|
||||||
new WeatherTool()
|
new WeatherTool(),
|
||||||
|
new SerpTool(),
|
||||||
]
|
]
|
||||||
// if (e.sender.role === 'admin' || e.sender.role === 'owner') {
|
// if (e.sender.role === 'admin' || e.sender.role === 'owner') {
|
||||||
// tools.push(...[new JinyanTool(), new KickOutTool()])
|
// tools.push(...[new JinyanTool(), new KickOutTool()])
|
||||||
|
|
|
||||||
|
|
@ -794,6 +794,12 @@ export function supportGuoba () {
|
||||||
label: '高德APIKey',
|
label: '高德APIKey',
|
||||||
bottomHelpMessage: '用于查询天气',
|
bottomHelpMessage: '用于查询天气',
|
||||||
component: 'Input'
|
component: 'Input'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'azSerpKey',
|
||||||
|
label: 'Azure search key',
|
||||||
|
bottomHelpMessage: 'https://www.microsoft.com/en-us/bing/apis/bing-web-search-api',
|
||||||
|
component: 'Input'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
// 获取配置数据方法(用于前端填充显示数据)
|
// 获取配置数据方法(用于前端填充显示数据)
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ const defaultConfig = {
|
||||||
autoJapanese: false,
|
autoJapanese: false,
|
||||||
enableGenerateContents: false,
|
enableGenerateContents: false,
|
||||||
amapKey: '',
|
amapKey: '',
|
||||||
|
azSerpKey: '',
|
||||||
version: 'v2.6.2'
|
version: 'v2.6.2'
|
||||||
}
|
}
|
||||||
const _path = process.cwd()
|
const _path = process.cwd()
|
||||||
|
|
|
||||||
41
utils/tools/SerpTool.js
Normal file
41
utils/tools/SerpTool.js
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
import { AbstractTool } from './AbstractTool.js'
|
||||||
|
import {Config} from "../config.js";
|
||||||
|
|
||||||
|
export class SerpTool extends AbstractTool {
|
||||||
|
name = 'serp'
|
||||||
|
|
||||||
|
parameters = {
|
||||||
|
properties: {
|
||||||
|
q: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'search keyword'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
required: ['q']
|
||||||
|
}
|
||||||
|
|
||||||
|
func = async function (opts) {
|
||||||
|
let { q } = opts
|
||||||
|
let key = Config.azSerpKey
|
||||||
|
|
||||||
|
let serpRes = await fetch(`https://api.bing.microsoft.com/v7.0/search?q=${encodeURIComponent(q)}&mkt=zh-CN`, {
|
||||||
|
headers: {
|
||||||
|
'Ocp-Apim-Subscription-Key': key
|
||||||
|
}
|
||||||
|
})
|
||||||
|
serpRes = await serpRes.json()
|
||||||
|
|
||||||
|
let res = serpRes.webPages.value
|
||||||
|
res.forEach(p => {
|
||||||
|
delete p.displayUrl
|
||||||
|
delete p.isFamilyFriendly
|
||||||
|
delete p.thumbnailUrl
|
||||||
|
delete p.id
|
||||||
|
delete p.isNavigational
|
||||||
|
|
||||||
|
})
|
||||||
|
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!'
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue