Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vercel/ai
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ai@3.2.25
Choose a base ref
...
head repository: vercel/ai
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ai@3.2.26
Choose a head ref
  • 5 commits
  • 6 files changed
  • 4 contributors

Commits on Jul 16, 2024

  1. chore (docs): improve ai/ui error handling page (#2294)

    lgrammel authored Jul 16, 2024
    Copy the full SHA
    6884145 View commit details
  2. Add empty parameters to field in useChat reference (#2296)

    jeremyphilemon authored Jul 16, 2024
    Copy the full SHA
    5fadb8b View commit details
  3. fix (docs): move description of FileList to parameters (#2297)

    jeremyphilemon authored Jul 16, 2024
    Copy the full SHA
    b2d97d1 View commit details
  4. fix (ai/core): forward request headers in generateObject and streamOb…

    …ject (#2299)
    lgrammel authored Jul 16, 2024
    Copy the full SHA
    8f545ce View commit details
  5. Version Packages (#2300)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Jul 16, 2024
    Copy the full SHA
    17dc142 View commit details
25 changes: 14 additions & 11 deletions content/docs/05-ai-sdk-ui/21-error-handling.mdx
Original file line number Diff line number Diff line change
@@ -23,16 +23,14 @@ You can use the error object to show an error message, disable the submit button
server.
</Note>

```tsx file="app/page.tsx" highlight="8,19-26,32"
```tsx file="app/page.tsx" highlight="7,17-24,30"
'use client';

import { useChat } from 'ai/react';

export default function Chat() {
const { messages, input, handleInputChange, handleSubmit, error, reload } =
useChat({
keepLastMessageOnError: true,
});
useChat({ keepLastMessageOnError: true });

return (
<div>
@@ -67,16 +65,20 @@ export default function Chat() {

Alternatively you can write a custom submit handler that replaces the last message when an error is present.

```tsx file="app/page.tsx" highlight="8,11-16,29"
```tsx file="app/page.tsx" highlight="15-21,33"
'use client';

import { useChat } from 'ai/react';

export default function Chat() {
const { messages, input, handleInputChange, handleSubmit, error, messages } =
useChat({
keepLastMessageOnError: true,
});
const {
handleInputChange,
handleSubmit,
error,
input,
messages,
setMesages,
} = useChat({ keepLastMessageOnError: true });

function customSubmit(event: React.FormEvent<HTMLFormElement>) {
if (error != null) {
@@ -109,15 +111,16 @@ export default function Chat() {
Errors can be processed by passing an [`onError`](/docs/reference/ai-sdk-ui/use-chat#on-error) callback function as an option to the [`useChat`](/docs/reference/ai-sdk-ui/use-chat), [`useCompletion`](/docs/reference/ai-sdk-ui/use-completion) or [`useAssistant`](/docs/reference/ai-sdk-ui/use-assistant) hooks.
The callback function receives an error object as an argument.

```tsx file="app/page.tsx" highlight="7-10"
```tsx file="app/page.tsx" highlight="8-11"
import { useChat } from 'ai/react';

export default function Page() {
const {
/* ... */
} = useChat({
keepLastMessageOnError: true,
// handle error:
onError: error => {
// handle error
console.error(error);
},
});
10 changes: 8 additions & 2 deletions content/docs/07-reference/ai-sdk-ui/01-use-chat.mdx
Original file line number Diff line number Diff line change
@@ -345,8 +345,14 @@ Allows you to easily create a conversational user interface for your chatbot app
properties: [
{
type: 'FileList',
description:
"A list of files that have been selected by the user using an <input type='file'> element. It's also used for a list of files dropped into web content when using the drag and drop API.",
parameters: [
{
name: '',
type: '',
description:
"A list of files that have been selected by the user using an <input type='file'> element. It's also used for a list of files dropped into web content when using the drag and drop API.",
},
],
},
{
type: 'Attachment',
6 changes: 6 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ai

## 3.2.26

### Patch Changes

- 8f545ce9: fix (ai/core): forward request headers in generateObject and streamObject

## 3.2.25

### Patch Changes
2 changes: 2 additions & 0 deletions packages/core/core/generate-object/generate-object.ts
Original file line number Diff line number Diff line change
@@ -154,6 +154,7 @@ Default and recommended: 'auto' (best mode for the model).
inputFormat: validatedPrompt.type,
prompt: convertToLanguageModelPrompt(validatedPrompt),
abortSignal,
headers,
}),
);

@@ -193,6 +194,7 @@ Default and recommended: 'auto' (best mode for the model).
inputFormat: validatedPrompt.type,
prompt: convertToLanguageModelPrompt(validatedPrompt),
abortSignal,
headers,
}),
);

2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ai",
"version": "3.2.25",
"version": "3.2.26",
"license": "Apache-2.0",
"sideEffects": false,
"main": "./dist/index.js",
7 changes: 7 additions & 0 deletions packages/core/tests/e2e/next-server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,13 @@

### Patch Changes

- Updated dependencies [8f545ce9]
- ai@3.2.26

## null

### Patch Changes

- Updated dependencies [99ddbb74]
- ai@3.2.25