dspy.Image¶
dspy.Image(url: Any = None, *, download: bool = False, **data)
¶
Bases: Type
Create an Image.
Parameters¶
url: The image source. Supported values include
- ``str``: HTTP(S)/GS URL or local file path
- ``bytes``: raw image bytes
- ``PIL.Image.Image``: a PIL image instance
- ``dict`` with a single ``{"url": value}`` entry (legacy form)
- already encoded data URI
download
Whether remote URLs should be downloaded to infer their MIME type.
Any additional keyword arguments are passed to :class:pydantic.BaseModel
.
Source code in dspy/adapters/types/image.py
Functions¶
description() -> str
classmethod
¶
extract_custom_type_from_annotation(annotation)
classmethod
¶
Extract all custom types from the annotation.
This is used to extract all custom types from the annotation of a field, while the annotation can
have arbitrary level of nesting. For example, we detect Tool
is in list[dict[str, Tool]]
.
Source code in dspy/adapters/types/base_type.py
format() -> list[dict[str, Any]] | str
cached
¶
Source code in dspy/adapters/types/image.py
from_PIL(pil_image)
classmethod
¶
from_file(file_path: str)
classmethod
¶
from_url(url: str, download: bool = False)
classmethod
¶
is_streamable() -> bool
classmethod
¶
parse_lm_response(response: str | dict[str, Any]) -> Optional[Type]
classmethod
¶
Parse a LM response into the custom type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response
|
str | dict[str, Any]
|
A LM response. |
required |
Returns:
Type | Description |
---|---|
Optional[Type]
|
A custom type object. |
parse_stream_chunk(chunk: ModelResponseStream) -> Optional[Type]
classmethod
¶
Parse a stream chunk into the custom type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunk
|
ModelResponseStream
|
A stream chunk. |
required |
Returns:
Type | Description |
---|---|
Optional[Type]
|
A custom type object or None if the chunk is not for this custom type. |
Source code in dspy/adapters/types/base_type.py
serialize_model()
¶
Source code in dspy/adapters/types/base_type.py
:::