Skip to content

text

Class info

Classes

Name Children Inherits
TextResourceLoader
llmling.resources.loaders.text
Loads context from raw text.

    🛈 DocStrings

    Resource loader for text content.

    TextResourceLoader

    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