fix: disable embeddings gracefully when GOOGLE_AI_API_KEY missing
- Catch and log GOOGLE_AI_API_KEY errors instead of failing - Allows endpoints to work without embeddings configured Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
+18
-10
@@ -212,17 +212,25 @@ async function handlePost(request: Request) {
|
|||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|
||||||
// Embed description asynchronously
|
// Embed description asynchronously (disabled if no GOOGLE_AI_API_KEY)
|
||||||
getApiKey('GOOGLE_AI_API_KEY').then(googleAiKey =>
|
getApiKey('GOOGLE_AI_API_KEY')
|
||||||
import('@/lib/claude/embed').then(({ embedText }) =>
|
.then(googleAiKey =>
|
||||||
embedText(input.description.trim(), googleAiKey).then(embeddingVec => {
|
import('@/lib/claude/embed').then(({ embedText }) =>
|
||||||
const embStr = `[${(embeddingVec as number[]).join(',')}]`
|
embedText(input.description.trim(), googleAiKey).then(embeddingVec => {
|
||||||
return asAdmin(db =>
|
const embStr = `[${(embeddingVec as number[]).join(',')}]`
|
||||||
db.execute(sql`UPDATE incidents SET embedding = ${embStr}::vector(768) WHERE id = ${incidentId}::uuid`)
|
return asAdmin(db =>
|
||||||
)
|
db.execute(sql`UPDATE incidents SET embedding = ${embStr}::vector(768) WHERE id = ${incidentId}::uuid`)
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
)
|
||||||
)
|
)
|
||||||
).catch(err => console.error('embed error:', err))
|
.catch(err => {
|
||||||
|
if (String(err).includes('GOOGLE_AI_API_KEY')) {
|
||||||
|
console.debug('Embeddings disabled: GOOGLE_AI_API_KEY not configured')
|
||||||
|
} else {
|
||||||
|
console.error('Embed error:', err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return NextResponse.json({ id: incidentId, reference_no: referenceNo }, { status: 201 })
|
return NextResponse.json({ id: incidentId, reference_no: referenceNo }, { status: 201 })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user