-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (docs): add streamText troubleshooting page (#4730)
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
content/docs/09-troubleshooting/15-stream-text-not-working.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: streamText fails silently | ||
description: Troubleshooting errors related to the streamText function not working. | ||
--- | ||
|
||
# `streamText` is not working | ||
|
||
## Issue | ||
|
||
I am using [`streamText`](/docs/reference/ai-sdk-core/stream-text) function, and it does not work. | ||
It does not throw any errors and the stream is only containing error parts. | ||
|
||
## Background | ||
|
||
`streamText` immediately starts streaming to enable sending data without waiting for the model. | ||
Errors become part of the stream and are not thrown to prevent e.g. servers from crashing. | ||
|
||
## Solution | ||
|
||
To log errors, you can provide an `onError` callback that is triggered when an error occurs. | ||
|
||
```tsx highlight="6-8" | ||
import { streamText } from 'ai'; | ||
|
||
const result = streamText({ | ||
model: yourModel, | ||
prompt: 'Invent a new holiday and describe its traditions.', | ||
onError({ error }) { | ||
console.error(error); // your error logging logic here | ||
}, | ||
}); | ||
``` |