feat(items): voice dictation with Gemma 4 and a reworked list UI
Dictation: a mic button in the add field uses the Web Speech API (es-AR) and
shows the partial transcript in the input. POST /api/voice/split asks Gemma 4
(Gemini API, plain fetch) to split the sentence into one string per item,
written the way the existing parser reads typed text; each string then goes
through the usual add flow. The endpoint never fails because of the model:
missing key, timeout, 429 or invalid JSON fall back to splitting on commas,
semicolons, " y " and " e ". A toast offers "Deshacer" for the whole dictation;
if the request fails, the transcript is added as a single item.
UI: "+" instead of the search icon, quantity tags ("2 L", "×12", "1 kg"), the
list name with a list switcher and the pending/bought count in the header,
"Comprados (N)" folded by default, and a bottom sheet to edit name, quantity
(− / + and unit), note and delete. PATCH items now accepts a name.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
30
apps/api/src/modules/voice/split/prompt.ts
Normal file
30
apps/api/src/modules/voice/split/prompt.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { VOICE_SPLIT_EXAMPLES } from '@superlist/shared'
|
||||
|
||||
import type { GeminiTurn, GenerateInput } from '@/lib/gemini'
|
||||
|
||||
/** What the model is told to do. Gemma accepts it as `systemInstruction`. */
|
||||
export const SPLIT_INSTRUCTION = `Sos un asistente que arma listas de compras en español rioplatense.
|
||||
Recibís la transcripción de lo que alguien dictó y respondés SOLO con un array JSON de strings, sin texto antes ni después.
|
||||
|
||||
Reglas:
|
||||
- Un elemento por producto.
|
||||
- Números en dígitos: "dos" → 2, "media docena" → 6, "una docena" → 12, "un kilo" → 1 kg, "un kilo y medio" → 1,5 kg.
|
||||
- Unidades abreviadas: g, kg, ml, l. Los envases quedan como palabra: "1 lata", "2 paquetes".
|
||||
- La cantidad va al principio: "2 l de leche", "400 g de queso", "12 huevos".
|
||||
- Detalles como marca, color, tipo o corte van como nota, después de un punto: "Bolsas de residuos. Negras y verdes".
|
||||
- No inventes productos ni cantidades: si no se dijo una cantidad, no pongas ninguna.
|
||||
- Corregí errores obvios de la transcripción (palabras mal reconocidas, mayúsculas).
|
||||
- Si no hay ningún producto, respondé [].`
|
||||
|
||||
/** The conversation sent to the model: the few-shot examples, then the transcript. */
|
||||
export function buildSplitPrompt(text: string): GenerateInput {
|
||||
const examples: GeminiTurn[] = VOICE_SPLIT_EXAMPLES.flatMap(({ said, items }) => [
|
||||
{ role: 'user' as const, text: said },
|
||||
{ role: 'model' as const, text: JSON.stringify(items) },
|
||||
])
|
||||
|
||||
return {
|
||||
systemInstruction: SPLIT_INSTRUCTION,
|
||||
turns: [...examples, { role: 'user', text }],
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user