Spaces:
Sleeping
Sleeping
File size: 1,405 Bytes
4d592a4 |
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import axios from 'axios';
import type {
QueryResponse,
UploadResponse,
DocumentsListResponse,
QueryMode
} from '../types';
const API_BASE_URL = import.meta.env.VITE_API_URL || '/api/v1';
const api = axios.create({
baseURL: API_BASE_URL,
headers: {
'Content-Type': 'application/json',
},
maxRedirects: 5,
});
export const uploadDocument = async (file: File): Promise<UploadResponse> => {
const formData = new FormData();
formData.append('file', file);
const response = await api.post<UploadResponse>('/upload/', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
return response.data;
};
export const querySystem = async (
query: string,
mode: QueryMode,
documentIds?: string[]
): Promise<QueryResponse> => {
const response = await api.post<QueryResponse>('/query/', {
query,
mode,
document_ids: documentIds,
});
return response.data;
};
export const getDocuments = async (): Promise<DocumentsListResponse> => {
const response = await api.get<DocumentsListResponse>('/documents/');
return response.data;
};
export const deleteDocument = async (documentId: string): Promise<void> => {
await api.delete(`/documents/${documentId}/`);
};
export const healthCheck = async (): Promise<{ status: string }> => {
const response = await api.get('/health/');
return response.data;
};
export default api;
|