Skip to content

content

Class info

Classes

Name Children Inherits
AudioBase64Content
llmling_agent.models.content
Audio from base64 data.
    AudioContent
    llmling_agent.models.content
    Base for audio content.
    AudioURLContent
    llmling_agent.models.content
    Audio from URL.
      BaseContent
      llmling_agent.models.content
      Base class for special content types (non-text).
      BaseImageContent
      llmling_agent.models.content
      Base for image content.
      BasePDFContent
      llmling_agent.models.content
      Base for PDF document content.
      ImageBase64Content
      llmling_agent.models.content
      Image from base64 data.
        ImageURLContent
        llmling_agent.models.content
        Image from URL.
          PDFBase64Content
          llmling_agent.models.content
          PDF from base64 data.
            PDFURLContent
            llmling_agent.models.content
            PDF from URL.
              VideoContent
              llmling_agent.models.content
              Base for video content.
              VideoURLContent
              llmling_agent.models.content
              Video from URL.

                🛈 DocStrings

                Content types for messages.

                AudioBase64Content

                Bases: AudioContent

                Audio from base64 data.

                Source code in src/llmling_agent/models/content.py
                244
                245
                246
                247
                248
                249
                250
                251
                252
                253
                254
                255
                256
                257
                258
                259
                260
                261
                262
                263
                264
                265
                266
                267
                268
                269
                270
                271
                272
                273
                274
                275
                276
                277
                278
                279
                280
                281
                282
                283
                284
                285
                class AudioBase64Content(AudioContent):
                    """Audio from base64 data."""
                
                    type: Literal["audio_base64"] = Field("audio_base64", init=False)
                    """Base64-encoded audio."""
                
                    data: str
                    """Audio data in base64 format."""
                
                    format: str | None = None  # mp3, wav, etc
                    """Audio format."""
                
                    def to_pydantic_ai(self) -> BinaryContent:
                        binary_data = base64.b64decode(self.data)
                        return BinaryContent(data=binary_data, media_type=f"audio/{self.format or 'mp3'}")
                
                    @classmethod
                    def from_bytes(cls, data: bytes, audio_format: str = "mp3") -> Self:
                        """Create from raw bytes."""
                        return cls(data=base64.b64encode(data).decode(), format=audio_format)
                
                    @classmethod
                    def from_path(cls, path: JoinablePathLike) -> Self:
                        """Create from file path with auto format detection."""
                        import mimetypes
                
                        from upathtools import to_upath
                
                        path_obj = to_upath(path)
                        mime_type, _ = mimetypes.guess_type(str(path_obj))
                        fmt = (
                            mime_type.removeprefix("audio/")
                            if mime_type and mime_type.startswith("audio/")
                            else "mp3"
                        )
                
                        return cls(data=base64.b64encode(path_obj.read_bytes()).decode(), format=fmt)
                
                    @property
                    def mime_type(self) -> str:
                        """Return the MIME type of the audio."""
                        return f"audio/{self.format or 'mp3'}"
                

                data instance-attribute

                data: str
                

                Audio data in base64 format.

                format class-attribute instance-attribute

                format: str | None = None
                

                Audio format.

                mime_type property

                mime_type: str
                

                Return the MIME type of the audio.

                type class-attribute instance-attribute

                type: Literal['audio_base64'] = Field('audio_base64', init=False)
                

                Base64-encoded audio.

                from_bytes classmethod

                from_bytes(data: bytes, audio_format: str = 'mp3') -> Self
                

                Create from raw bytes.

                Source code in src/llmling_agent/models/content.py
                260
                261
                262
                263
                @classmethod
                def from_bytes(cls, data: bytes, audio_format: str = "mp3") -> Self:
                    """Create from raw bytes."""
                    return cls(data=base64.b64encode(data).decode(), format=audio_format)
                

                from_path classmethod

                from_path(path: JoinablePathLike) -> Self
                

                Create from file path with auto format detection.

                Source code in src/llmling_agent/models/content.py
                265
                266
                267
                268
                269
                270
                271
                272
                273
                274
                275
                276
                277
                278
                279
                280
                @classmethod
                def from_path(cls, path: JoinablePathLike) -> Self:
                    """Create from file path with auto format detection."""
                    import mimetypes
                
                    from upathtools import to_upath
                
                    path_obj = to_upath(path)
                    mime_type, _ = mimetypes.guess_type(str(path_obj))
                    fmt = (
                        mime_type.removeprefix("audio/")
                        if mime_type and mime_type.startswith("audio/")
                        else "mp3"
                    )
                
                    return cls(data=base64.b64encode(path_obj.read_bytes()).decode(), format=fmt)
                

                AudioContent

                Bases: BaseContent

                Base for audio content.

                Source code in src/llmling_agent/models/content.py
                221
                222
                223
                224
                225
                226
                227
                228
                class AudioContent(BaseContent):
                    """Base for audio content."""
                
                    format: str | None = None  # mp3, wav, etc
                    """Audio format."""
                
                    description: str | None = None
                    """Human-readable description of the content."""
                

                description class-attribute instance-attribute

                description: str | None = None
                

                Human-readable description of the content.

                format class-attribute instance-attribute

                format: str | None = None
                

                Audio format.

                AudioURLContent

                Bases: AudioContent

                Audio from URL.

                Source code in src/llmling_agent/models/content.py
                231
                232
                233
                234
                235
                236
                237
                238
                239
                240
                241
                class AudioURLContent(AudioContent):
                    """Audio from URL."""
                
                    type: Literal["audio_url"] = Field("audio_url", init=False)
                    """URL-based audio."""
                
                    url: str
                    """URL to the audio."""
                
                    def to_pydantic_ai(self) -> AudioUrl:
                        return AudioUrl(url=self.url)
                

                type class-attribute instance-attribute

                type: Literal['audio_url'] = Field('audio_url', init=False)
                

                URL-based audio.

                url instance-attribute

                url: str
                

                URL to the audio.

                BaseContent

                Bases: Schema

                Base class for special content types (non-text).

                Source code in src/llmling_agent/models/content.py
                30
                31
                32
                33
                34
                35
                36
                37
                38
                39
                40
                41
                42
                43
                class BaseContent(Schema):
                    """Base class for special content types (non-text)."""
                
                    type: str = Field(init=False)
                    """Discriminator field for content types."""
                
                    description: str | None = None
                    """Human-readable description of the content."""
                
                    model_config = ConfigDict(frozen=True)
                
                    def to_pydantic_ai(self) -> UserContent:
                        msg = "Subclasses must implement this method"
                        raise NotImplementedError(msg)
                

                description class-attribute instance-attribute

                description: str | None = None
                

                Human-readable description of the content.

                type class-attribute instance-attribute

                type: str = Field(init=False)
                

                Discriminator field for content types.

                BaseImageContent

                Bases: BaseContent

                Base for image content.

                Source code in src/llmling_agent/models/content.py
                46
                47
                48
                49
                50
                51
                52
                53
                54
                55
                56
                57
                58
                59
                60
                61
                62
                63
                64
                65
                66
                67
                68
                69
                70
                71
                72
                73
                74
                75
                76
                77
                78
                79
                80
                81
                82
                83
                84
                85
                86
                87
                class BaseImageContent(BaseContent):
                    """Base for image content."""
                
                    detail: DetailLevel | None = None
                    """Detail level for image processing by vision models.
                    - high: Maximum resolution (up to 2048x2048)
                    - low: Lower resolution (512x512)
                    - auto: Let model decide based on content
                    """
                
                    @classmethod
                    async def from_path(
                        cls,
                        path: JoinablePathLike,
                        *,
                        detail: DetailLevel | None = None,
                        description: str | None = None,
                    ) -> ImageURLContent | ImageBase64Content:
                        """Create image content from any path.
                
                        Automatically chooses between URL and base64 based on path type.
                        Downloads and converts remote content if needed.
                
                        Args:
                            path: Local path or URL to image
                            detail: Optional detail level for processing
                            description: Optional description of the image
                        """
                        from upathtools import to_upath
                
                        path_obj = to_upath(path)
                
                        # For http(s) URLs, pass through as URL content
                        if path_obj.protocol in {"http", "https"}:
                            return ImageURLContent(
                                url=str(path_obj), detail=detail, description=description
                            )
                
                        # For all other paths, read and convert to base64
                        data = await read_path(path_obj, mode="rb")
                        content = base64.b64encode(data).decode()
                        return ImageBase64Content(data=content, detail=detail, description=description)
                

                detail class-attribute instance-attribute

                detail: DetailLevel | None = None
                

                Detail level for image processing by vision models. - high: Maximum resolution (up to 2048x2048) - low: Lower resolution (512x512) - auto: Let model decide based on content

                from_path async classmethod

                from_path(
                    path: JoinablePathLike,
                    *,
                    detail: DetailLevel | None = None,
                    description: str | None = None
                ) -> ImageURLContent | ImageBase64Content
                

                Create image content from any path.

                Automatically chooses between URL and base64 based on path type. Downloads and converts remote content if needed.

                Parameters:

                Name Type Description Default
                path JoinablePathLike

                Local path or URL to image

                required
                detail DetailLevel | None

                Optional detail level for processing

                None
                description str | None

                Optional description of the image

                None
                Source code in src/llmling_agent/models/content.py
                56
                57
                58
                59
                60
                61
                62
                63
                64
                65
                66
                67
                68
                69
                70
                71
                72
                73
                74
                75
                76
                77
                78
                79
                80
                81
                82
                83
                84
                85
                86
                87
                @classmethod
                async def from_path(
                    cls,
                    path: JoinablePathLike,
                    *,
                    detail: DetailLevel | None = None,
                    description: str | None = None,
                ) -> ImageURLContent | ImageBase64Content:
                    """Create image content from any path.
                
                    Automatically chooses between URL and base64 based on path type.
                    Downloads and converts remote content if needed.
                
                    Args:
                        path: Local path or URL to image
                        detail: Optional detail level for processing
                        description: Optional description of the image
                    """
                    from upathtools import to_upath
                
                    path_obj = to_upath(path)
                
                    # For http(s) URLs, pass through as URL content
                    if path_obj.protocol in {"http", "https"}:
                        return ImageURLContent(
                            url=str(path_obj), detail=detail, description=description
                        )
                
                    # For all other paths, read and convert to base64
                    data = await read_path(path_obj, mode="rb")
                    content = base64.b64encode(data).decode()
                    return ImageBase64Content(data=content, detail=detail, description=description)
                

                BasePDFContent

                Bases: BaseContent

                Base for PDF document content.

                Source code in src/llmling_agent/models/content.py
                145
                146
                147
                148
                149
                150
                151
                152
                153
                154
                155
                156
                157
                158
                159
                160
                161
                162
                163
                164
                165
                166
                167
                168
                169
                170
                171
                172
                173
                174
                175
                176
                177
                178
                179
                class BasePDFContent(BaseContent):
                    """Base for PDF document content."""
                
                    detail: DetailLevel | None = None
                    """Detail level for document processing by models."""
                
                    @classmethod
                    async def from_path(
                        cls,
                        path: JoinablePathLike,
                        *,
                        detail: DetailLevel | None = None,
                        description: str | None = None,
                    ) -> PDFURLContent | PDFBase64Content:
                        """Create PDF content from any path.
                
                        Args:
                            path: Local path or URL to PDF
                            detail: Optional detail level for processing
                            description: Optional description of the document
                        """
                        from upathtools import to_upath
                
                        path_obj = to_upath(path)
                
                        # For http(s) URLs, pass through as URL content
                        if path_obj.protocol in {"http", "https"}:
                            return PDFURLContent(
                                url=str(path_obj), detail=detail, description=description
                            )
                
                        # For all other paths, read and convert to base64
                        data = await read_path(path_obj, mode="rb")
                        content = base64.b64encode(data).decode()
                        return PDFBase64Content(data=content, detail=detail, description=description)
                

                detail class-attribute instance-attribute

                detail: DetailLevel | None = None
                

                Detail level for document processing by models.

                from_path async classmethod

                from_path(
                    path: JoinablePathLike,
                    *,
                    detail: DetailLevel | None = None,
                    description: str | None = None
                ) -> PDFURLContent | PDFBase64Content
                

                Create PDF content from any path.

                Parameters:

                Name Type Description Default
                path JoinablePathLike

                Local path or URL to PDF

                required
                detail DetailLevel | None

                Optional detail level for processing

                None
                description str | None

                Optional description of the document

                None
                Source code in src/llmling_agent/models/content.py
                151
                152
                153
                154
                155
                156
                157
                158
                159
                160
                161
                162
                163
                164
                165
                166
                167
                168
                169
                170
                171
                172
                173
                174
                175
                176
                177
                178
                179
                @classmethod
                async def from_path(
                    cls,
                    path: JoinablePathLike,
                    *,
                    detail: DetailLevel | None = None,
                    description: str | None = None,
                ) -> PDFURLContent | PDFBase64Content:
                    """Create PDF content from any path.
                
                    Args:
                        path: Local path or URL to PDF
                        detail: Optional detail level for processing
                        description: Optional description of the document
                    """
                    from upathtools import to_upath
                
                    path_obj = to_upath(path)
                
                    # For http(s) URLs, pass through as URL content
                    if path_obj.protocol in {"http", "https"}:
                        return PDFURLContent(
                            url=str(path_obj), detail=detail, description=description
                        )
                
                    # For all other paths, read and convert to base64
                    data = await read_path(path_obj, mode="rb")
                    content = base64.b64encode(data).decode()
                    return PDFBase64Content(data=content, detail=detail, description=description)
                

                ImageBase64Content

                Bases: BaseImageContent

                Image from base64 data.

                Source code in src/llmling_agent/models/content.py
                103
                104
                105
                106
                107
                108
                109
                110
                111
                112
                113
                114
                115
                116
                117
                118
                119
                120
                121
                122
                123
                124
                125
                126
                127
                128
                129
                130
                131
                132
                133
                134
                135
                136
                137
                138
                139
                140
                141
                142
                class ImageBase64Content(BaseImageContent):
                    """Image from base64 data."""
                
                    type: Literal["image_base64"] = Field("image_base64", init=False)
                    """Base64-encoded image."""
                
                    data: str
                    """Base64-encoded image data."""
                
                    mime_type: str = "image/jpeg"
                    """MIME type of the image."""
                
                    def to_pydantic_ai(self) -> BinaryImage:
                        binary_data = base64.b64decode(self.data)
                        return BinaryImage(data=binary_data, media_type=self.mime_type or "image/jpeg")
                
                    @classmethod
                    def from_bytes(
                        cls,
                        data: bytes,
                        *,
                        detail: DetailLevel | None = None,
                        description: str | None = None,
                    ) -> ImageBase64Content:
                        """Create image content from raw bytes.
                
                        Args:
                            data: Raw image bytes
                            detail: Optional detail level for processing
                            description: Optional description of the image
                        """
                        content = base64.b64encode(data).decode()
                        return cls(data=content, detail=detail, description=description)
                
                    @classmethod
                    def from_pil_image(cls, image: PIL.Image.Image) -> ImageBase64Content:
                        """Create content from PIL Image."""
                        with io.BytesIO() as buffer:
                            image.save(buffer, format="PNG")
                            return cls(data=base64.b64encode(buffer.getvalue()).decode())
                

                data instance-attribute

                data: str
                

                Base64-encoded image data.

                mime_type class-attribute instance-attribute

                mime_type: str = 'image/jpeg'
                

                MIME type of the image.

                type class-attribute instance-attribute

                type: Literal['image_base64'] = Field('image_base64', init=False)
                

                Base64-encoded image.

                from_bytes classmethod

                from_bytes(
                    data: bytes, *, detail: DetailLevel | None = None, description: str | None = None
                ) -> ImageBase64Content
                

                Create image content from raw bytes.

                Parameters:

                Name Type Description Default
                data bytes

                Raw image bytes

                required
                detail DetailLevel | None

                Optional detail level for processing

                None
                description str | None

                Optional description of the image

                None
                Source code in src/llmling_agent/models/content.py
                119
                120
                121
                122
                123
                124
                125
                126
                127
                128
                129
                130
                131
                132
                133
                134
                135
                @classmethod
                def from_bytes(
                    cls,
                    data: bytes,
                    *,
                    detail: DetailLevel | None = None,
                    description: str | None = None,
                ) -> ImageBase64Content:
                    """Create image content from raw bytes.
                
                    Args:
                        data: Raw image bytes
                        detail: Optional detail level for processing
                        description: Optional description of the image
                    """
                    content = base64.b64encode(data).decode()
                    return cls(data=content, detail=detail, description=description)
                

                from_pil_image classmethod

                from_pil_image(image: Image) -> ImageBase64Content
                

                Create content from PIL Image.

                Source code in src/llmling_agent/models/content.py
                137
                138
                139
                140
                141
                142
                @classmethod
                def from_pil_image(cls, image: PIL.Image.Image) -> ImageBase64Content:
                    """Create content from PIL Image."""
                    with io.BytesIO() as buffer:
                        image.save(buffer, format="PNG")
                        return cls(data=base64.b64encode(buffer.getvalue()).decode())
                

                ImageURLContent

                Bases: BaseImageContent

                Image from URL.

                Source code in src/llmling_agent/models/content.py
                 90
                 91
                 92
                 93
                 94
                 95
                 96
                 97
                 98
                 99
                100
                class ImageURLContent(BaseImageContent):
                    """Image from URL."""
                
                    type: Literal["image_url"] = Field("image_url", init=False)
                    """URL-based image."""
                
                    url: str
                    """URL to the image."""
                
                    def to_pydantic_ai(self) -> ImageUrl:
                        return ImageUrl(url=self.url)
                

                type class-attribute instance-attribute

                type: Literal['image_url'] = Field('image_url', init=False)
                

                URL-based image.

                url instance-attribute

                url: str
                

                URL to the image.

                PDFBase64Content

                Bases: BasePDFContent

                PDF from base64 data.

                Source code in src/llmling_agent/models/content.py
                195
                196
                197
                198
                199
                200
                201
                202
                203
                204
                205
                206
                207
                208
                209
                210
                211
                212
                213
                214
                215
                216
                217
                218
                class PDFBase64Content(BasePDFContent):
                    """PDF from base64 data."""
                
                    type: Literal["pdf_base64"] = Field("pdf_base64", init=False)
                    """Base64-data based PDF."""
                
                    data: str
                    """Base64-encoded PDF data."""
                
                    @classmethod
                    def from_bytes(
                        cls,
                        data: bytes,
                        *,
                        detail: DetailLevel | None = None,
                        description: str | None = None,
                    ) -> Self:
                        """Create PDF content from raw bytes."""
                        content = base64.b64encode(data).decode()
                        return cls(data=content, detail=detail, description=description)
                
                    def to_pydantic_ai(self) -> BinaryContent:
                        binary_data = base64.b64decode(self.data)
                        return BinaryContent(binary_data, media_type="application/pdf")
                

                data instance-attribute

                data: str
                

                Base64-encoded PDF data.

                type class-attribute instance-attribute

                type: Literal['pdf_base64'] = Field('pdf_base64', init=False)
                

                Base64-data based PDF.

                from_bytes classmethod

                from_bytes(
                    data: bytes, *, detail: DetailLevel | None = None, description: str | None = None
                ) -> Self
                

                Create PDF content from raw bytes.

                Source code in src/llmling_agent/models/content.py
                204
                205
                206
                207
                208
                209
                210
                211
                212
                213
                214
                @classmethod
                def from_bytes(
                    cls,
                    data: bytes,
                    *,
                    detail: DetailLevel | None = None,
                    description: str | None = None,
                ) -> Self:
                    """Create PDF content from raw bytes."""
                    content = base64.b64encode(data).decode()
                    return cls(data=content, detail=detail, description=description)
                

                PDFURLContent

                Bases: BasePDFContent

                PDF from URL.

                Source code in src/llmling_agent/models/content.py
                182
                183
                184
                185
                186
                187
                188
                189
                190
                191
                192
                class PDFURLContent(BasePDFContent):
                    """PDF from URL."""
                
                    type: Literal["pdf_url"] = Field("pdf_url", init=False)
                    """URL-based PDF."""
                
                    url: str
                    """URL to the PDF document."""
                
                    def to_pydantic_ai(self) -> DocumentUrl:
                        return DocumentUrl(url=self.url)
                

                type class-attribute instance-attribute

                type: Literal['pdf_url'] = Field('pdf_url', init=False)
                

                URL-based PDF.

                url instance-attribute

                url: str
                

                URL to the PDF document.

                VideoContent

                Bases: BaseContent

                Base for video content.

                Source code in src/llmling_agent/models/content.py
                288
                289
                290
                291
                292
                293
                294
                295
                class VideoContent(BaseContent):
                    """Base for video content."""
                
                    format: str | None = None
                    """Video format."""
                
                    description: str | None = None
                    """Human-readable description of the content."""
                

                description class-attribute instance-attribute

                description: str | None = None
                

                Human-readable description of the content.

                format class-attribute instance-attribute

                format: str | None = None
                

                Video format.

                VideoURLContent

                Bases: VideoContent

                Video from URL.

                Source code in src/llmling_agent/models/content.py
                298
                299
                300
                301
                302
                303
                304
                305
                class VideoURLContent(VideoContent):
                    """Video from URL."""
                
                    type: Literal["video_url"] = Field("video_url", init=False)
                    """URL-based video."""
                
                    url: str
                    """URL to the video."""
                

                type class-attribute instance-attribute

                type: Literal['video_url'] = Field('video_url', init=False)
                

                URL-based video.

                url instance-attribute

                url: str
                

                URL to the video.