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.11
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.12
Choose a head ref
  • 4 commits
  • 91 files changed
  • 4 contributors

Commits on Jun 27, 2024

  1. chore (examples): add useObject to next-openai-pages (#2117)

    jeremyphilemon authored Jun 27, 2024
    Copy the full SHA
    caa198b View commit details
  2. feat (ai/core): custom request headers (#2116)

    lgrammel authored Jun 27, 2024
    Copy the full SHA
    5edc611 View commit details
  3. feat (docs): add example for headers

    lgrammel committed Jun 27, 2024
    Copy the full SHA
    6851542 View commit details
  4. Version Packages (#2118)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Jun 27, 2024
    Copy the full SHA
    c9a542b View commit details
Showing with 1,152 additions and 566 deletions.
  1. +26 −0 content/docs/03-ai-sdk-core/25-settings.mdx
  2. +7 −0 content/docs/07-reference/ai-sdk-core/01-generate-text.mdx
  3. +7 −0 content/docs/07-reference/ai-sdk-core/02-stream-text.mdx
  4. +71 −65 content/docs/07-reference/ai-sdk-core/03-generate-object.mdx
  5. +74 −67 content/docs/07-reference/ai-sdk-core/04-stream-object.mdx
  6. +7 −0 content/docs/07-reference/ai-sdk-core/05-embed.mdx
  7. +7 −0 content/docs/07-reference/ai-sdk-core/06-embed-many.mdx
  8. +7 −0 content/docs/07-reference/ai-sdk-rsc/01-stream-ui.mdx
  9. +4 −0 content/providers/01-ai-sdk-providers/02-azure.mdx
  10. +10 −1 examples/ai-core/src/generate-text/openai-custom-headers.ts
  11. +25 −0 examples/next-openai-pages/app/api/stream-object/route.ts
  12. +29 −0 examples/next-openai-pages/pages/basics/stream-object/index.tsx
  13. +11 −11 examples/next-openai-pages/pages/index.tsx
  14. +11 −0 packages/amazon-bedrock/CHANGELOG.md
  15. +3 −3 packages/amazon-bedrock/package.json
  16. +8 −0 packages/amazon-bedrock/src/bedrock-chat-language-model.ts
  17. +11 −0 packages/anthropic/CHANGELOG.md
  18. +3 −3 packages/anthropic/package.json
  19. +22 −38 packages/anthropic/src/anthropic-messages-language-model.test.ts
  20. +3 −2 packages/anthropic/src/anthropic-messages-language-model.ts
  21. +13 −0 packages/azure/CHANGELOG.md
  22. +4 −4 packages/azure/package.json
  23. +45 −12 packages/azure/src/azure-openai-provider.test.ts
  24. +6 −0 packages/azure/src/azure-openai-provider.ts
  25. +11 −0 packages/cohere/CHANGELOG.md
  26. +3 −3 packages/cohere/package.json
  27. +20 −35 packages/cohere/src/cohere-chat-language-model.test.ts
  28. +3 −2 packages/cohere/src/cohere-chat-language-model.ts
  29. +16 −0 packages/core/CHANGELOG.md
  30. +21 −0 packages/core/core/embed/embed-many.test.ts
  31. +10 −2 packages/core/core/embed/embed-many.ts
  32. +20 −0 packages/core/core/embed/embed.test.ts
  33. +9 −4 packages/core/core/embed/embed.ts
  34. +25 −0 packages/core/core/generate-object/generate-object.test.ts
  35. +3 −0 packages/core/core/generate-object/generate-object.ts
  36. +41 −1 packages/core/core/generate-object/stream-object.test.ts
  37. +5 −0 packages/core/core/generate-object/stream-object.ts
  38. +24 −1 packages/core/core/generate-text/generate-text.test.ts
  39. +3 −0 packages/core/core/generate-text/generate-text.ts
  40. +37 −1 packages/core/core/generate-text/stream-text.test.ts
  41. +3 −0 packages/core/core/generate-text/stream-text.ts
  42. +6 −0 packages/core/core/prompt/call-settings.ts
  43. +8 −8 packages/core/package.json
  44. +44 −0 packages/core/rsc/stream-ui/__snapshots__/stream-ui.ui.test.tsx.snap
  45. +2 −0 packages/core/rsc/stream-ui/stream-ui.tsx
  46. +37 −0 packages/core/rsc/stream-ui/stream-ui.ui.test.tsx
  47. +7 −0 packages/core/tests/e2e/next-server/CHANGELOG.md
  48. +11 −0 packages/google-vertex/CHANGELOG.md
  49. +3 −3 packages/google-vertex/package.json
  50. +8 −0 packages/google-vertex/src/google-vertex-language-model.ts
  51. +11 −0 packages/google/CHANGELOG.md
  52. +3 −3 packages/google/package.json
  53. +20 −35 packages/google/src/google-generative-ai-language-model.test.ts
  54. +3 −2 packages/google/src/google-generative-ai-language-model.ts
  55. +11 −0 packages/mistral/CHANGELOG.md
  56. +3 −3 packages/mistral/package.json
  57. +20 −34 packages/mistral/src/mistral-chat-language-model.test.ts
  58. +3 −2 packages/mistral/src/mistral-chat-language-model.ts
  59. +10 −15 packages/mistral/src/mistral-embedding-model.test.ts
  60. +3 −1 packages/mistral/src/mistral-embedding-model.ts
  61. +11 −0 packages/openai/CHANGELOG.md
  62. +3 −3 packages/openai/package.json
  63. +24 −44 packages/openai/src/openai-chat-language-model.test.ts
  64. +3 −2 packages/openai/src/openai-chat-language-model.ts
  65. +24 −44 packages/openai/src/openai-completion-language-model.test.ts
  66. +3 −2 packages/openai/src/openai-completion-language-model.ts
  67. +12 −20 packages/openai/src/openai-embedding-model.test.ts
  68. +3 −1 packages/openai/src/openai-embedding-model.ts
  69. +12 −0 packages/provider-utils/CHANGELOG.md
  70. +2 −2 packages/provider-utils/package.json
  71. +11 −0 packages/provider-utils/src/combine-headers.ts
  72. +1 −0 packages/provider-utils/src/index.ts
  73. +3 −7 packages/provider-utils/src/post-to-api.ts
  74. +7 −0 packages/provider-utils/src/remove-undefined-entries.ts
  75. +9 −1 packages/provider-utils/src/test/json-test-server.ts
  76. +9 −1 packages/provider-utils/src/test/streaming-test-server.ts
  77. +6 −0 packages/provider/CHANGELOG.md
  78. +1 −1 packages/provider/package.json
  79. +6 −0 packages/provider/src/embedding-model/v1/embedding-model-v1.ts
  80. +6 −0 packages/provider/src/language-model/v1/language-model-v1-call-settings.ts
  81. +9 −0 packages/react/CHANGELOG.md
  82. +3 −3 packages/react/package.json
  83. +6 −0 packages/solid/CHANGELOG.md
  84. +2 −2 packages/solid/package.json
  85. +9 −0 packages/svelte/CHANGELOG.md
  86. +3 −3 packages/svelte/package.json
  87. +8 −0 packages/ui-utils/CHANGELOG.md
  88. +2 −2 packages/ui-utils/package.json
  89. +6 −0 packages/vue/CHANGELOG.md
  90. +2 −2 packages/vue/package.json
  91. +65 −65 pnpm-lock.yaml
26 changes: 26 additions & 0 deletions content/docs/03-ai-sdk-core/25-settings.mdx
Original file line number Diff line number Diff line change
@@ -74,3 +74,29 @@ Maximum number of retries. Set to 0 to disable retries. Default: `2`.
### `abortSignal`

An optional abort signal that can be used to cancel the call.

### `headers`

Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.

You can use the request headers to provide additional information to the provider,
depending on what the provider supports. For example, some observability providers support
headers such as `Prompt-Id`.

```ts
import { openai } from '@ai-sdk/openai';

const result = await generateText({
model: openai('gpt-3.5-turbo'),
prompt: 'Invent a new holiday and describe its traditions.',
headers: {
'Prompt-Id': 'my-prompt-id',
},
});
```

<Note>
The `headers` setting is for request-specific headers. You can also set
`headers` in the provider configuration. These headers will be sent with every
request made by the provider.
</Note>
7 changes: 7 additions & 0 deletions content/docs/07-reference/ai-sdk-core/01-generate-text.mdx
Original file line number Diff line number Diff line change
@@ -323,6 +323,13 @@ console.log(text);
description:
'An optional abort signal that can be used to cancel the call.',
},
{
name: 'headers',
type: 'Record<string, string>',
isOptional: true,
description:
'Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.',
},
{
name: 'maxAutomaticRoundtrips',
type: 'number',
7 changes: 7 additions & 0 deletions content/docs/07-reference/ai-sdk-core/02-stream-text.mdx
Original file line number Diff line number Diff line change
@@ -325,6 +325,13 @@ for await (const textPart of textStream) {
description:
'An optional abort signal that can be used to cancel the call.',
},
{
name: 'headers',
type: 'Record<string, string>',
isOptional: true,
description:
'Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.',
},
{
name: 'onFinish',
type: '(result: OnFinishResult) => void',
136 changes: 71 additions & 65 deletions content/docs/07-reference/ai-sdk-core/03-generate-object.mdx
Original file line number Diff line number Diff line change
@@ -42,29 +42,30 @@ console.log(JSON.stringify(object, null, 2));
{
name: 'model',
type: 'LanguageModel',
description: `The language model to use. Example: openai('gpt-4-turbo')`
description: `The language model to use. Example: openai('gpt-4-turbo')`,
},
{
name: 'mode',
type: "'auto' | 'json' | 'grammar' | 'tool'",
description:
"The mode to use for object generation. Not every model supports all modes. Defaults to 'auto'."
"The mode to use for object generation. Not every model supports all modes. Defaults to 'auto'.",
},
{
name: 'schema',
type: 'Zod Schema',
description: 'The schema that describes the shape of the object to generate. It is sent to the model to generate the object and used to validate the output.'
name: 'schema',
type: 'Zod Schema',
description:
'The schema that describes the shape of the object to generate. It is sent to the model to generate the object and used to validate the output.',
},
{
name: 'system',
type: 'string',
description:
'The system prompt to use that specifies the behavior of the model.'
'The system prompt to use that specifies the behavior of the model.',
},
{
name: 'prompt',
type: 'string',
description: 'The input prompt to generate the text from.'
description: 'The input prompt to generate the text from.',
},
{
name: 'messages',
@@ -77,22 +78,22 @@ console.log(JSON.stringify(object, null, 2));
{
name: 'role',
type: "'system'",
description: 'The role for the system message.'
description: 'The role for the system message.',
},
{
name: 'content',
type: 'string',
description: 'The content of the message.'
}
]
description: 'The content of the message.',
},
],
},
{
type: 'CoreUserMessage',
parameters: [
{
name: 'role',
type: "'user'",
description: 'The role for the user message.'
description: 'The role for the user message.',
},
{
name: 'content',
@@ -105,42 +106,42 @@ console.log(JSON.stringify(object, null, 2));
{
name: 'type',
type: "'text'",
description: 'The type of the message part.'
description: 'The type of the message part.',
},
{
name: 'text',
type: 'string',
description: 'The text content of the message part.'
}
]
description: 'The text content of the message part.',
},
],
},
{
type: 'ImagePart',
parameters: [
{
name: 'type',
type: "'image'",
description: 'The type of the message part.'
description: 'The type of the message part.',
},
{
name: 'image',
type: 'string | Uint8Array | Buffer | ArrayBuffer | URL',
description:
'The image content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs.'
}
]
}
]
}
]
'The image content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs.',
},
],
},
],
},
],
},
{
type: 'CoreAssistantMessage',
parameters: [
{
name: 'role',
type: "'assistant'",
description: 'The role for the assistant message.'
description: 'The role for the assistant message.',
},
{
name: 'content',
@@ -153,53 +154,53 @@ console.log(JSON.stringify(object, null, 2));
{
name: 'type',
type: "'text'",
description: 'The type of the message part.'
description: 'The type of the message part.',
},
{
name: 'text',
type: 'string',
description: 'The text content of the message part.'
}
]
description: 'The text content of the message part.',
},
],
},
{
type: 'ToolCallPart',
parameters: [
{
name: 'type',
type: "'tool-call'",
description: 'The type of the message part.'
description: 'The type of the message part.',
},
{
name: 'toolCallId',
type: 'string',
description: 'The id of the tool call.'
description: 'The id of the tool call.',
},
{
name: 'toolName',
type: 'string',
description:
'The name of the tool, which typically would be the name of the function.'
'The name of the tool, which typically would be the name of the function.',
},
{
name: 'args',
type: 'object based on zod schema',
description:
'Parameters generated by the model to be used by the tool.'
}
]
}
]
}
]
'Parameters generated by the model to be used by the tool.',
},
],
},
],
},
],
},
{
type: 'CoreToolMessage',
parameters: [
{
name: 'role',
type: "'tool'",
description: 'The role for the assistant message.'
description: 'The role for the assistant message.',
},
{
name: 'content',
@@ -212,99 +213,104 @@ console.log(JSON.stringify(object, null, 2));
{
name: 'type',
type: "'tool-result'",
description: 'The type of the message part.'
description: 'The type of the message part.',
},
{
name: 'toolCallId',
type: 'string',
description:
'The id of the tool call the result corresponds to.'
'The id of the tool call the result corresponds to.',
},
{
name: 'toolName',
type: 'string',
description:
'The name of the tool the result corresponds to.'
'The name of the tool the result corresponds to.',
},
{
name: 'result',
type: 'unknown',
description:
'The result returned by the tool after execution.'
'The result returned by the tool after execution.',
},
{
name: 'isError',
type: 'boolean',
isOptional: true,
description:
'Whether the result is an error or an error message.'
}
]
}
]
}
]
}
]
'Whether the result is an error or an error message.',
},
],
},
],
},
],
},
],
},

