Spaces:
Runtime error
Runtime error
Download frontend/src/lib/api.js from Satyam311/maintenance-classifier-api: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/Satyam311/maintenance-classifier-api/resolve/main/frontend/src/lib/api.js
- Command line
-
hf download hf://spaces/Satyam311/maintenance-classifier-api/frontend/src/lib/api.js
-
curl -L -o api.js https://huggingface.co/spaces/Satyam311/maintenance-classifier-api/resolve/main/frontend/src/lib/api.js
1.33 kB
| export const API_BASE = import.meta.env.VITE_API_BASE_URL || '/api' | |
| const BASE = API_BASE | |
| async function request(path, options = {}) { | |
| const res = await fetch(`${BASE}${path}`, { | |
| headers: { 'Content-Type': 'application/json' }, | |
| ...options, | |
| }) | |
| if (!res.ok) { | |
| const body = await res.json().catch(() => ({})) | |
| const err = new Error(body.detail || `Request failed: ${res.status}`) | |
| err.status = res.status | |
| throw err | |
| } | |
| return res.json() | |
| } | |
| export const api = { | |
| classify: (narrative_text) => | |
| request('/classify', { method: 'POST', body: JSON.stringify({ narrative_text }) }), | |
| search: ({ q = '', system, severity, limit = 20 }) => { | |
| const params = new URLSearchParams({ q, limit: String(limit) }) | |
| if (system) params.set('system', system) | |
| if (severity) params.set('severity', severity) | |
| return request(`/search?${params.toString()}`) | |
| }, | |
| submitCorrection: (report_id, field_corrected, corrected_value) => | |
| request('/corrections', { | |
| method: 'POST', | |
| body: JSON.stringify({ report_id, field_corrected, corrected_value }), | |
| }), | |
| ask: (question) => | |
| request('/ask', { method: 'POST', body: JSON.stringify({ question }) }), | |
| stats: () => request('/stats'), | |
| modelPerformance: () => request('/model-performance'), | |
| health: () => request('/health'), | |
| } | |