Public
Script
October 23, 2023
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
import { fetch } from "https://esm.town/v/std/fetch";
export async function chatWithPdfRetriever(query: string, pdf_url: string) {
const loadUrl = "https://cardinal.tail8de85.ts.net/pdf/load";
const queryUrl = "https://cardinal.tail8de85.ts.net/pdf/query";
// First POST request to load the PDF
const loadResponse = await fetch(loadUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"pdf_url": pdf_url,
}),
});
if (!loadResponse.ok) {
throw new Error(`Failed to load PDF. Status: ${loadResponse.status}`);
}
// Second POST request to query the loaded PDF
const queryResponse = await fetch(queryUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"query": query,
"pdf_url": pdf_url,
}),
});
if (!queryResponse.ok) {
throw new Error(`Failed to query PDF. Status: ${queryResponse.status}`);
}
// Return the response from the second call
return await queryResponse.json();
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023