-
Notifications
You must be signed in to change notification settings - Fork 5
/
tutorial-search.js
25 lines (23 loc) · 857 Bytes
/
tutorial-search.js
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
export default async function tutorialSearch(request, response) {
const DC_API_URL = "https://api.cloud.deepset.ai/api/v1/workspaces"
const options = {
method: 'POST',
headers: {
accept: 'application/json',
'content-type': 'application/json',
authorization: `Bearer ${process.env.DC_API_KEY}`
},
body: JSON.stringify({debug: false, queries: [request.query.query]})
};
try {
const dcResponse = await fetch(`${DC_API_URL}/${process.env.DC_WORKSPACE_NAME}/pipelines/${process.env.DC_PIPELINE_NAME}/search`, options);
if (dcResponse.status === 200) {
const result = await dcResponse.text();
response.status(200).send(result)
} else {
response.status(dcResponse.status).send(dcResponse.statusText)
}
} catch (error) {
console.error("Error:", error);
}
}