File size: 1,326 Bytes
d4ec2fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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'),
}