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.

              🛈 DocStrings

              Content types for messages.

              AudioBase64Content

              Bases: AudioContent

              Audio from base64 data.

              Source code in src/llmling_agent/models/content.py
              237
              238
              239
              240
              241
              242
              243
              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
              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_openai_format(self) -> dict[str, Any]:
                      """Convert to OpenAI API format for audio models."""
                      data_url = f"data:audio/{self.format or 'mp3'};base64,{self.data}"
                      content = {"url": data_url, "format": self.format or "auto"}
                      return {"type": "audio", "audio": content}
              
                  @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: StrPath) -> Self:
                      """Create from file path with auto format detection."""
                      import mimetypes
              
                      from upath import UPath
              
                      path_obj = 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)
              

              data instance-attribute

              data: str
              

              Audio data in base64 format.

              format class-attribute instance-attribute

              format: str | None = None
              

              Audio format.

              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
              255
              256
              257
              258
              @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: StrPath) -> Self
              

              Create from file path with auto format detection.

              Source code in src/llmling_agent/models/content.py
              260
              261
              262
              263
              264
              265
              266
              267
              268
              269
              270
              271
              272
              273
              274
              275
              @classmethod
              def from_path(cls, path: StrPath) -> Self:
                  """Create from file path with auto format detection."""
                  import mimetypes
              
                  from upath import UPath
              
                  path_obj = 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)
              

              to_openai_format

              to_openai_format() -> dict[str, Any]
              

              Convert to OpenAI API format for audio models.

              Source code in src/llmling_agent/models/content.py
              249
              250
              251
              252
              253
              def to_openai_format(self) -> dict[str, Any]:
                  """Convert to OpenAI API format for audio models."""
                  data_url = f"data:audio/{self.format or 'mp3'};base64,{self.data}"
                  content = {"url": data_url, "format": self.format or "auto"}
                  return {"type": "audio", "audio": content}
              

              AudioContent

              Bases: BaseContent

              Base for audio content.

              Source code in src/llmling_agent/models/content.py
              212
              213
              214
              215
              216
              217
              218
              219
              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
              222
              223
              224
              225
              226
              227
              228
              229
              230
              231
              232
              233
              234
              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_openai_format(self) -> dict[str, Any]:
                      """Convert to OpenAI API format for audio models."""
                      content = {"url": self.url, "format": self.format or "auto"}
                      return {"type": "audio", "audio": content}
              

              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.

              to_openai_format

              to_openai_format() -> dict[str, Any]
              

              Convert to OpenAI API format for audio models.

              Source code in src/llmling_agent/models/content.py
              231
              232
              233
              234
              def to_openai_format(self) -> dict[str, Any]:
                  """Convert to OpenAI API format for audio models."""
                  content = {"url": self.url, "format": self.format or "auto"}
                  return {"type": "audio", "audio": content}
              

              BaseContent

              Bases: BaseModel

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

              Source code in src/llmling_agent/models/content.py
              23
              24
              25
              26
              27
              28
              29
              30
              31
              32
              33
              34
              35
              36
              class BaseContent(BaseModel):
                  """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, use_attribute_docstrings=True, extra="forbid")
              
                  def to_openai_format(self) -> dict[str, Any]:
                      """Convert to OpenAI API format."""
                      raise NotImplementedError
              

              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.

              to_openai_format

              to_openai_format() -> dict[str, Any]
              

              Convert to OpenAI API format.

              Source code in src/llmling_agent/models/content.py
              34
              35
              36
              def to_openai_format(self) -> dict[str, Any]:
                  """Convert to OpenAI API format."""
                  raise NotImplementedError
              

              BaseImageContent

              Bases: BaseContent

              Base for image content.

              Source code in src/llmling_agent/models/content.py
              39
              40
              41
              42
              43
              44
              45
              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
              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: StrPath,
                      *,
                      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 upath import UPath
              
                      path_obj = 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: StrPath, *, 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 StrPath

              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
              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
              @classmethod
              async def from_path(
                  cls,
                  path: StrPath,
                  *,
                  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 upath import UPath
              
                  path_obj = 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
              139
              140
              141
              142
              143
              144
              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
              class BasePDFContent(BaseContent):
                  """Base for PDF document content."""
              
                  detail: DetailLevel | None = None
                  """Detail level for document processing by models."""
              
                  def to_openai_format(self) -> dict[str, Any]:
                      """Convert to OpenAI API format for PDF handling."""
                      raise NotImplementedError
              
                  @classmethod
                  async def from_path(
                      cls,
                      path: StrPath,
                      *,
                      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 upath import UPath
              
                      path_obj = 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: StrPath, *, detail: DetailLevel | None = None, description: str | None = None
              ) -> PDFURLContent | PDFBase64Content
              

              Create PDF content from any path.

              Parameters:

              Name Type Description Default
              path StrPath

              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
              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
              @classmethod
              async def from_path(
                  cls,
                  path: StrPath,
                  *,
                  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 upath import UPath
              
                  path_obj = 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)
              

              to_openai_format

              to_openai_format() -> dict[str, Any]
              

              Convert to OpenAI API format for PDF handling.

              Source code in src/llmling_agent/models/content.py
              145
              146
              147
              def to_openai_format(self) -> dict[str, Any]:
                  """Convert to OpenAI API format for PDF handling."""
                  raise NotImplementedError
              

              ImageBase64Content

              Bases: BaseImageContent

              Image from base64 data.

              Source code in src/llmling_agent/models/content.py
               98
               99
              100
              101
              102
              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
              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."""
              
                  def to_openai_format(self) -> dict[str, Any]:
                      """Convert to OpenAI API format for vision models."""
                      data_url = f"data:image/jpeg;base64,{self.data}"
                      content = {"url": data_url, "detail": self.detail or "auto"}
                      return {"type": "image_url", "image_url": content}
              
                  @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.

              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
              113
              114
              115
              116
              117
              118
              119
              120
              121
              122
              123
              124
              125
              126
              127
              128
              129
              @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
              131
              132
              133
              134
              135
              136
              @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())
              

              to_openai_format

              to_openai_format() -> dict[str, Any]
              

              Convert to OpenAI API format for vision models.

              Source code in src/llmling_agent/models/content.py
              107
              108
              109
              110
              111
              def to_openai_format(self) -> dict[str, Any]:
                  """Convert to OpenAI API format for vision models."""
                  data_url = f"data:image/jpeg;base64,{self.data}"
                  content = {"url": data_url, "detail": self.detail or "auto"}
                  return {"type": "image_url", "image_url": content}
              

              ImageURLContent

              Bases: BaseImageContent

              Image from URL.

              Source code in src/llmling_agent/models/content.py
              83
              84
              85
              86
              87
              88
              89
              90
              91
              92
              93
              94
              95
              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_openai_format(self) -> dict[str, Any]:
                      """Convert to OpenAI API format for vision models."""
                      content = {"url": self.url, "detail": self.detail or "auto"}
                      return {"type": "image_url", "image_url": content}
              

              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.

              to_openai_format

              to_openai_format() -> dict[str, Any]
              

              Convert to OpenAI API format for vision models.

              Source code in src/llmling_agent/models/content.py
              92
              93
              94
              95
              def to_openai_format(self) -> dict[str, Any]:
                  """Convert to OpenAI API format for vision models."""
                  content = {"url": self.url, "detail": self.detail or "auto"}
                  return {"type": "image_url", "image_url": content}
              

              PDFBase64Content

              Bases: BasePDFContent

              PDF from base64 data.

              Source code in src/llmling_agent/models/content.py
              190
              191
              192
              193
              194
              195
              196
              197
              198
              199
              200
              201
              202
              203
              204
              205
              206
              207
              208
              209
              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)
              

              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
              199
              200
              201
              202
              203
              204
              205
              206
              207
              208
              209
              @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
              180
              181
              182
              183
              184
              185
              186
              187
              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."""
              

              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.