#Access chat_messages after chat

1 messages · Page 1 of 1 (latest)

young ingot
#

I have parsed the object returned by user.chat_messages after initiate_chat() returns - user is the user proxy agent that initiated the chat. All of the chat messages are available in the list after parsing but the roles are reversed.

6: {'content': 'exitcode: 0 (execution succeeded)\nCode output: \n', 'role': 'assistant'}


7: {'content': "Great!! The code executed successfully and the information about the recent papers has been saved to 'arxiv_recent_papers.txt'. You can open this file to view the details of these papers. If you want to run the script again, simply delete or rename the existing 'arxiv_recent_papers.txt' and then execute the code again.\nTERMINATE:\n", 'role': 'user'}

Is this by design and if so may I know why? Not an issue - easy to fix - just curious.

granite jolt
#

@young ingot I think it's by design, but maybe I'm missing your point. If you still have a questions, can you be more specific? Thx.

young ingot
#

#6 has 'role' as 'assistant' but this is a user message.
#7 has 'role' as 'user' but this is an assistant message.

All of the messages in the list with 'role': 'assistant' are 'user' messages and all of the messages in the list with 'role':'user' are 'assistant' messages.

The above output cam from this code:

    user.initiate_chat(assistant, message=arxiv, clear_history=False)
    messages = chat_messages_to_list(user.chat_messages)
    index = 0
    for message in messages:
        print(f"{index}: {message}\n\n")
        index += 1

If this is by design then I am very curious as to the reasoning for the design: not trying to change or challange anything, just very curious.

And:

def chat_messages_to_list(chat_messages)->List:
    extracted_messages = []
    for key in chat_messages:
        for message in chat_messages[key]:
            extracted_messages.append({'content': message['content'], 'role': message['role']})

    return extracted_messages
granite jolt
#

@young ingot What is the value of arxiv on the first line?

young ingot
# granite jolt <@1139264316353298532> What is the value of arxiv on the first line?

Sorry, I missed this earlier:

arxiv = """
Query arxiv for the 5 most recent papers on the topic of Retrieval Augmented Generation as it applies to LLM context. Ensure the papers have been published in the last 3 months. When we have the desired information, save the information to a text file. Start by getting the current date. The output should include:
    - publication date of the paper
    - title of the paper
    - brief summary of the paper
    - a clickable link to the pdf of the paper
"""
limpid belfry
#

@young ingot did you figure it out? I also found the reversed role issue interesting and confusing 😅