feat (provider): add providerMetadata to ImageModelV2 interface#5977
Merged
feat (provider): add providerMetadata to ImageModelV2 interface#5977
providerMetadata to ImageModelV2 interface#5977Conversation
providerMetadata to ImageModelV2` interfaceproviderMetadata to ImageModelV2 interface
…generate-image.ts`
…nai/src/openai-image-model.ts`
…nai/src/openai-image-model.ts`
…cific type than `ProviderMetaData` to support image-specific metadata
…st for providerMetadata in packages/openai/src/openai-image-model.test.ts
lgrammel
reviewed
Apr 30, 2025
Comment on lines
+165
to
+174
| if (result.providerMetadata) { | ||
| for (const [providerName, metadata] of Object.entries<{ | ||
| images: unknown; | ||
| }>(result.providerMetadata)) { | ||
| providerMetadata[providerName] ??= { images: [] }; | ||
| providerMetadata[providerName].images.push( | ||
| ...result.providerMetadata[providerName].images, | ||
| ); | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
what about provider metadata that's not images?
Collaborator
Author
There was a problem hiding this comment.
It would be merged into the result.providerMetadata[providerName] object, but I haven't seen any meta data yet. I can prepare the code for it already though if you like?
lgrammel
reviewed
Apr 30, 2025
| export type ImageModelV2ProviderMetadata = Record< | ||
| string, | ||
| { | ||
| images: JSONArray; |
Collaborator
There was a problem hiding this comment.
can this be optional or null?
Collaborator
Author
There was a problem hiding this comment.
I think the dx would be better if it's always present, set to an array with the same length as the result.images array. But each item of the JSONArray can be null
lgrammel
approved these changes
Apr 30, 2025
lgrammel
pushed a commit
that referenced
this pull request
May 2, 2025
# Releases ## ai@5.0.0-canary.17 ### Major Changes - f04fb4a: chore (ai): replace useChat attachments with file ui parts - fd1924b: chore (ai): remove redundant `mimeType` property - fafc3f2: chore (ai): change file to parts to use urls instead of data - 92cb0a2: chore (ai): rename CoreMessage to ModelMessage ### Minor Changes - c9ad635: feat (ai): add filename to file ui parts ### Patch Changes - 9bd5ab5: feat (provider): add providerMetadata to ImageModelV2 interface (#5977) The `experimental_generateImage` method from the `ai` package now returnes revised prompts for OpenAI's image models. ```js const prompt = 'Santa Claus driving a Cadillac'; const { providerMetadata } = await experimental_generateImage({ model: openai.image('dall-e-3'), prompt, }); const revisedPrompt = providerMetadata.openai.images[0]?.revisedPrompt; console.log({ prompt, revisedPrompt, }); ``` - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/provider-utils@3.0.0-canary.14 ### Major Changes - 957b739: chore (provider-utils): rename TestServerCall.requestBody to requestBodyJson ### Patch Changes - Updated dependencies [9bd5ab5] - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/amazon-bedrock@3.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/anthropic@2.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/assemblyai@0.0.1-canary.2 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/azure@2.0.0-canary.16 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [136819b] - Updated dependencies [9bd5ab5] - Updated dependencies [284353f] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/openai@2.0.0-canary.15 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/cerebras@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/openai-compatible@1.0.0-canary.14 ## @ai-sdk/cohere@2.0.0-canary.15 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/deepgram@1.0.0-canary.7 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/deepinfra@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/openai-compatible@1.0.0-canary.14 ## @ai-sdk/deepseek@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/openai-compatible@1.0.0-canary.14 ## @ai-sdk/elevenlabs@1.0.0-canary.7 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/fal@1.0.0-canary.15 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/fireworks@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/openai-compatible@1.0.0-canary.14 ## @ai-sdk/gladia@1.0.0-canary.4 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/google@2.0.0-canary.15 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/google-vertex@3.0.0-canary.15 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/anthropic@2.0.0-canary.14 - @ai-sdk/google@2.0.0-canary.15 ## @ai-sdk/groq@2.0.0-canary.15 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/hume@1.0.0-canary.7 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/langchain@1.0.0-canary.5 ### Patch Changes - Updated dependencies [f04fb4a] - Updated dependencies [fd1924b] - Updated dependencies [957b739] - Updated dependencies [fafc3f2] - Updated dependencies [c9ad635] - Updated dependencies [9bd5ab5] - Updated dependencies [92cb0a2] - ai@5.0.0-canary.17 - @ai-sdk/provider-utils@3.0.0-canary.14 ## @ai-sdk/llamaindex@1.0.0-canary.5 ### Patch Changes - Updated dependencies [f04fb4a] - Updated dependencies [fd1924b] - Updated dependencies [957b739] - Updated dependencies [fafc3f2] - Updated dependencies [c9ad635] - Updated dependencies [9bd5ab5] - Updated dependencies [92cb0a2] - ai@5.0.0-canary.17 - @ai-sdk/provider-utils@3.0.0-canary.14 ## @ai-sdk/lmnt@1.0.0-canary.7 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/luma@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/mistral@2.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/openai@2.0.0-canary.15 ### Patch Changes - 136819b: chore(providers/openai): re-introduce logprobs as providerMetadata - 9bd5ab5: feat (provider): add providerMetadata to ImageModelV2 interface (#5977) The `experimental_generateImage` method from the `ai` package now returnes revised prompts for OpenAI's image models. ```js const prompt = 'Santa Claus driving a Cadillac'; const { providerMetadata } = await experimental_generateImage({ model: openai.image('dall-e-3'), prompt, }); const revisedPrompt = providerMetadata.openai.images[0]?.revisedPrompt; console.log({ prompt, revisedPrompt, }); ``` - 284353f: fix(providers/openai): zod parse error with function - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/openai-compatible@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/perplexity@2.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/provider@2.0.0-canary.13 ### Patch Changes - 9bd5ab5: feat (provider): add providerMetadata to ImageModelV2 interface (#5977) The `experimental_generateImage` method from the `ai` package now returnes revised prompts for OpenAI's image models. ```js const prompt = 'Santa Claus driving a Cadillac'; const { providerMetadata } = await experimental_generateImage({ model: openai.image('dall-e-3'), prompt, }); const revisedPrompt = providerMetadata.openai.images[0]?.revisedPrompt; console.log({ prompt, revisedPrompt, }); ``` ## @ai-sdk/react@2.0.0-canary.16 ### Patch Changes - c34ccd7: feat (ui/react): support resuming an ongoing stream - Updated dependencies [f04fb4a] - Updated dependencies [fd1924b] - Updated dependencies [957b739] - Updated dependencies [fafc3f2] - Updated dependencies [c9ad635] - Updated dependencies [9bd5ab5] - Updated dependencies [92cb0a2] - ai@5.0.0-canary.17 - @ai-sdk/provider-utils@3.0.0-canary.14 ## @ai-sdk/replicate@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/revai@1.0.0-canary.7 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/rsc@1.0.0-canary.15 ### Patch Changes - Updated dependencies [f04fb4a] - Updated dependencies [fd1924b] - Updated dependencies [957b739] - Updated dependencies [fafc3f2] - Updated dependencies [c9ad635] - Updated dependencies [9bd5ab5] - Updated dependencies [92cb0a2] - ai@5.0.0-canary.17 - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/svelte@3.0.0-canary.16 ### Patch Changes - Updated dependencies [f04fb4a] - Updated dependencies [fd1924b] - Updated dependencies [957b739] - Updated dependencies [fafc3f2] - Updated dependencies [c9ad635] - Updated dependencies [9bd5ab5] - Updated dependencies [92cb0a2] - ai@5.0.0-canary.17 - @ai-sdk/provider-utils@3.0.0-canary.14 ## @ai-sdk/togetherai@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/openai-compatible@1.0.0-canary.14 ## @ai-sdk/valibot@1.0.0-canary.16 ### Patch Changes - Updated dependencies [957b739] - @ai-sdk/provider-utils@3.0.0-canary.14 ## @ai-sdk/vue@2.0.0-canary.16 ### Patch Changes - Updated dependencies [f04fb4a] - Updated dependencies [fd1924b] - Updated dependencies [957b739] - Updated dependencies [fafc3f2] - Updated dependencies [c9ad635] - Updated dependencies [9bd5ab5] - Updated dependencies [92cb0a2] - ai@5.0.0-canary.17 - @ai-sdk/provider-utils@3.0.0-canary.14 ## @ai-sdk/xai@2.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/openai-compatible@1.0.0-canary.14 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
iteratetograceness
pushed a commit
to iteratetograceness/ai
that referenced
this pull request
May 9, 2025
…ercel#5977) ## Background Compare vercel#5698 ## Summary Additional provider-specific options to the image model provider interface. They are passed through to the provider from the AI SDK and enable provider-specific functionality that can be fully encapsulated in the provider. Unlike other models, ImageModel request return an array of images, and provider can return image-specific metadata for each. So far, this pull request passing through the revised prompt used for each image. In order to make that possible, I introduced a new type `ImageModelV2ProviderMetadata` which is the same as `SharedV2ProviderMetadata` plus it guarantees the presence of the `.images` key ```js export type ImageModelV2ProviderMetadata = Record< string, { images: JSONArray; } & JSONValue >; ``` That also makes it possible to deeply merge providerMetadata from multiple responses effectively. ## Verification I updated the `examples/ai-core/src/generate-image/openai.ts` example to verify that the code is working.
iteratetograceness
pushed a commit
to iteratetograceness/ai
that referenced
this pull request
May 9, 2025
# Releases ## ai@5.0.0-canary.17 ### Major Changes - f04fb4a: chore (ai): replace useChat attachments with file ui parts - fd1924b: chore (ai): remove redundant `mimeType` property - fafc3f2: chore (ai): change file to parts to use urls instead of data - 92cb0a2: chore (ai): rename CoreMessage to ModelMessage ### Minor Changes - c9ad635: feat (ai): add filename to file ui parts ### Patch Changes - 9bd5ab5: feat (provider): add providerMetadata to ImageModelV2 interface (vercel#5977) The `experimental_generateImage` method from the `ai` package now returnes revised prompts for OpenAI's image models. ```js const prompt = 'Santa Claus driving a Cadillac'; const { providerMetadata } = await experimental_generateImage({ model: openai.image('dall-e-3'), prompt, }); const revisedPrompt = providerMetadata.openai.images[0]?.revisedPrompt; console.log({ prompt, revisedPrompt, }); ``` - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/provider-utils@3.0.0-canary.14 ### Major Changes - 957b739: chore (provider-utils): rename TestServerCall.requestBody to requestBodyJson ### Patch Changes - Updated dependencies [9bd5ab5] - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/amazon-bedrock@3.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/anthropic@2.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/assemblyai@0.0.1-canary.2 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/azure@2.0.0-canary.16 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [136819b] - Updated dependencies [9bd5ab5] - Updated dependencies [284353f] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/openai@2.0.0-canary.15 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/cerebras@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/openai-compatible@1.0.0-canary.14 ## @ai-sdk/cohere@2.0.0-canary.15 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/deepgram@1.0.0-canary.7 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/deepinfra@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/openai-compatible@1.0.0-canary.14 ## @ai-sdk/deepseek@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/openai-compatible@1.0.0-canary.14 ## @ai-sdk/elevenlabs@1.0.0-canary.7 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/fal@1.0.0-canary.15 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/fireworks@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/openai-compatible@1.0.0-canary.14 ## @ai-sdk/gladia@1.0.0-canary.4 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/google@2.0.0-canary.15 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/google-vertex@3.0.0-canary.15 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/anthropic@2.0.0-canary.14 - @ai-sdk/google@2.0.0-canary.15 ## @ai-sdk/groq@2.0.0-canary.15 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/hume@1.0.0-canary.7 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/langchain@1.0.0-canary.5 ### Patch Changes - Updated dependencies [f04fb4a] - Updated dependencies [fd1924b] - Updated dependencies [957b739] - Updated dependencies [fafc3f2] - Updated dependencies [c9ad635] - Updated dependencies [9bd5ab5] - Updated dependencies [92cb0a2] - ai@5.0.0-canary.17 - @ai-sdk/provider-utils@3.0.0-canary.14 ## @ai-sdk/llamaindex@1.0.0-canary.5 ### Patch Changes - Updated dependencies [f04fb4a] - Updated dependencies [fd1924b] - Updated dependencies [957b739] - Updated dependencies [fafc3f2] - Updated dependencies [c9ad635] - Updated dependencies [9bd5ab5] - Updated dependencies [92cb0a2] - ai@5.0.0-canary.17 - @ai-sdk/provider-utils@3.0.0-canary.14 ## @ai-sdk/lmnt@1.0.0-canary.7 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/luma@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/mistral@2.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/openai@2.0.0-canary.15 ### Patch Changes - 136819b: chore(providers/openai): re-introduce logprobs as providerMetadata - 9bd5ab5: feat (provider): add providerMetadata to ImageModelV2 interface (vercel#5977) The `experimental_generateImage` method from the `ai` package now returnes revised prompts for OpenAI's image models. ```js const prompt = 'Santa Claus driving a Cadillac'; const { providerMetadata } = await experimental_generateImage({ model: openai.image('dall-e-3'), prompt, }); const revisedPrompt = providerMetadata.openai.images[0]?.revisedPrompt; console.log({ prompt, revisedPrompt, }); ``` - 284353f: fix(providers/openai): zod parse error with function - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/openai-compatible@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/perplexity@2.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/provider@2.0.0-canary.13 ### Patch Changes - 9bd5ab5: feat (provider): add providerMetadata to ImageModelV2 interface (vercel#5977) The `experimental_generateImage` method from the `ai` package now returnes revised prompts for OpenAI's image models. ```js const prompt = 'Santa Claus driving a Cadillac'; const { providerMetadata } = await experimental_generateImage({ model: openai.image('dall-e-3'), prompt, }); const revisedPrompt = providerMetadata.openai.images[0]?.revisedPrompt; console.log({ prompt, revisedPrompt, }); ``` ## @ai-sdk/react@2.0.0-canary.16 ### Patch Changes - c34ccd7: feat (ui/react): support resuming an ongoing stream - Updated dependencies [f04fb4a] - Updated dependencies [fd1924b] - Updated dependencies [957b739] - Updated dependencies [fafc3f2] - Updated dependencies [c9ad635] - Updated dependencies [9bd5ab5] - Updated dependencies [92cb0a2] - ai@5.0.0-canary.17 - @ai-sdk/provider-utils@3.0.0-canary.14 ## @ai-sdk/replicate@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/revai@1.0.0-canary.7 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/rsc@1.0.0-canary.15 ### Patch Changes - Updated dependencies [f04fb4a] - Updated dependencies [fd1924b] - Updated dependencies [957b739] - Updated dependencies [fafc3f2] - Updated dependencies [c9ad635] - Updated dependencies [9bd5ab5] - Updated dependencies [92cb0a2] - ai@5.0.0-canary.17 - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 ## @ai-sdk/svelte@3.0.0-canary.16 ### Patch Changes - Updated dependencies [f04fb4a] - Updated dependencies [fd1924b] - Updated dependencies [957b739] - Updated dependencies [fafc3f2] - Updated dependencies [c9ad635] - Updated dependencies [9bd5ab5] - Updated dependencies [92cb0a2] - ai@5.0.0-canary.17 - @ai-sdk/provider-utils@3.0.0-canary.14 ## @ai-sdk/togetherai@1.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/openai-compatible@1.0.0-canary.14 ## @ai-sdk/valibot@1.0.0-canary.16 ### Patch Changes - Updated dependencies [957b739] - @ai-sdk/provider-utils@3.0.0-canary.14 ## @ai-sdk/vue@2.0.0-canary.16 ### Patch Changes - Updated dependencies [f04fb4a] - Updated dependencies [fd1924b] - Updated dependencies [957b739] - Updated dependencies [fafc3f2] - Updated dependencies [c9ad635] - Updated dependencies [9bd5ab5] - Updated dependencies [92cb0a2] - ai@5.0.0-canary.17 - @ai-sdk/provider-utils@3.0.0-canary.14 ## @ai-sdk/xai@2.0.0-canary.14 ### Patch Changes - Updated dependencies [957b739] - Updated dependencies [9bd5ab5] - @ai-sdk/provider-utils@3.0.0-canary.14 - @ai-sdk/provider@2.0.0-canary.13 - @ai-sdk/openai-compatible@1.0.0-canary.14 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Compare #5698
Summary
Additional provider-specific options to the image model provider interface. They are passed through to the provider from the AI SDK and enable provider-specific functionality that can be fully encapsulated in the provider.
Unlike other models, ImageModel request return an array of images, and provider can return image-specific metadata for each. So far, this pull request passing through the revised prompt used for each image. In order to make that possible, I introduced a new type
ImageModelV2ProviderMetadatawhich is the same asSharedV2ProviderMetadataplus it guarantees the presence of the.imageskeyThat also makes it possible to deeply merge providerMetadata from multiple responses effectively.
Verification
I updated the
examples/ai-core/src/generate-image/openai.tsexample to verify that the code is working.Tasks
pnpm changesetin the project root)pnpm prettier-fixin the project root)Future Work
.providerMetadatafor these types of models.providerMetadatain image models by other providers - Follow up issue: [v5] Implement.providerMetadataacross all image models #6405