fix: resolver FUNCTION_INVOCATION_FAILED y pipeline de Instagram
- transcriptor: restaurar await toFile() — sin él Whisper recibía una Promise en vez del archivo y devolvía 400 - transcriptor: detectar MIME type real (m4a para Instagram, mp3 TikTok) - analizar: normalizar duración (TikTok→ms, Instagram→s float) a entero antes de guardar en Supabase y pasar a GPT-4o - analizar/server: reemplazar .catch() en insert de error por try/catch — el builder de Supabase no expone .catch() directamente; el TypeError escapaba al outer catch y causaba FUNCTION_INVOCATION_FAILED en Vercel - validador: fallback de último recurso en enums cuando GPT-4o devuelve valor inválido (ej. "ninguno" para desarrollo_tipo) Probado end-to-end: Instagram Reel → OK en 27s Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -42,7 +42,8 @@ export async function transcribir(audioUrl, idioma = 'es') {
|
||||
const ext = audioUrl.split('?')[0].split('.').pop()?.toLowerCase() || 'mp3'
|
||||
const mimeMap = { mp3: 'audio/mpeg', m4a: 'audio/mp4', mp4: 'audio/mp4', webm: 'audio/webm', ogg: 'audio/ogg', wav: 'audio/wav' }
|
||||
const mimeType = mimeMap[ext] || 'audio/mpeg'
|
||||
const audioFile = toFile(audioResponse, `audio.${ext}`, { type: mimeType })
|
||||
// toFile es async en el SDK de OpenAI — await es necesario aunque el IDE lo marque como hint
|
||||
const audioFile = await toFile(audioResponse, `audio.${ext}`, { type: mimeType })
|
||||
|
||||
const transcripcion = await openai.audio.transcriptions.create({
|
||||
file: audioFile,
|
||||
|
||||
@ -40,7 +40,12 @@ function normalizarEnum(valor, validos, aliases = {}) {
|
||||
const matchU = validos.find(v => v.toLowerCase() === underscored)
|
||||
if (matchU) return matchU
|
||||
|
||||
return sinAcentos // sin match → Zod reportará el error
|
||||
// 6. Fallback de último recurso: "otra" > "ninguna" > "ninguno" > último valor del enum
|
||||
// GPT-4o a veces devuelve "ninguno" para campos donde no corresponde
|
||||
if (validos.includes('otra')) return 'otra'
|
||||
if (validos.includes('ninguna')) return 'ninguna'
|
||||
if (validos.includes('ninguno')) return 'ninguno'
|
||||
return validos[validos.length - 1]
|
||||
}
|
||||
|
||||
/** Enum flexible: tolera acentos, mayúsculas, espacios y aliases explícitos */
|
||||
|
||||
Reference in New Issue
Block a user