-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path5_systematic_review.py
More file actions
66 lines (60 loc) · 2.28 KB
/
Copy path5_systematic_review.py
File metadata and controls
66 lines (60 loc) · 2.28 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""Run a systematic review: search, screen, extract, and generate a report."""
import os
import time
import requests
api_key = os.environ["ELICIT_API_KEY"]
# Create
response = requests.post(
"https://elicit.com/api/v2/sessions/systematic-reviews",
headers={"Authorization": f"Bearer {api_key}"},
json={
"researchQuestion": "Do GLP-1 receptor agonists reduce major adverse cardiovascular events in adults with type 2 diabetes?",
"searches": [
{"query": "GLP-1 receptor agonist cardiovascular outcomes", "maxResults": 100},
{"query": "GLP-1 agonist MACE type 2 diabetes", "corpus": "pubmed", "maxResults": 100},
],
"abstractScreening": {
"criteria": [
{
"name": "Human RCT",
"instructions": "The study must be a randomized controlled trial in human adults.",
}
]
},
"extraction": {
"questions": [
{
"name": "MACE hazard ratio",
"instructions": "Extract the hazard ratio and 95% confidence interval for major adverse cardiovascular events.",
}
]
},
"generateReport": True,
},
)
response.raise_for_status()
review = response.json()
session_id = review["sessionId"]
print(f"Review created: {review['url']}")
# Poll — reviews run through several stages and can take a while
while True:
time.sleep(60)
review = requests.get(
f"https://elicit.com/api/v2/sessions/systematic-reviews/{session_id}",
headers={"Authorization": f"Bearer {api_key}"},
).json()
print(f"Status: {review['status']} ({review['executionStage']})")
if review["status"] != "processing":
break
if review["status"] == "completed":
# export URLs are presigned, valid for 7 days
data = review["data"]
for stage in ("search", "screen", "fulltext", "extract"):
if stage in data:
print(f" {stage} export: {data[stage]['csv']}")
if "report" in data:
print(f"\n{data['report']['result']['title']}")
print(data["report"]["result"]["summary"])
print(f" PDF: {data['report']['pdf']}")
elif review["status"] == "failed":
print(f"Review failed: {review.get('error')}")