-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3_create_report.py
More file actions
44 lines (39 loc) · 1.33 KB
/
Copy path3_create_report.py
File metadata and controls
44 lines (39 loc) · 1.33 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
37
38
39
40
41
42
43
44
"""Create a research report and poll until complete."""
import os
import time
import requests
api_key = os.environ["ELICIT_API_KEY"]
# Create
response = requests.post(
"https://elicit.com/api/v2/sessions/reports",
headers={"Authorization": f"Bearer {api_key}"},
json={
"researchQuestion": "What is the evidence for melatonin supplementation improving sleep quality in adults?",
"maxSearchPapers": 50,
"maxExtractPapers": 10,
},
)
response.raise_for_status()
report = response.json()
session_id = report["sessionId"]
print(f"Report created: {report['url']}")
# Poll (reports take 5-15 minutes)
while True:
time.sleep(30)
report = requests.get(
f"https://elicit.com/api/v2/sessions/reports/{session_id}",
headers={"Authorization": f"Bearer {api_key}"},
).json()
print(f"Status: {report['status']}")
if report["status"] == "completed":
print(f"\n{report['result']['title']}")
print(report["result"]["summary"])
print(f"\n{report['url']}")
break
elif report["status"] == "failed":
print(f"Report failed: {report.get('error')}")
break
elif report["status"] == "pausedForInsufficientQuota":
# out of quota mid-run — resume later, see 6_list_sessions.py
print(f"Report paused: {report['url']}")
break