-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path5_systematic_review.js
More file actions
67 lines (62 loc) · 2.2 KB
/
Copy path5_systematic_review.js
File metadata and controls
67 lines (62 loc) · 2.2 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
67
// Run a systematic review: search, screen, extract, and generate a report
const apiKey = process.env.ELICIT_API_KEY;
// Create
const createResponse = await fetch("https://elicit.com/api/v2/sessions/systematic-reviews", {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
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,
}),
});
const { sessionId, url } = await createResponse.json();
console.log(`Review created: ${url}`);
// Poll — reviews run through several stages and can take a while
let review;
while (true) {
await new Promise((r) => setTimeout(r, 60_000));
const resp = await fetch(`https://elicit.com/api/v2/sessions/systematic-reviews/${sessionId}`, {
headers: { Authorization: `Bearer ${apiKey}` },
});
review = await resp.json();
console.log(`Status: ${review.status} (${review.executionStage})`);
if (review.status !== "processing") break;
}
if (review.status === "completed") {
// export URLs are presigned, valid for 7 days
for (const stage of ["search", "screen", "fulltext", "extract"]) {
if (review.data[stage]) console.log(` ${stage} export: ${review.data[stage].csv}`);
}
if (review.data.report) {
console.log(`\n${review.data.report.result.title}`);
console.log(review.data.report.result.summary);
console.log(` PDF: ${review.data.report.pdf}`);
}
} else if (review.status === "failed") {
console.error("Review failed:", review.error);
}