| const BASE_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:8000' | |
| export type Encoder = 'xlm-roberta-large' | |
| export type Decoder = 'gemma3' | 'qwen3' | |
| export interface AnnotationEntry { | |
| span: string | |
| emojis: string | |
| } | |
| export interface AnnotationData { | |
| marked: string | |
| annotations: AnnotationEntry[] | |
| } | |
| export interface AnnotateResponse { | |
| valid: boolean | |
| annotation?: AnnotationData | |
| reason?: string | |
| } | |
| export async function postAnnotate( | |
| encoder: Encoder, | |
| decoder: Decoder, | |
| text: string, | |
| signal?: AbortSignal | |
| ): Promise<AnnotateResponse> { | |
| const res = await fetch(`${BASE_URL}/api/annotate`, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ encoder, decoder, text }), | |
| signal, | |
| }) | |
| if (!res.ok) throw new Error(`HTTP ${res.status}`) | |
| return res.json() | |
| } | |