fix: improve dictation

This commit is contained in:
Jose Selesan
2026-10-29 10:53:15 -03:00
parent 9159dd9c9b
commit cc0611b6a0
5 changed files with 71 additions and 21 deletions

View File

@@ -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('[]'))