-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path3_create_report.js
More file actions
39 lines (35 loc) · 1.16 KB
/
3_create_report.js
File metadata and controls
39 lines (35 loc) · 1.16 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
// Create a research report and poll until complete
const apiKey = process.env.ELICIT_API_KEY;
// Create
const createResponse = await fetch("https://elicit.com/api/v1/reports", {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
researchQuestion: "What is the evidence for melatonin supplementation improving sleep quality in adults?",
maxSearchPapers: 50,
maxExtractPapers: 10,
}),
});
const { reportId, url } = await createResponse.json();
console.log(`Report created: ${url}`);
// Poll (reports take 5-15 minutes)
while (true) {
await new Promise((r) => setTimeout(r, 30_000));
const resp = await fetch(`https://elicit.com/api/v1/reports/${reportId}`, {
headers: { Authorization: `Bearer ${apiKey}` },
});
const report = await resp.json();
console.log(`Status: ${report.status}`);
if (report.status === "completed") {
console.log(`\n${report.result.title}`);
console.log(report.result.summary);
console.log(`\n${report.url}`);
break;
} else if (report.status === "failed") {
console.error("Report failed:", report.error);
break;
}
}