forked from ntthanh2603/gemini-web-to-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeep_search_client.py
More file actions
36 lines (30 loc) · 1.02 KB
/
Copy pathdeep_search_client.py
File metadata and controls
36 lines (30 loc) · 1.02 KB
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
import json
import time
import requests
BASE = "http://localhost:4981/gemini/v1beta"
with requests.post(
f"{BASE}/interactions",
json={
"input": "Compare Elasticsearch vs OpenSearch architecture and performance",
"agent": "deep-research-pro-preview-12-2025",
"background": True,
"stream": True # ← bật streaming
},
stream=True,
headers={"Accept": "text/event-stream"}
) as resp:
for line in resp.iter_lines(decode_unicode=True):
if not line or not line.startswith("data:"):
continue
event = json.loads(line[5:].strip())
status = event.get("status", "")
if status == "in_progress":
print(f"[...] Đang nghiên cứu...", end="\r", flush=True)
elif status == "completed":
outputs = event.get("outputs") or []
if outputs:
print("\n" + outputs[-1]["text"])
break
elif status == "failed":
print("Error:", event.get("error"))
break