Skip to content

Commit 076bcc0

Browse files
samdentyiteratetogracenesslgrammel
authored
fix (examples): avoid mixed message types in use-chat-streamdata-multistep (#5824) (#5886)
Co-authored-by: Grace Yun <[email protected]> Co-authored-by: Lars Grammel <[email protected]>
1 parent 95857aa commit 076bcc0

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

content/cookbook/01-next/24-stream-text-multistep.mdx

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ export async function POST(req: Request) {
5454
system:
5555
'You are a helpful assistant with a different system prompt. Repeat the extract user goal in your answer.',
5656
// continue the workflow stream with the messages from the previous step:
57-
messages: [...messages, ...(await result1.response).messages],
57+
messages: [
58+
...convertToCoreMessages(messages),
59+
...(await result1.response).messages,
60+
],
5861
});
5962

6063
// forward the 2nd result to the client (incl. the finish event):

examples/next-openai/app/api/use-chat-streamdata-multistep/route.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { openai } from '@ai-sdk/openai';
2-
import { createDataStreamResponse, streamText, tool } from 'ai';
2+
import {
3+
convertToCoreMessages,
4+
createDataStreamResponse,
5+
streamText,
6+
tool,
7+
} from 'ai';
38
import { z } from 'zod';
49

510
export async function POST(req: Request) {
@@ -36,7 +41,10 @@ export async function POST(req: Request) {
3641
system:
3742
'You are a helpful assistant with a different system prompt. Repeat the extract user goal in your answer.',
3843
// continue the workflow stream with the messages from the previous step:
39-
messages: [...messages, ...(await result1.response).messages],
44+
messages: [
45+
...convertToCoreMessages(messages),
46+
...(await result1.response).messages,
47+
],
4048
});
4149

4250
// forward the 2nd result to the client (incl. the finish event):

0 commit comments

Comments
 (0)