Skip to content

Commit

Permalink
fix (docs): update responseMessages to response.messages (#4299)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrammel authored Jan 7, 2025
1 parent 8b422ea commit 045f726
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
4 changes: 2 additions & 2 deletions content/cookbook/01-next/100-save-messages-to-database.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export function POST(request) {
model: openai('gpt-4o'),
system: 'you are a friendly assistant!',
messages: coreMessages,
onFinish: async ({ responseMessages }) => {
onFinish: async ({ response }) => {
try {
await saveChat({
id,
messages: [...coreMessages, ...responseMessages],
messages: [...coreMessages, ...response.messages],
});
} catch (error) {
console.error('Failed to save chat');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ import { openai } from '@ai-sdk/openai';
export async function POST(req: Request) {
const { messages }: { messages: CoreMessage[] } = await req.json();

const { responseMessages } = await generateText({
const { response } = await generateText({
model: openai('gpt-4'),
system: 'You are a helpful assistant.',
messages,
});

return Response.json({ messages: responseMessages });
return Response.json({ messages: response.messages });
}
```

Expand Down
8 changes: 4 additions & 4 deletions content/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ const result = await generateText({
Adding the generated assistant and tool messages to your conversation history is a common task,
especially if you are using multi-step tool calls.

Both `generateText` and `streamText` have a `responseMessages` property that you can use to
Both `generateText` and `streamText` have a `response.messages` property that you can use to
add the assistant and tool messages to your conversation history.
It is also available in the `onFinish` callback of `streamText`.

The `responseMessages` property contains an array of `CoreMessage` objects that you can add to your conversation history:
The `response.messages` property contains an array of `CoreMessage` objects that you can add to your conversation history:

```ts
import { generateText } from 'ai';
Expand All @@ -160,13 +160,13 @@ const messages: CoreMessage[] = [
// ...
];

const { responseMessages } = await generateText({
const { response } = await generateText({
// ...
messages,
});

// add the response messages to your conversation history:
messages.push(...responseMessages); // streamText: ...(await responseMessages)
messages.push(...response.messages); // streamText: ...((await response).messages)
```

## Tool Choice
Expand Down
4 changes: 2 additions & 2 deletions content/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,11 @@ export async function POST(request) {
model: openai('gpt-4o'),
system: 'you are a friendly assistant!',
messages: coreMessages,
onFinish: async ({ responseMessages }) => {
onFinish: async ({ response }) => {
try {
await saveChat({
id,
messages: [...coreMessages, ...responseMessages],
messages: [...coreMessages, ...response.messages],
});
} catch (error) {
console.error('Failed to save chat');
Expand Down
9 changes: 2 additions & 7 deletions content/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1014,12 +1014,6 @@ To see `streamText` in action, check out [these examples](#examples).
description:
'Optional metadata from the provider. Resolved whe the response is finished. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
},
{
name: 'responseMessages',
type: 'Promise<Array<CoreAssistantMessage | CoreToolMessage>>',
description:
'The response messages that were generated during the call. It consists of an assistant message, potentially containing tool calls. When there are tool results, there is an additional tool message with the tool results that are available. If there are tools that do not have execute functions, they are not included in the tool results and need to be added separately. Resolved when the response is finished.',
},
{
name: 'text',
type: 'Promise<string>',
Expand Down Expand Up @@ -1815,7 +1809,8 @@ To see `streamText` in action, check out [these examples](#examples).
},
],
},
]}

]}
/>

## Examples
Expand Down

0 comments on commit 045f726

Please sign in to comment.