Skip to content

TextResource

Base classes

Name Children Inherits
BaseResource
llmling.config.models
Base class for all resource types.

⋔ Inheritance diagram

graph TD
  770213009["models.TextResource"]
  1028592330["models.BaseResource"]
  330168112["schema.Schema"]
  3879467795["main.BaseModel"]
  2751680898["builtins.object"]
  1028592330 --> 770213009
  330168112 --> 1028592330
  3879467795 --> 330168112
  2751680898 --> 3879467795

🛈 DocStrings

Bases: BaseResource

Raw text resource.

Source code in src/llmling/config/models.py
class TextResource(BaseResource):
    """Raw text resource."""

    type: Literal["text"] = Field(default="text", init=False)
    """Discriminator field identifying this as a text-based resource."""

    content: str
    """The actual text content of the resource."""

    _mime_type: str | None = None  # Optional override

    @model_validator(mode="after")
    def validate_content(self) -> TextResource:
        """Validate that the content is not empty."""
        if not self.content:
            msg = "Content cannot be empty"
            raise ValueError(msg)
        return self

    @property
    def mime_type(self) -> str:
        """Get MIME type, trying to detect JSON/YAML."""
        if self._mime_type:
            return self._mime_type
        # Could add content inspection here
        return "text/plain"

content instance-attribute

content: str

The actual text content of the resource.

mime_type property

mime_type: str

Get MIME type, trying to detect JSON/YAML.

type class-attribute instance-attribute

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

Discriminator field identifying this as a text-based resource.

validate_content

validate_content() -> TextResource

Validate that the content is not empty.

Source code in src/llmling/config/models.py
@model_validator(mode="after")
def validate_content(self) -> TextResource:
    """Validate that the content is not empty."""
    if not self.content:
        msg = "Content cannot be empty"
        raise ValueError(msg)
    return self

:fa-brands-github: Show source on GitHub