lakshmisravya123
Deploy Smart Document Search to HF Spaces
e1d7ef4
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();
}