import { FormEvent, useState } from 'react'; import { sendStructuredChat } from '../api'; import type { ChatMessage, StructuredOutputSchema } from '../types'; interface ExtractionResult { summary: string; sentiment: 'positive' | 'neutral' | 'negative'; keywords: string[]; } const EXTRACTION_SCHEMA: StructuredOutputSchema = { name: 'text_extraction', strict: true, schema: { type: 'object', additionalProperties: false, properties: { summary: { type: 'string', description: 'One short sentence summarizing the input.' }, sentiment: { type: 'string', enum: ['positive', 'neutral', 'negative'] }, keywords: { type: 'array', items: { type: 'string' }, description: 'Three to five important keywords from the input.', }, }, required: ['summary', 'sentiment', 'keywords'], }, }; const SYSTEM_PROMPT: ChatMessage = { role: 'system', content: 'Extract structured facts from the user text. Return only data matching the JSON schema.', }; export function ExtractTab() { const [text, setText] = useState('Kazzle makes it much faster to turn rough ideas into working apps.'); const [extracting, setExtracting] = useState(false); const [result, setResult] = useState(null); const [error, setError] = useState(null); async function onSubmit(event: FormEvent) { event.preventDefault(); const content = text.trim(); if (!content || extracting) return; setExtracting(true); setError(null); try { const extracted = await sendStructuredChat( [SYSTEM_PROMPT, { role: 'user', content }], EXTRACTION_SCHEMA, { max_completion_tokens: 512 }, ); setResult(extracted); } catch (err) { setError(err instanceof Error ? err.message : String(err)); } finally { setExtracting(false); } } return (

Use structured output when the app needs data, not prose. The server forwards OpenAI-style response_format.json_schema and returns parsed JSON.