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.16
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.17
Choose a head ref
  • 10 commits
  • 60 files changed
  • 6 contributors

Commits on Jul 4, 2024

  1. chore (ci): update gh actions pnpm setup to v4 (#2179)

    jeremyphilemon authored Jul 4, 2024
    1
    Copy the full SHA
    580a5a3 View commit details

Commits on Jul 5, 2024

  1. Copy the full SHA
    3db90c3 View commit details

Commits on Jul 8, 2024

  1. fix (ci): do not bump example version in recent changeset (#2202)

    jeremyphilemon authored Jul 8, 2024
    Copy the full SHA
    05a6385 View commit details
  2. Copy the full SHA
    5c1f0bd View commit details
  3. Update nuxt and nuxt examples (#2186)

    Co-authored-by: Lars Grammel <lars.grammel@gmail.com>
    gmickel and lgrammel authored Jul 8, 2024
    Copy the full SHA
    7e83d75 View commit details
  4. fix (ai/provider-utils): generalize to Error (DomException not always…

    … available) (#2205)
    lgrammel authored Jul 8, 2024
    Copy the full SHA
    d481729 View commit details
  5. feat (ai): verify that system messages have string content (#2206)

    lgrammel authored Jul 8, 2024
    Copy the full SHA
    abb2260 View commit details
  6. feat (ai/ui): add onError handler to useObject (#2207)

    Co-authored-by: Paul Chavez <paulchavezromero20@gmail.com>
    lgrammel and developaul authored Jul 8, 2024
    Copy the full SHA
    6a11cfa View commit details
  7. Copy the full SHA
    915e93f View commit details
  8. Version Packages (#2203)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Jul 8, 2024
    Copy the full SHA
    b218ef2 View commit details
Showing with 2,865 additions and 3,241 deletions.
  1. +1 −1 .github/workflows/ci.yml
  2. +5 −5 .github/workflows/quality.yml
  3. +1 −1 .github/workflows/release-snapshot.yml
  4. +1 −1 .github/workflows/release.yml
  5. +7 −0 content/docs/07-reference/ai-sdk-ui/03-use-object.mdx
  6. +4 −0 examples/nuxt-openai/nuxt.config.ts
  7. +14 −13 examples/nuxt-openai/package.json
  8. +2 −2 examples/nuxt-openai/server/api/chat-with-functions.ts
  9. +10 −19 examples/nuxt-openai/server/api/chat-with-vision.ts
  10. +8 −14 examples/nuxt-openai/server/api/chat.ts
  11. +7 −8 examples/nuxt-openai/server/api/completion.ts
  12. +1 −1 examples/solidstart-openai/src/routes/index.tsx
  13. +7 −0 packages/amazon-bedrock/CHANGELOG.md
  14. +2 −2 packages/amazon-bedrock/package.json
  15. +7 −0 packages/anthropic/CHANGELOG.md
  16. +2 −2 packages/anthropic/package.json
  17. +8 −0 packages/azure/CHANGELOG.md
  18. +3 −3 packages/azure/package.json
  19. +7 −0 packages/cohere/CHANGELOG.md
  20. +2 −2 packages/cohere/package.json
  21. +17 −0 packages/core/CHANGELOG.md
  22. +7 −2 packages/core/core/generate-object/stream-object.ts
  23. +19 −0 packages/core/core/prompt/get-validated-prompt.test.ts
  24. +11 −0 packages/core/core/prompt/get-validated-prompt.ts
  25. +7 −7 packages/core/package.json
  26. +1 −1 packages/core/rsc/streamable.tsx
  27. +16 −10 packages/core/svelte/use-chat.ts
  28. +9 −0 packages/core/tests/e2e/next-server/CHANGELOG.md
  29. +7 −0 packages/google-vertex/CHANGELOG.md
  30. +2 −2 packages/google-vertex/package.json
  31. +7 −0 packages/google/CHANGELOG.md
  32. +2 −2 packages/google/package.json
  33. +7 −0 packages/mistral/CHANGELOG.md
  34. +2 −2 packages/mistral/package.json
  35. +7 −0 packages/openai/CHANGELOG.md
  36. +2 −2 packages/openai/package.json
  37. +6 −0 packages/provider-utils/CHANGELOG.md
  38. +1 −1 packages/provider-utils/package.json
  39. +2 −2 packages/provider-utils/src/is-abort-error.ts
  40. +10 −0 packages/react/CHANGELOG.md
  41. +3 −3 packages/react/package.json
  42. +15 −11 packages/react/src/use-chat.ts
  43. +78 −0 packages/react/src/use-chat.ui.test.tsx
  44. +10 −0 packages/react/src/use-object.ts
  45. +8 −0 packages/react/src/use-object.ui.test.tsx
  46. +7 −0 packages/solid/CHANGELOG.md
  47. +2 −2 packages/solid/package.json
  48. +16 −10 packages/solid/src/use-chat.ts
  49. +79 −0 packages/solid/src/use-chat.ui.test.tsx
  50. +9 −0 packages/svelte/CHANGELOG.md
  51. +3 −3 packages/svelte/package.json
  52. +16 −10 packages/svelte/src/use-chat.ts
  53. +7 −0 packages/ui-utils/CHANGELOG.md
  54. +2 −2 packages/ui-utils/package.json
  55. +7 −0 packages/vue/CHANGELOG.md
  56. +2 −2 packages/vue/package.json
  57. +28 −0 packages/vue/src/TestChatFormComponent.vue
  58. +10 −6 packages/vue/src/use-chat.ts
  59. +49 −0 packages/vue/src/use-chat.ui.test.tsx
  60. +2,273 −3,087 pnpm-lock.yaml
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v3

- name: Setup pnpm
uses: pnpm/action-setup@v2.2.2
uses: pnpm/action-setup@v4
with:
version: 8.6.9

10 changes: 5 additions & 5 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ jobs:
uses: actions/checkout@v3

- name: Setup pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
with:
version: 8.6.9

@@ -39,9 +39,9 @@ jobs:
uses: actions/checkout@v3

- name: Setup pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
with:
version: 8
version: 8.6.9

- name: Use Node.js 18
uses: actions/setup-node@v3
@@ -63,9 +63,9 @@ jobs:
uses: actions/checkout@v3

- name: Setup pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v4
with:
version: 7
version: 8.6.9

- name: Use Node.js 18
uses: actions/setup-node@v3
2 changes: 1 addition & 1 deletion .github/workflows/release-snapshot.yml
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ jobs:
fetch-depth: 0

- name: Setup pnpm 8
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 8.6.9

2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ jobs:
fetch-depth: 0

- name: Setup pnpm 8
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 8.6.9

7 changes: 7 additions & 0 deletions content/docs/07-reference/ai-sdk-ui/03-use-object.mdx
Original file line number Diff line number Diff line change
@@ -74,6 +74,13 @@ export default function Page() {
description:
'Optional. A custom fetch function to be used for the API call. Defaults to the global fetch function.',
},
{
name: 'onError',
type: '(error: Error) => void',
optional: true,
description:
'Optional. Callback function to be called when an error is encountered.',
},
]}
/>

4 changes: 4 additions & 0 deletions examples/nuxt-openai/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -2,10 +2,14 @@
export default defineNuxtConfig({
devtools: { enabled: true },
modules: ['@nuxtjs/tailwindcss'],

nitro: {
preset: 'vercel-edge', // you can use 'vercel' or other providers here
},

runtimeConfig: {
openaiApiKey: '',
},

compatibilityDate: '2024-07-05',
});
27 changes: 14 additions & 13 deletions examples/nuxt-openai/package.json
Original file line number Diff line number Diff line change
@@ -10,22 +10,23 @@
},
"devDependencies": {
"@ai-sdk/vue": "latest",
"@nuxt/devtools": "0.8.0",
"@nuxt/ui-templates": "^1.3.1",
"@nuxtjs/tailwindcss": "^6.8.0",
"@ai-sdk/openai": "latest",
"@nuxt/devtools": "1.3.9",
"@nuxt/ui-templates": "^1.3.4",
"@nuxtjs/tailwindcss": "^6.12.0",
"@types/node": "^18",
"@vue/reactivity": "^3.3.4",
"@vue/runtime-core": "^3.3.4",
"@vue/runtime-dom": "^3.3.4",
"@vue/shared": "^3.4.27",
"@vue/reactivity": "^3.4.31",
"@vue/runtime-core": "^3.4.31",
"@vue/runtime-dom": "^3.4.31",
"@vue/shared": "^3.4.31",
"ai": "latest",
"nuxt": "^3.6.5",
"openai": "4.47.1",
"tailwindcss": "^3.3.3",
"ufo": "^1.2.0",
"nuxt": "^3.12.3",
"openai": "4.52.3",
"tailwindcss": "^3.4.4",
"ufo": "^1.5.3",
"unctx": "^2.3.1",
"vue": "^3.3.4",
"vue-router": "4.2.5"
"vue": "^3.4.31",
"vue-router": "4.4.0"
},
"version": "0.0.0"
}
4 changes: 2 additions & 2 deletions examples/nuxt-openai/server/api/chat-with-functions.ts
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ export default defineLazyEventHandler(async () => {
const { messages } = await readBody(event);

const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo-0613',
model: 'gpt-3.5-turbo',
stream: true,
messages,
functions,
@@ -74,7 +74,7 @@ export default defineLazyEventHandler(async () => {
return openai.chat.completions.create({
messages: [...messages, ...newMessages],
stream: true,
model: 'gpt-3.5-turbo-0613',
model: 'gpt-3.5-turbo',
});
}
},
29 changes: 10 additions & 19 deletions examples/nuxt-openai/server/api/chat-with-vision.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { OpenAIStream, StreamingTextResponse } from 'ai';
import OpenAI from 'openai';
import { convertToCoreMessages, streamText } from 'ai';
import { createOpenAI } from '@ai-sdk/openai';

export default defineLazyEventHandler(async () => {
const apiKey = useRuntimeConfig().openaiApiKey;
if (!apiKey) throw new Error('Missing OpenAI API key');
const openai = new OpenAI({
const openai = createOpenAI({
apiKey: apiKey,
});

@@ -16,31 +16,22 @@ export default defineLazyEventHandler(async () => {
const currentMessage = messages[messages.length - 1];

// Ask OpenAI for a streaming chat completion given the prompt
const response = await openai.chat.completions.create({
model: 'gpt-4-vision-preview',
stream: true,
max_tokens: 150,
const response = await streamText({
model: openai('gpt-4o'),
maxTokens: 150,
messages: [
...initialMessages,
...convertToCoreMessages(initialMessages),
{
...currentMessage,
role: 'user',
content: [
{ type: 'text', text: currentMessage.content },

// forward the image information to OpenAI:
{
type: 'image_url',
image_url: data.imageUrl,
},
{ type: 'image', image: new URL(data.imageUrl) },
],
},
],
});

// Convert the response into a friendly text-stream
const stream = OpenAIStream(response);

// Respond with the stream
return new StreamingTextResponse(stream);
return response.toAIStreamResponse();
});
});
22 changes: 8 additions & 14 deletions examples/nuxt-openai/server/api/chat.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import { OpenAIStream, StreamingTextResponse } from 'ai';
import OpenAI from 'openai';
import { ChatCompletionMessageParam } from 'openai/resources/chat';
import { streamText } from 'ai';
import { createOpenAI } from '@ai-sdk/openai';

export default defineLazyEventHandler(async () => {
const apiKey = useRuntimeConfig().openaiApiKey;
if (!apiKey) throw new Error('Missing OpenAI API key');
const openai = new OpenAI({

const openai = createOpenAI({
apiKey: apiKey,
});

return defineEventHandler(async (event: any) => {
// Extract the `prompt` from the body of the request
const { messages } = (await readBody(event)) as {
messages: ChatCompletionMessageParam[];
};
const { messages } = await readBody(event);

// Ask OpenAI for a streaming chat completion given the prompt
const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
stream: true,
const result = await streamText({
model: openai('gpt-3.5-turbo'),
messages,
});

// Convert the response into a friendly text-stream
const stream = OpenAIStream(response);

// Respond with the stream
return new StreamingTextResponse(stream);
return result.toAIStreamResponse();
});
});
15 changes: 7 additions & 8 deletions examples/nuxt-openai/server/api/completion.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { OpenAIStream, StreamingTextResponse, StreamData } from 'ai';
import OpenAI from 'openai';
import { streamText, StreamingTextResponse, StreamData } from 'ai';
import { createOpenAI } from '@ai-sdk/openai';

export default defineLazyEventHandler(async () => {
const apiKey = useRuntimeConfig().openaiApiKey;
if (!apiKey) throw new Error('Missing OpenAI API key');
const openai = new OpenAI({
const openai = createOpenAI({
apiKey: apiKey,
});

@@ -13,9 +13,8 @@ export default defineLazyEventHandler(async () => {
const { prompt } = await readBody(event);

// Ask OpenAI for a streaming chat completion given the prompt
const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
stream: true,
const result = await streamText({
model: openai('gpt-3.5-turbo'),
messages: [{ role: 'user', content: prompt }],
});

@@ -25,8 +24,8 @@ export default defineLazyEventHandler(async () => {
data.append({ test: 'value' });

// Convert the response into a friendly text-stream
const stream = OpenAIStream(response, {
onFinal(completion) {
const stream = result.toAIStream({
onFinal(_) {
data.close();
},
});
2 changes: 1 addition & 1 deletion examples/solidstart-openai/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ export default function Chat() {
class="fixed bottom-0 w-full max-w-md p-2 mb-8 border border-gray-300 rounded shadow-xl"
value={input()}
placeholder="Say something..."
onChange={handleInputChange}
onInput={handleInputChange}
/>
</form>
</div>
7 changes: 7 additions & 0 deletions packages/amazon-bedrock/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @ai-sdk/amazon-bedrock

## 0.0.4

### Patch Changes

- Updated dependencies [d481729f]
- @ai-sdk/provider-utils@1.0.1

## 0.0.3

### Patch Changes
4 changes: 2 additions & 2 deletions packages/amazon-bedrock/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ai-sdk/amazon-bedrock",
"version": "0.0.3",
"version": "0.0.4",
"license": "Apache-2.0",
"sideEffects": false,
"main": "./dist/index.js",
@@ -30,7 +30,7 @@
},
"dependencies": {
"@ai-sdk/provider": "0.0.11",
"@ai-sdk/provider-utils": "1.0.0",
"@ai-sdk/provider-utils": "1.0.1",
"@aws-sdk/client-bedrock-runtime": "3.602.0"
},
"devDependencies": {
7 changes: 7 additions & 0 deletions packages/anthropic/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @ai-sdk/anthropic

## 0.0.28

### Patch Changes

- Updated dependencies [d481729f]
- @ai-sdk/provider-utils@1.0.1

## 0.0.27

### Patch Changes
4 changes: 2 additions & 2 deletions packages/anthropic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ai-sdk/anthropic",
"version": "0.0.27",
"version": "0.0.28",
"license": "Apache-2.0",
"sideEffects": false,
"main": "./dist/index.js",
@@ -30,7 +30,7 @@
},
"dependencies": {
"@ai-sdk/provider": "0.0.11",
"@ai-sdk/provider-utils": "1.0.0"
"@ai-sdk/provider-utils": "1.0.1"
},
"devDependencies": {
"@types/node": "^18",
8 changes: 8 additions & 0 deletions packages/azure/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @ai-sdk/azure

## 0.0.11

### Patch Changes

- Updated dependencies [d481729f]
- @ai-sdk/provider-utils@1.0.1
- @ai-sdk/openai@0.0.35

## 0.0.10

### Patch Changes
6 changes: 3 additions & 3 deletions packages/azure/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ai-sdk/azure",
"version": "0.0.10",
"version": "0.0.11",
"license": "Apache-2.0",
"sideEffects": false,
"main": "./dist/index.js",
@@ -29,9 +29,9 @@
}
},
"dependencies": {
"@ai-sdk/openai": "0.0.34",
"@ai-sdk/openai": "0.0.35",
"@ai-sdk/provider": "0.0.11",
"@ai-sdk/provider-utils": "1.0.0"
"@ai-sdk/provider-utils": "1.0.1"
},
"devDependencies": {
"@types/node": "^18",
7 changes: 7 additions & 0 deletions packages/cohere/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @ai-sdk/cohere

## 0.0.4

### Patch Changes

- Updated dependencies [d481729f]
- @ai-sdk/provider-utils@1.0.1

## 0.0.3

### Patch Changes
Loading