Skip to content

Commit eab10c4

Browse files
committed
Log errors from vercel ai sdk stream
1 parent a1b5ba6 commit eab10c4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

backend/src/llm-apis/vercel-ai-sdk/ai-sdk.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { z } from 'zod'
2929
import { System } from '../claude'
3030
import { saveMessage } from '../message-cost-tracker'
3131
import { vertexFinetuned } from './vertex-finetuned'
32+
import { logger } from 'common/util/logger'
3233

3334
// TODO: We'll want to add all our models here!
3435
const modelToAiSDKModel = (model: Model): LanguageModelV1 => {
@@ -90,6 +91,12 @@ export const promptAiSdkStream = async function* (
9091
let finishedReasoning = false
9192

9293
for await (const chunk of response.fullStream) {
94+
if (chunk.type === 'error') {
95+
logger.error({ chunk }, 'Error from AI SDK')
96+
if (process.env.ENVIRONMENT !== 'prod') {
97+
throw new Error(chunk.error as string)
98+
}
99+
}
93100
if (chunk.type === 'reasoning') {
94101
if (!hasReasoning) {
95102
hasReasoning = true

0 commit comments

Comments
 (0)