-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool.py
53 lines (42 loc) · 1.45 KB
/
tool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import json
import os
import requests
from dotenv import load_dotenv
load_dotenv()
"""
Tool Functions
- First, add the description of the tool in `tools`.
- Then, add the specific implementation of the tool in `tools`.
"""
class Tools:
def __init__(self) -> None:
self.toolConfig = self._tools()
def _tools(self):
tools = [
{
'name_for_human': 'Exa Search',
'name_for_model': 'exa_search',
'description_for_model': 'Exa.ai Search is a powerful search engine that can be used to access the internet, query the latest research developments, stay updated with current news, and more.',
'parameters': [
{
'name': 'search_query',
'description': 'Search for keywords or phrases',
'required': True,
'schema': {'type': 'string'},
}
],
}
]
return tools
def exa_search(self, search_query: str):
url = "https://api.exa.ai/answer"
payload = json.dumps({
"query": search_query,
"text": True
})
headers = {
'Authorization': f'Bearer {os.getenv("EXA-API-KEY")}',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload).json()
return response["answer"]