79439152

Date: 2025-02-14 11:09:57
Score: 0.5
Natty:
Report link

When working with autogen.ChatResult, the response object contains multiple attributes, and the actual chat history is stored in a dictionary format. To extract and display relevant information, follow these steps:

You need to access the dict attribute to convert the response into a dictionary and then extract the chat history.

def extract_chat_response(response):

# Convert response to dictionary
response_dict = response.__dict__

# Extract chat history
chat_history = response_dict.get("output", {}).get("chat_history", [])

# Display the assistant's response
if len(chat_history) > 1:
    st.chat_message("assistant").write(chat_history[1]["content"])

# Iterate through chat history and display responses until "TERMINATE" is found
for i in range(2, len(chat_history)):
    if "TERMINATE" not in chat_history[i]["content"]:
        st.chat_message("assistant").write(chat_history[i]["content"])
    else:
        break  # Stop iterating if "TERMINATE" is found
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): When
  • Low reputation (1):
Posted by: Thomas James