feat: 增加搜索来源选项

This commit is contained in:
ikechan8370 2023-06-24 16:12:04 +08:00
parent 592e18494b
commit 8d13145d2f
4 changed files with 33 additions and 14 deletions

View file

@ -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 = {}

View file

@ -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'
}