Spaces:
Running
Running
Update app.py
Browse filesBrave search uses Free_AI plan and returns snippets, source, age
app.py
CHANGED
@@ -78,15 +78,34 @@ def get_brave_search_results(query: str):
|
|
78 |
response = requests.get(
|
79 |
url,
|
80 |
headers= {"Accept": "application/json",
|
81 |
-
"X-Subscription-Token":
|
82 |
},
|
83 |
)
|
|
|
|
|
|
|
84 |
jdata = response.json()
|
85 |
web_results = jdata['web']['results']
|
86 |
for item in web_results:
|
87 |
title = item['title']
|
88 |
description = item['description']
|
89 |
rv += f'{title}: {description} --'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
return rv
|
91 |
|
92 |
|
|
|
78 |
response = requests.get(
|
79 |
url,
|
80 |
headers= {"Accept": "application/json",
|
81 |
+
"X-Subscription-Token": BRAVE_KEY
|
82 |
},
|
83 |
)
|
84 |
+
rv ='''Following are list items delineated by *item separator*
|
85 |
+
At the end of each item is (item source, item age)
|
86 |
+
*item separator* '''
|
87 |
jdata = response.json()
|
88 |
web_results = jdata['web']['results']
|
89 |
for item in web_results:
|
90 |
title = item['title']
|
91 |
description = item['description']
|
92 |
rv += f'{title}: {description} --'
|
93 |
+
try: # extra_snippets can be missing
|
94 |
+
for snip in item['extra_snippets']:
|
95 |
+
rv += (snip + ' ')
|
96 |
+
except:
|
97 |
+
pass
|
98 |
+
try:
|
99 |
+
host = item['meta_url']['hostname']
|
100 |
+
except:
|
101 |
+
host = 'unknown'
|
102 |
+
try:
|
103 |
+
age = item['age']
|
104 |
+
except:
|
105 |
+
age = 'unknown'
|
106 |
+
rv += f' (Item source: {host}, Item age: {age})'
|
107 |
+
rv += ' *item separator* '
|
108 |
+
|
109 |
return rv
|
110 |
|
111 |
|