Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SearchApi Tool #3931

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ AZURE_AI_SEARCH_SEARCH_OPTION_SELECT=
GOOGLE_SEARCH_API_KEY=
GOOGLE_CSE_ID=

# SearchApi
#-----------------
SEARCHAPI_API_KEY=

# SerpAPI
#-----------------
SERPAPI_API_KEY=
Expand Down
13 changes: 13 additions & 0 deletions api/app/clients/tools/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@
}
]
},
{
"name": "SearchApi",
"pluginKey": "searchapi",
"description": "SearchApi is a robust real-time SERP API delivering structured data from a collection of search engines.",
"icon": "https://www.searchapi.io/press/searchapi-logo-symbol-screen.png",
"authConfig": [
{
"authField": "SEARCHAPI_API_KEY",
"label": "SearchApi Private API Key",
"description": "Private Key for SearchApi. Register at <a href='https://www.searchapi.io/'>SearchApi</a> to obtain a private key."
}
]
},
{
"name": "Serpapi",
"pluginKey": "serpapi",
Expand Down
12 changes: 11 additions & 1 deletion api/app/clients/tools/util/handleTools.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { ZapierToolKit } = require('langchain/agents');
const { Calculator } = require('langchain/tools/calculator');
const { WebBrowser } = require('langchain/tools/webbrowser');
const { SerpAPI, ZapierNLAWrapper } = require('langchain/tools');
const { SerpAPI, ZapierNLAWrapper, SearchApi } = require('langchain/tools');
const { OpenAIEmbeddings } = require('langchain/embeddings/openai');
const { getUserPluginAuthValue } = require('~/server/services/PluginService');
const {
Expand Down Expand Up @@ -208,6 +208,16 @@ const loadTools = async ({
browser.description_for_model = browser.description;
return browser;
},
searchapi: async () => {
let apiKey = process.env.SEARCHAPI_API_KEY;
if (!apiKey) {
apiKey = await getUserPluginAuthValue(user, 'SEARCHAPI_API_KEY');
}
return new SearchApi(apiKey, {
hl: 'en',
gl: 'us',
});
},
serpapi: async () => {
let apiKey = process.env.SERPAPI_API_KEY;
if (!apiKey) {
Expand Down