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
|
||||
getApiKey('GOOGLE_AI_API_KEY').then(googleAiKey =>
|
||||
import('@/lib/claude/embed').then(({ embedText }) =>
|
||||
embedText(input.description.trim(), googleAiKey).then(embeddingVec => {
|
||||
const embStr = `[${(embeddingVec as number[]).join(',')}]`
|
||||
return asAdmin(db =>
|
||||
db.execute(sql`UPDATE incidents SET embedding = ${embStr}::vector(768) WHERE id = ${incidentId}::uuid`)
|
||||
)
|
||||
})
|
||||
// Embed description asynchronously (disabled if no GOOGLE_AI_API_KEY)
|
||||
getApiKey('GOOGLE_AI_API_KEY')
|
||||
.then(googleAiKey =>
|
||||
import('@/lib/claude/embed').then(({ embedText }) =>
|
||||
embedText(input.description.trim(), googleAiKey).then(embeddingVec => {
|
||||
const embStr = `[${(embeddingVec as number[]).join(',')}]`
|
||||
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 })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user