feat: 增加bing搜索插件支持

This commit is contained in:
Hk-Gosuto
2023-08-07 12:31:03 +08:00
parent f7bba11890
commit d693d51201
3 changed files with 44 additions and 28 deletions

View File

@@ -6,6 +6,7 @@ import { ChatOpenAI } from "langchain/chat_models/openai";
import { BaseCallbackHandler } from "langchain/callbacks";
import {
BingSerpAPI,
DynamicTool,
RequestsGetTool,
RequestsPostTool,
@@ -145,7 +146,14 @@ async function handle(req: NextRequest) {
});
let searchTool: Tool = new DuckDuckGo();
if (process.env.SERPAPI_API_KEY) {
if (process.env.BING_SEARCH_API_KEY) {
let bingSearchTool = new BingSerpAPI(process.env.BING_SEARCH_API_KEY);
searchTool = new DynamicTool({
name: "bing_search",
description: bingSearchTool.description,
func: async (input: string) => bingSearchTool.call(input),
});
} else if (process.env.SERPAPI_API_KEY) {
let serpAPITool = new SerpAPI(process.env.SERPAPI_API_KEY);
searchTool = new DynamicTool({
name: "google_search",