-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path3_create_report.py
More file actions
40 lines (35 loc) · 1.12 KB
/
3_create_report.py
File metadata and controls
40 lines (35 loc) · 1.12 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
"""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/v1/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()
report_id = report["reportId"]
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/v1/reports/{report_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