{
name: 'maxTokens',
type: 'number',
isOptional: true,
description: 'Maximum number of tokens to generate.'
description: 'Maximum number of tokens to generate.',
},
{
name: 'temperature',
type: 'number',
isOptional: true,
description:
'Temperature setting. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.'
'Temperature setting. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.',
},
{
name: 'topP',
type: 'number',
isOptional: true,
description:
'Nucleus sampling. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.'
'Nucleus sampling. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.',
},
{
name: 'presencePenalty',
type: 'number',
isOptional: true,
description:
'Presence penalty setting. It affects the likelihood of the model to repeat information that is already in the prompt. The value is passed through to the provider. The range depends on the provider and model.'
'Presence penalty setting. It affects the likelihood of the model to repeat information that is already in the prompt. The value is passed through to the provider. The range depends on the provider and model.',
},
{
name: 'frequencyPenalty',
type: 'number',
isOptional: true,
description:
'Frequency penalty setting. It affects the likelihood of the model to repeatedly use the same words or phrases. The value is passed through to the provider. The range depends on the provider and model.'
'Frequency penalty setting. It affects the likelihood of the model to repeatedly use the same words or phrases. The value is passed through to the provider. The range depends on the provider and model.',
},
{
name: 'seed',
type: 'number',
isOptional: true,
description:
'The seed (integer) to use for random sampling. If set and supported by the model, calls will generate deterministic results.'
'The seed (integer) to use for random sampling. If set and supported by the model, calls will generate deterministic results.',
},
{
name: 'maxRetries',
type: 'number',
isOptional: true,
description:
'Maximum number of retries. Set to 0 to disable retries. Default: 2.'
'Maximum number of retries. Set to 0 to disable retries. Default: 2.',
},
{
name: 'abortSignal',
type: 'AbortSignal',
isOptional: true,
description:
'An optional abort signal that can be used to cancel the call.'
}

]}
'An optional abort signal that can be used to cancel the call.',
},
{
name: 'headers',
type: 'Record<string, string>',
isOptional: true,
description:
'Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.',
},
]}
/>

### Returns
Loading