-
Notifications
You must be signed in to change notification settings - Fork 4
/
brave.py
45 lines (34 loc) · 1.19 KB
/
brave.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
import requests
import os
'''
Things to ask about
- how big is this now
'''
def brave_req(query: str):
url = f"https://api.search.brave.com/res/v1/web/search?q={query.replace(' ', '+')}"
payload = {}
headers = {
'Accept': 'application/json',
'Accept-Encoding': 'gzip',
'X-Subscription-Token': os.getenv("BRAVE_API_KEY")
}
response = requests.request("GET", url, headers=headers, data=payload)
return response.json()
# take the brave response and concat all of the descriptiosn in the web results
def concat_brave_search_results(brave_search_response):
results = brave_search_response['web']['results']
concatted = ""
for result in results:
concatted += result['description'] + "\n"
return concatted
# hits the summarizer endpoint of the brave api
def summarizer(query: str):
url = f"https://api.search.brave.com/res/v1/web/search?q={query.replace(' ', '+')}&summary=1"
payload = {}
headers = {
'Accept': 'application/json',
'Accept-Encoding': 'gzip',
'X-Subscription-Token': os.getenv("BRAVE_API_KEY")
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)