Skip to content

Commit 0b6b535

Browse files
authored
feat: make model representations LLM friendly (#119)
1 parent de3b82a commit 0b6b535

5 files changed

Lines changed: 46 additions & 5 deletions

File tree

src/deepset_mcp/api/indexes/models.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Any
33

44
from pydantic import BaseModel
5+
from rich.repr import Result
56

67
from deepset_mcp.api.shared_models import DeepsetUser
78

@@ -35,6 +36,24 @@ class Index(BaseModel):
3536
last_edited_by: DeepsetUser | None = None
3637
status: IndexStatus
3738

39+
def __rich_repr__(self) -> Result:
40+
"""Used to display the model in an LLM friendly way."""
41+
yield "name", self.name
42+
yield "description", self.description, None
43+
yield "desired_status", self.desired_status
44+
yield "status", self.status
45+
yield "status", self.status
46+
yield "created_by", f"{self.created_by.given_name} {self.created_by.family_name} ({self.created_by.id})"
47+
yield "created_at", self.created_at.strftime("%m/%d/%Y %I:%M:%S %p")
48+
yield (
49+
"last_edited_by",
50+
f"{self.last_edited_by.given_name} {self.last_edited_by.family_name} ({self.last_edited_by.id})"
51+
if self.last_edited_by
52+
else None,
53+
)
54+
yield "last_edited_at", self.last_edited_at.strftime("%m/%d/%Y %I:%M:%S %p") if self.last_edited_at else None
55+
yield "config_yaml", self.config_yaml if self.config_yaml is not None else "Get full index to see config."
56+
3857

3958
class IndexList(BaseModel):
4059
"""Response model for listing indexes."""

src/deepset_mcp/api/pipeline/models.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from uuid import UUID
55

66
from pydantic import BaseModel, Field, model_validator
7+
from rich.repr import Result
78

89
from deepset_mcp.api.shared_models import DeepsetUser
910

@@ -41,6 +42,22 @@ class Config:
4142
datetime: lambda dt: dt.isoformat()
4243
}
4344

45+
def __rich_repr__(self) -> Result:
46+
"""Used to display the model in an LLM friendly way."""
47+
yield "name", self.name
48+
yield "service_level", self.service_level.value
49+
yield "status", self.status
50+
yield "created_by", f"{self.created_by.given_name} {self.created_by.family_name} ({self.created_by.id})"
51+
yield "created_at", self.created_at.strftime("%m/%d/%Y %I:%M:%S %p")
52+
yield (
53+
"last_updated_by",
54+
f"{self.last_updated_by.given_name} {self.last_updated_by.family_name} ({self.last_updated_by.id})"
55+
if self.last_updated_by
56+
else None,
57+
)
58+
yield "last_updated_at", self.last_updated_at.strftime("%m/%d/%Y %I:%M:%S %p") if self.last_updated_at else None
59+
yield "yaml_config", self.yaml_config if self.yaml_config is not None else "Get full pipeline to see config."
60+
4461

4562
class ValidationError(BaseModel):
4663
"""Model representing a validation error from the pipeline validation API."""
@@ -55,6 +72,11 @@ class PipelineValidationResult(BaseModel):
5572
valid: bool
5673
errors: list[ValidationError] = []
5774

75+
def __rich_repr__(self) -> Result:
76+
"""Used to display the model in an LLM friendly way."""
77+
yield "valid", self.valid
78+
yield "errors", [f"{e.message} ({e.code})" for e in self.errors]
79+
5880

5981
class TraceFrame(BaseModel):
6082
"""Model representing a single frame in a stack trace."""

src/deepset_mcp/tool_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def get_slice_from_object_store(
8080
8181
:param object_id: Identifier of the object.
8282
:param start: Start index for slicing.
83-
:param end: End index for slicing (None for end of sequence).
83+
:param end: End index for slicing (optional - leave empty to get slice from start to end of sequence).
8484
:param path: Navigation path to object to slice (optional).
8585
:return: String representation of the slice.
8686
"""

src/deepset_mcp/tools/tokonomics/explorer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class RichExplorer:
3232
def __init__(
3333
self,
3434
store: ObjectStore,
35-
max_items: int = 20,
35+
max_items: int = 25,
3636
max_string_length: int = 300,
37-
max_depth: int = 3,
37+
max_depth: int = 4,
3838
max_search_matches: int = 10,
3939
search_context_length: int = 150,
4040
) -> None:

test/unit/tools/tokonomics/test_explorer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def test_init_default_params(self, store: ObjectStore) -> None:
2323
explorer = RichExplorer(store)
2424

2525
assert explorer.store is store
26-
assert explorer.max_items == 20
26+
assert explorer.max_items == 25
2727
assert explorer.max_string_length == 300
28-
assert explorer.max_depth == 3
28+
assert explorer.max_depth == 4
2929
assert explorer.max_search_matches == 10
3030
assert explorer.search_context_length == 150
3131
assert explorer.console.options.is_terminal is False

0 commit comments

Comments
 (0)