feat: add Image type for image-specific file handling#2567
Open
feat: add Image type for image-specific file handling#2567
Conversation
This PR adds a new `cog.Image` type that extends `cog.Path` to provide image-specific handling in model inputs and outputs. The Image type works identically to Path but produces OpenAPI schemas with `format: "uri"` and `x-cog-type: "image"`, following the same pattern as streaming outputs that use `x-cog-array-type: "iterator"`. This allows UIs to provide image-specific widgets while correctly identifying the value as a URI. Changes: - Add Image class in cog/types.py with Pydantic v1 and v2 support - Export Image from cog package - Update AST-based OpenAPI schema generation to handle Image type - Add comprehensive unit and integration tests - Update documentation with Image type examples
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.
This experimental PR adds a new
cog.Imagetype that extendscog.Pathto provide image-specific handling in model inputs and outputs.The Image type works identically to Path but produces OpenAPI schemas with
format: "uri"andx-cog-type: "image", following the same pattern as streaming outputs that usex-cog-array-type: "iterator". This allows UIs to provide image-specific widgets while correctly identifying the value as a URI.Example usage
OpenAPI schema
The generated OpenAPI schema for an Image input:
{ "image": { "title": "Image", "description": "An input image", "type": "string", "format": "uri", "x-cog-type": "image" } }Related: