feat: support googleCustomSearchTool

This commit is contained in:
Hk-Gosuto 2023-12-26 13:23:57 +08:00
parent e60c0f009b
commit 1c845c5676
2 changed files with 49 additions and 26 deletions

View File

@ -36,19 +36,53 @@
## 主要功能 ## 主要功能
- 除插件工具外,与原项目保持一致 [ChatGPT-Next-Web 主要功能](https://github.com/Yidadaa/ChatGPT-Next-Web#主要功能) - 除插件工具外,与原项目保持一致 [ChatGPT-Next-Web 主要功能](https://github.com/Yidadaa/ChatGPT-Next-Web#主要功能)
- 支持 GPT-4V(视觉) 模型 - 支持 GPT-4V(视觉) 模型
- 需要配置对象存储服务,请参考 [对象存储服务配置指南](./docs/s3-oss.md) 配置 - 需要配置对象存储服务,请参考 [对象存储服务配置指南](./docs/s3-oss.md) 配置
- 基于 [LangChain](https://github.com/hwchase17/langchainjs) 实现的插件功能,目前支持以下插件,未来会添加更多 - 基于 [LangChain](https://github.com/hwchase17/langchainjs) 实现的插件功能,目前支持以下插件,未来会添加更多
- 搜索 - 搜索(优先级:`GoogleCustomSearch > SerpAPI > BingSerpAPI > ChooseSearchEngine > DuckDuckGo`
- [SerpAPI](https://js.langchain.com/docs/api/tools/classes/SerpAPI)
- [BingSerpAPI](https://js.langchain.com/docs/api/tools/classes/BingSerpAPI) - [GoogleCustomSearch](https://api.js.langchain.com/classes/langchain_tools.GoogleCustomSearch.html)
- 环境变量:
- `GOOGLE_API_KEY`
- `GOOGLE_CSE_ID`
- 申请参考:[说明](https://stackoverflow.com/questions/37083058/programmatically-searching-google-in-python-using-custom-search)
- [SerpAPI](https://api.js.langchain.com/classes/langchain_tools.SerpAPI.html)
- 环境变量:`SERPAPI_API_KEY`
- 申请地址:[SerpApi: Google Search API](https://serpapi.com/)
- [BingSerpAPI](https://api.js.langchain.com/classes/langchain_tools.BingSerpAPI.html)
- 环境变量:`BING_SEARCH_API_KEY`
- 申请地址:[Web Search API | Microsoft Bing](https://www.microsoft.com/en-us/bing/apis/bing-web-search-api)
- ChooseSearchEngine
- 环境变量:`CHOOSE_SEARCH_ENGINE`
可选项如下:
- google
- baidu
- 说明此项为直连搜索引擎免去api试用量小的烦恼但可能因为网络问题导致无法使用
- ⚠ 注意:已知在 vercel 环境下会出现调用不稳定的情况 https://github.com/Hk-Gosuto/ChatGPT-Next-Web-LangChain/issues/89#issuecomment-1868887904
- DuckDuckGo - DuckDuckGo
- 计算 - 计算
- [Calculator](https://js.langchain.com/docs/api/tools_calculator/classes/Calculator) - [Calculator](https://js.langchain.com/docs/api/tools_calculator/classes/Calculator)
- 网络请求 - 网络请求
- [WebBrowser](https://js.langchain.com/docs/api/tools_webbrowser/classes/WebBrowser) - [WebBrowser](https://js.langchain.com/docs/api/tools_webbrowser/classes/WebBrowser)
- PDFBrowser - PDFBrowser
- ⚠ 仅在非vercel环境部署时可用 ⚠ - ⚠ 仅在非 vercel 环境部署时可用 ⚠
- 其它 - 其它
- [Wiki](https://js.langchain.com/docs/api/tools/classes/WikipediaQueryRun) - [Wiki](https://js.langchain.com/docs/api/tools/classes/WikipediaQueryRun)
- DALL-E 3 - DALL-E 3
@ -60,6 +94,7 @@
- 使用本插件需要一定的专业知识Stable Diffusion 本身的相关问题不在本项目的解答范围内,如果您确定要使用本插件请参考 [Stable Diffusion 插件配置指南](./docs/stable-diffusion-plugin-cn.md) 文档进行配置 - 使用本插件需要一定的专业知识Stable Diffusion 本身的相关问题不在本项目的解答范围内,如果您确定要使用本插件请参考 [Stable Diffusion 插件配置指南](./docs/stable-diffusion-plugin-cn.md) 文档进行配置
- StableDiffusion 插件需要配置对象存储服务,请参考 [对象存储服务配置指南](./docs/s3-oss.md) 配置 - StableDiffusion 插件需要配置对象存储服务,请参考 [对象存储服务配置指南](./docs/s3-oss.md) 配置
- Arxiv - Arxiv
- 支持 Gemini-Pro 模型(同步上游仓库并修改接口为流式传输) - 支持 Gemini-Pro 模型(同步上游仓库并修改接口为流式传输)
- 以下功能目前还不支持 - 以下功能目前还不支持
- **插件功能** - **插件功能**
@ -72,11 +107,7 @@
- [x] 支持使用 DuckDuckGo 作为默认搜索引擎 - [x] 支持使用 DuckDuckGo 作为默认搜索引擎
当前配置 `SERPAPI_API_KEY` 时优先使用 `SerpAPI` 作为搜索插件,不配置时默认使用 `DuckDuckGo` 作为搜索插件。 不配置时默认使用 `DuckDuckGo` 作为搜索插件。
当前配置 `BING_SEARCH_API_KEY` 时优先使用 `BingSerpAPI` 作为搜索插件,不配置时默认使用 `DuckDuckGo` 作为搜索插件。
优先级:`SerpAPI > BingSerpAPI > DuckDuckGo`
- [x] 插件列表页面开发 - [x] 插件列表页面开发
- [x] 支持开关指定插件 - [x] 支持开关指定插件
@ -142,23 +173,6 @@ code1,code2,code3
OpanAI 密钥,你在 openai 账户页面申请的 api key。 OpanAI 密钥,你在 openai 账户页面申请的 api key。
### `SERPAPI_API_KEY` (可选)
[SerpApi: Google Search API](https://serpapi.com/)
### `BING_SEARCH_API_KEY` (可选)
[Web Search API | Microsoft Bing](https://www.microsoft.com/en-us/bing/apis/bing-web-search-api)
### `CHOOSE_SEARCH_ENGINE` (可选)
此项为直连搜索引擎免去api试用量小的烦恼但可能因为网络问题导致无法使用
可选项如下:
- google
- baidu
### `CODE` (可选) ### `CODE` (可选)
访问密码,可选,可以使用逗号隔开多个密码。 访问密码,可选,可以使用逗号隔开多个密码。

View File

@ -242,6 +242,15 @@ export class AgentApi {
func: async (input: string) => serpAPITool.call(input), func: async (input: string) => serpAPITool.call(input),
}); });
} }
if (process.env.GOOGLE_CSE_ID && process.env.GOOGLE_API_KEY) {
console.log("use googleCustomSearchTool");
let googleCustomSearchTool = new langchainTools["GoogleCustomSearch"]();
searchTool = new DynamicTool({
name: "google_custom_search",
description: googleCustomSearchTool.description,
func: async (input: string) => googleCustomSearchTool.call(input),
});
}
const tools = []; const tools = [];