Skip to content

TextResourceLoader

Base classes

Name Children Inherits
ResourceLoader
llmling.resources.base
Base class for resource loaders.

⋔ Inheritance diagram

graph TD
  447311692["text.TextResourceLoader"]
  2188557175["base.ResourceLoader"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  2180369605["protocols.CompletionProvider"]
  1073422405["typing.Protocol"]
  3481597255["typing.Generic"]
  2188557175 --> 447311692
  925645236 --> 2188557175
  2751680898 --> 925645236
  2180369605 --> 2188557175
  1073422405 --> 2180369605
  3481597255 --> 1073422405
  2751680898 --> 3481597255
  3481597255 --> 2188557175

🛈 DocStrings

Bases: ResourceLoader[TextResource]

Loads context from raw text.

Source code in src/llmling/resources/loaders/text.py
class TextResourceLoader(ResourceLoader[TextResource]):
    """Loads context from raw text."""

    context_class = TextResource
    uri_scheme = "text"
    supported_mime_types: ClassVar[list[str]] = ["text/plain"]

    async def _load_impl(
        self,
        resource: TextResource,
        name: str,
        processor_registry: ProcessorRegistry | None,
    ) -> AsyncIterator[LoadedResource]:
        """Load text content."""
        try:
            content = resource.content
            if processor_registry and (procs := resource.processors):
                processed = await processor_registry.process(content, procs)
                content = processed.content

            yield create_loaded_resource(
                content=content,
                source_type="text",
                uri=self.create_uri(name=name),
                mime_type=self.supported_mime_types[0],
                name=resource.description or name,
                description=resource.description,
                additional_metadata={"type": "text"},
            )
        except Exception as exc:
            msg = f"Failed to load text content: {exc}"
            raise exceptions.LoaderError(msg) from exc

:fa-brands-github: Show source on GitHub