File size: 951 Bytes
e1d7ef4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const API = '/api';

export async function uploadDocument(file) {
  const form = new FormData();
  form.append('document', file);
  const res = await fetch(`${API}/documents/upload`, { method: 'POST', body: form });
  if (!res.ok) throw new Error((await res.json()).error);
  return res.json();
}

export async function getDocuments() {
  const res = await fetch(`${API}/documents`);
  if (!res.ok) throw new Error((await res.json()).error);
  return res.json();
}

export async function deleteDocument(id) {
  const res = await fetch(`${API}/documents/${id}`, { method: 'DELETE' });
  return res.json();
}

export async function askQuestion(question, documentIds, sessionId) {
  const res = await fetch(`${API}/search/ask`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ question, documentIds, sessionId }),
  });
  if (!res.ok) throw new Error((await res.json()).error);
  return res.json();
}