Skip to content

Automatically store BinaryContents in message history somewhere and turn them into FileUrlsΒ #3073

@DouweM

Description

@DouweM

Description

BinaryContent returned by the model (as in #2970) or uploaded by a user (as in https://ai.pydantic.dev/input/) is typically going to be too large to store in a DB or send to an OpenTelemetry backend, so it'd be good to have a way to specify a store_blob function that turns BinaryContent into a FileUrl, and have that be in the stored message history.

If the file is stored somewhere the model API can access, like a public bucket, the FileUrl will not need be converted back into a BinaryContent when using the message history, but if that's not the case you'd need a load_blob function as well that is given the FileUrl and can check the URL (e.g. starting with file: or x-custom: or https://my-bucket.s3), and download it if necessary.

The functions should probably take the run context so they can access deps to know where to store the data, e.g. based on the user or a region.

#2970 currently adds support for output_type=BinaryImage, and with this feature it could support output_type=ImageUrl as well, with the binary content returned by the model automatically uploaded to blob storage.

Inspired by https://github.com/nwcell/pydantic-ai-stash by @nwcell.

References

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions