SourceResourceLoader
Base classes
| Name |
Children |
Inherits |
ResourceLoader llmling.resources.base Base class for resource loaders. |
|
|
⋔ Inheritance diagram
graph TD
2297616779["source.SourceResourceLoader"]
2188557175["base.ResourceLoader"]
925645236["abc.ABC"]
2751680898["builtins.object"]
2180369605["protocols.CompletionProvider"]
1073422405["typing.Protocol"]
3481597255["typing.Generic"]
2188557175 --> 2297616779
925645236 --> 2188557175
2751680898 --> 925645236
2180369605 --> 2188557175
1073422405 --> 2180369605
3481597255 --> 1073422405
2751680898 --> 3481597255
3481597255 --> 2188557175
🛈 DocStrings
Bases: ResourceLoader[SourceResource]
Loads context from Python source code.
Source code in src/llmling/resources/loaders/source.py
| class SourceResourceLoader(ResourceLoader[SourceResource]):
"""Loads context from Python source code."""
context_class = SourceResource
uri_scheme = "python"
supported_mime_types: ClassVar[list[str]] = ["text/x-python"]
async def _load_impl(
self,
resource: SourceResource,
name: str,
processor_registry: ProcessorRegistry | None,
) -> AsyncIterator[LoadedResource]:
"""Load Python source content."""
try:
content = importing.get_module_source(
resource.import_path,
recursive=resource.recursive,
include_tests=resource.include_tests,
)
if processor_registry and (procs := resource.processors):
processed = await processor_registry.process(content, procs)
content = processed.content
meta = {"import_path": resource.import_path, "recursive": resource.recursive}
yield create_loaded_resource(
content=content,
source_type="source",
uri=self.create_uri(name=name),
mime_type="text/x-python",
name=resource.description or resource.import_path,
description=resource.description,
additional_metadata=meta,
)
except Exception as exc:
msg = f"Failed to load source from {resource.import_path}"
raise exceptions.LoaderError(msg) from exc
async def get_completions(
self,
current_value: str,
argument_name: str | None = None,
**options: Any,
) -> list[str]:
"""Get Python import path completions."""
try:
return [name for name in sys.modules if name.startswith(current_value or "")]
except Exception:
logger.exception("Import completion failed")
return []
|
get_completions
async
get_completions(current_value: str, argument_name: str | None = None, **options: Any) -> list[str]
Get Python import path completions.
Source code in src/llmling/resources/loaders/source.py
| async def get_completions(
self,
current_value: str,
argument_name: str | None = None,
**options: Any,
) -> list[str]:
"""Get Python import path completions."""
try:
return [name for name in sys.modules if name.startswith(current_value or "")]
except Exception:
logger.exception("Import completion failed")
return []
|
:fa-brands-github: Show source on GitHub