Skip to content

Commit 3219ab0

Browse files
committed
feat(message): add format_message method to Message class
1 parent fd809f7 commit 3219ab0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

flowllm/core/schema/message.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,38 @@ def simple_dump(self, add_reasoning: bool = True) -> dict:
9595

9696
return result
9797

98+
def format_message(
99+
self,
100+
i: int | None = None,
101+
add_time_created: bool = False,
102+
use_name_first: bool = False,
103+
add_reasoning_content: bool = True,
104+
add_tool_calls: bool = True
105+
) -> str:
106+
content = ""
107+
if i is not None:
108+
content += f"round{i} "
109+
110+
if add_time_created:
111+
content += f"[{self.time_created}] "
112+
113+
if use_name_first:
114+
content += f"{self.name or self.role.value}:\n"
115+
else:
116+
content += f"{self.role.value}:\n"
117+
118+
if add_reasoning_content and self.reasoning_content:
119+
content += self.reasoning_content + "\n"
120+
121+
if self.content:
122+
content += self.content + "\n"
123+
124+
if add_tool_calls and self.tool_calls:
125+
for tool_call in self.tool_calls:
126+
content += f" - tool_call={tool_call.name} params={tool_call.arguments}\n"
127+
128+
return content.strip()
129+
98130

99131
class Trajectory(BaseModel):
100132
"""Represents a conversation trajectory with messages and optional scoring."""

0 commit comments

Comments
 (0)