fix: improve dictation
This commit is contained in:
@@ -8,6 +8,7 @@ Recibís la transcripción de lo que alguien dictó y respondés SOLO con un arr
|
||||
|
||||
Reglas:
|
||||
- Un elemento por producto.
|
||||
- La transcripción casi nunca trae comas: los productos nombrados uno tras otro son elementos distintos ("azúcar leche y café" son 3), salvo que juntos formen un solo producto ("dulce de leche", "queso crema", "pan rallado").
|
||||
- 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".
|
||||
|
||||
@@ -120,6 +120,32 @@ describe('POST /api/voice/split', () => {
|
||||
expect(JSON.stringify(warnings)).toContain('invalid-json')
|
||||
})
|
||||
|
||||
it('asks for minimal thinking and retries a 5xx once', async () => {
|
||||
let calls = 0
|
||||
const fetchMock = mockFetch(async () =>
|
||||
++calls === 1
|
||||
? new Response('{}', { status: 500 })
|
||||
: modelAnswer('["Azúcar", "Leche", "Café"]'),
|
||||
)
|
||||
|
||||
const response = await split({ text: 'azúcar leche y café' })
|
||||
|
||||
expect(await response.json()).toEqual({ items: ['Azúcar', 'Leche', 'Café'] })
|
||||
expect(fetchMock).toHaveBeenCalledTimes(2)
|
||||
const sent = JSON.parse(String(fetchMock.mock.calls[0]?.[1]?.body))
|
||||
expect(sent.generationConfig.thinkingConfig).toEqual({ thinkingLevel: 'minimal' })
|
||||
})
|
||||
|
||||
it('falls back when the model answers 5xx twice', async () => {
|
||||
const fetchMock = mockFetch(async () => new Response('{}', { status: 503 }))
|
||||
|
||||
const response = await split({ text: 'pan y leche' })
|
||||
|
||||
expect(await response.json()).toEqual({ items: ['pan', 'leche'] })
|
||||
expect(fetchMock).toHaveBeenCalledTimes(2)
|
||||
expect(JSON.stringify(warnings)).toContain('http-503')
|
||||
})
|
||||
|
||||
it('falls back without calling the model when there is no API key', async () => {
|
||||
delete process.env.GEMINI_API_KEY
|
||||
const fetchMock = mockFetch(async () => modelAnswer('[]'))
|
||||
|
||||
Reference in New Issue
Block a user