-
Notifications
You must be signed in to change notification settings - Fork 838
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import aiohttp | ||
import requests | ||
import json | ||
|
||
from decouple import config | ||
from langchain_community.tools import BaseTool | ||
|
||
|
||
url = "https://google.serper.dev/search" | ||
|
||
|
||
class GoogleSearch(BaseTool): | ||
name = "PubMed® search" | ||
description = "useful for answering question about medical publications" | ||
return_direct = False | ||
|
||
def _run(self, query: str) -> str: | ||
headers = { | ||
"X-API-KEY": self.metadata.get("apiKey"), | ||
"Content-Type": "application/json", | ||
} | ||
payload = json.dumps({"q": query}) | ||
response = requests.request("POST", url, headers=headers, data=payload) | ||
return response.text | ||
|
||
async def _arun(self, query: str) -> str: | ||
headers = { | ||
"X-API-KEY": self.metadata.get("apiKey"), | ||
"Content-Type": "application/json", | ||
} | ||
payload = json.dumps({"q": query}) | ||
|
||
async with aiohttp.ClientSession() as session: | ||
async with session.post(url, headers=headers, data=payload) as response: | ||
return await response.text() |
2 changes: 2 additions & 0 deletions
2
libs/superagent/prisma/migrations/20240331072847_google_search_tool/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterEnum | ||
ALTER TYPE "ToolType" ADD VALUE 'GOOGLE_SEARCH'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ enum ToolType { | |
RESEARCH | ||
GITHUB | ||
SCRAPER | ||
GOOGLE_SEARCH | ||
} | ||
|
||
enum DatasourceType { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters