Skip to content

Commit

Permalink
fix (docs): update text & code in streaming text gen example (#2080)
Browse files Browse the repository at this point in the history
Co-authored-by: Derrick Maina <[email protected]>
  • Loading branch information
lgrammel and MrMaina100 committed Jun 25, 2024
1 parent a92523c commit ff204fe
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Text generation can sometimes take a long time to complete, especially when you'

## Client

Let's create a simple React component that will call the `getAnswer` function when a button is clicked. The `getAnswer` function will call the `streamText` function, which will then generate text based on the input prompt. To consume the stream of text in the client, we will use the `readStreamableValue` function from the `ai/rsc` module.
Let's create a simple React component that will call the `generate` function when a button is clicked. The `generate` function will call the `streamText` function, which will then generate text based on the input prompt. To consume the stream of text in the client, we will use the `readStreamableValue` function from the `ai/rsc` module.

```tsx filename="app/page.tsx"
'use client';
Expand Down Expand Up @@ -57,7 +57,7 @@ export default function Home() {

## Server

On the server side, we need to implement the `getAnswer` function, which will call the `streamText` function. The `streamText` function will generate text based on the input prompt. In order to stream the text generation to the client, we will use `createStreambleValue` that can wrap any changable value and stream it to the client.
On the server side, we need to implement the `generate` function, which will call the `streamText` function. The `streamText` function will generate text based on the input prompt. In order to stream the text generation to the client, we will use `createStreambleValue` that can wrap any changable value and stream it to the client.

Using DevTools, we can see the text generation being streamed to the client in real-time.

Expand All @@ -69,8 +69,6 @@ import { openai } from '@ai-sdk/openai';
import { createStreamableValue } from 'ai/rsc';

export async function generate(input: string) {
'use server';

const stream = createStreamableValue('');

(async () => {
Expand Down

0 comments on commit ff204fe

Please sign in to comment.