forked from alitrack/duckduckgo-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
21 lines (18 loc) · 639 Bytes
/
Copy pathdemo.py
File metadata and controls
21 lines (18 loc) · 639 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from httpx import get
def fetch_search_results(query):
"""
Fetch search results for a given query.
:param query: Search query string
:return: List of search results
"""
search = get('http://127.0.0.1:8000/search',
params={
'q': query,
'max_results': 3,
})
snippets = ""
for index, result in enumerate(search.json()):
snippet = f'[{index + 1}] "{result["body"]}" URL:{result["href"]}.'
snippets += snippet
return [{'role': 'system', 'content': snippets}]
print(fetch_search_results("ChatGPT 最新版本?"))