Skip to content

PDFBase64Content

Base classes

Name Children Inherits
BasePDFContent
llmling_agent.models.content
Base for PDF document content.

⋔ Inheritance diagram

graph TD
  94461877375200["content.PDFBase64Content"]
  94461877935216["content.BasePDFContent"]
  94461877390128["content.BaseContent"]
  94461844082608["main.BaseModel"]
  139711135027392["builtins.object"]
  94461877935216 --> 94461877375200
  94461877390128 --> 94461877935216
  94461844082608 --> 94461877390128
  139711135027392 --> 94461844082608

🛈 DocStrings

Bases: BasePDFContent

PDF from base64 data.

Source code in src/llmling_agent/models/content.py
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
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."""

    def to_openai_format(self) -> dict[str, Any]:
        """Convert to OpenAI API format for PDF handling."""
        data_url = f"data:application/pdf;base64,{self.data}"
        content = {"url": data_url, "detail": self.detail or "auto"}
        return {"type": "file", "file": content}

    @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
212
213
214
215
216
217
218
219
220
221
222
@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)

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
206
207
208
209
210
def to_openai_format(self) -> dict[str, Any]:
    """Convert to OpenAI API format for PDF handling."""
    data_url = f"data:application/pdf;base64,{self.data}"
    content = {"url": data_url, "detail": self.detail or "auto"}
    return {"type": "file", "file": content}

Show source on GitHub