Skip to content

Commit

Permalink
Improve update_chat_messages() rendering of chat messages
Browse files Browse the repository at this point in the history
  • Loading branch information
xhluca committed Oct 21, 2024
1 parent 9afc0e2 commit 3c08362
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/agentlab/analyze/agent_xray.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,28 @@ def update_chat_messages():
chat_messages = agent_info.get("chat_messages", ["No Chat Messages"])
messages = []
for i, m in enumerate(chat_messages):
msg_str = f"# Message {i}\n```\n{m}\n```\n\n"
# breakpoint()
if isinstance(m, BaseMessage): # TODO remove once langchain is deprecated
m = m.content
msg_str = f"# Message {i}\n```\n{m.content}\n```\n\n"
elif isinstance(m, dict):
m = m.get("content", "No Content")
messages.append(f"""# Message {i}\n```\n{m}\n```\n\n""")
content = m.get("content", "<No Content>")
role = m.get("role", "<Unknown>")
if isinstance(content, list):
content_str = ""
for part in content:
if isinstance(part, str):
content_str += part + "\n"

elif isinstance(part, dict) and part.get("type", None) == "text":
content_str += part.get("text", "<No Text>") + "\n"


content = content_str

msg_str = f"# Message {i} (role: {role})\n```\n{content}\n```\n\n"

messages.append(msg_str)
return "\n".join(messages)


Expand Down

0 comments on commit 3c08362

Please sign in to comment.