Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions mellea/stdlib/components/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,7 @@ def format_for_llm(self) -> TemplateRepresentation:
"""
return TemplateRepresentation(
obj=self,
args={
"role": self.role,
"content": self._content_cblock,
"images": self._images,
"documents": self._docs,
},
args={"content": self._content_cblock, "documents": self._docs},
template_order=["*", "Message"],
)

Expand Down Expand Up @@ -219,21 +214,6 @@ def __init__(
self._tool_output = tool_output
self._tool = tool

def format_for_llm(self) -> TemplateRepresentation:
"""Return the same representation as ``Message`` with a ``name`` field added to the args dict.

Returns:
TemplateRepresentation: Template representation including the tool
name alongside the standard message fields.
"""
message_repr = super().format_for_llm()
args = message_repr.args
args["name"] = self.name

return TemplateRepresentation(
obj=self, args=args, template_order=["*", "Message"]
)

def __repr__(self) -> str:
"""Pretty representation of messages, because they are a special case."""
return f'mellea.ToolMessage(role="{self.role}", content="{self.content}", name="{self.name}")'
Expand Down
20 changes: 0 additions & 20 deletions test/stdlib/components/test_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def test_message_format_for_llm_structure():
msg = Message("user", "hello")
tr = msg.format_for_llm()
assert isinstance(tr, TemplateRepresentation)
assert tr.args["role"] == "user"
assert tr.args["content"] is msg._content_cblock
assert tr.args["images"] is None
assert tr.args["documents"] is None


Expand Down Expand Up @@ -212,24 +210,6 @@ def test_tool_message_fields():
assert tm.arguments == {"x": 1}


def test_tool_message_format_for_llm_includes_name():
from mellea.core import ModelToolCall

fake_tool = type("T", (), {"as_json_tool": {}})()
mtc = ModelToolCall("my_tool", fake_tool, {})
tm = ToolMessage(
role="tool",
content="output",
tool_output="output",
name="my_tool",
args={},
tool=mtc,
)
tr = tm.format_for_llm()
assert isinstance(tr, TemplateRepresentation)
assert tr.args["name"] == "my_tool"


def test_tool_message_repr():
from mellea.core import ModelToolCall

Expand Down
Loading