LoadedResource
Base classes
| Name |
Children |
Inherits |
Schema schemez.schema Base class for configuration models. |
|
|
⋔ Inheritance diagram
graph TD
742652763["models.LoadedResource"]
330168112["schema.Schema"]
3879467795["main.BaseModel"]
2751680898["builtins.object"]
330168112 --> 742652763
3879467795 --> 330168112
2751680898 --> 3879467795
🛈 DocStrings
Bases: Schema
Result of loading and processing a context.
Source code in src/llmling/resources/models.py
| class LoadedResource(Schema):
"""Result of loading and processing a context."""
content: str = "" # Keep for backward compatibility
content_items: list[MessageContent] = Field(default_factory=list)
source_type: str | None = None
metadata: ResourceMetadata
etag: str | None = None # For MCP caching support
@model_validator(mode="before")
@classmethod
def ensure_content_sync(cls, data: dict[str, Any]) -> dict[str, Any]:
"""Ensure content and content_items are in sync."""
if isinstance(data, dict):
content = data.get("content", "")
content_items = data.get("content_items", [])
# If we have content but no items, create a text item
if content and not content_items:
msg_content = MessageContent(type="text", content=content)
data["content_items"] = [msg_content.model_dump()]
# If we have items but no content, use first text item's content
elif content_items and not content:
text_items = [
i for i in content_items if isinstance(i, dict) and i.get("type") == "text"
]
if text_items:
data["content"] = text_items[0]["content"]
return data
|
ensure_content_sync
classmethod
ensure_content_sync(data: dict[str, Any]) -> dict[str, Any]
Ensure content and content_items are in sync.
Source code in src/llmling/resources/models.py
| @model_validator(mode="before")
@classmethod
def ensure_content_sync(cls, data: dict[str, Any]) -> dict[str, Any]:
"""Ensure content and content_items are in sync."""
if isinstance(data, dict):
content = data.get("content", "")
content_items = data.get("content_items", [])
# If we have content but no items, create a text item
if content and not content_items:
msg_content = MessageContent(type="text", content=content)
data["content_items"] = [msg_content.model_dump()]
# If we have items but no content, use first text item's content
elif content_items and not content:
text_items = [
i for i in content_items if isinstance(i, dict) and i.get("type") == "text"
]
if text_items:
data["content"] = text_items[0]["content"]
return data
|
:fa-brands-github: Show source on GitHub