OpenAI-Assistants-Template
OpenAI-Assistants-Template copied to clipboard
update chat history retrieval
Pull Request: Complete Chat History Retrieval Fix
Background
The initial implementation of the chat history retrieval functionality within the Jupyter notebook environment had a limitation that prevented it from displaying the full chat archive, particularly for extensive chat histories. It was observed that the chat messages were being truncated to a certain point, thereby not providing the complete historical record of conversations.
Issue
Upon investigation, the underlying cause of the issue was identified as the method used to retrieve chat messages. The get_messages_in_chat
function's result was being directly manipulated without handling the potential for non-list iterable types.
Proposed Solution
This commit overhauls the chat history retrieval logic to ensure:
- All messages are fetched from the chat thread, including those from extensive archives.
- Proper reversal of messages for chronological display without causing
TypeError
.
Code Changes
The specific changes made are as follows:
- [x] Modified the message retrieval logic to handle the
SyncCursorPage[ThreadMessage]
object type, which includes using thelist()
constructor to allow for subsequent list operations, such as reversing. - [x] Implemented a consistent message reversal process, using slicing, to display messages in the correct chronological order, with the oldest message appearing first.
Result
These changes result in the complete chat history being fetched and displayed correctly, resolving the issue of truncated messages. Both extensive and short chat histories are now fully retrievable and viewable in the expected order.
the display() and Markdown() functions produce an error when opening this notebook on VSCode. Please review your code.
Error: File ~/Desktop/AssistantGPT/utils/modules.py:63, in display_chat_messages(messages) 59 formatted_message = f"{role}: {content}" 61 if role == "USER": 62 # Display user messages in markdown cells (add formatting if required) ---> 63 display(Markdown(f"{formatted_message}")) 64 else: 65 # Display assistant messages in markdown cells (add formatting if required) 66 display(Markdown(f"{formatted_message}"))
NameError: name 'Markdown' is not defined
Do you see a debugger warning in Jupyter console? It appears that the difficulties with importing IPython.display
and related errors are a result of the frozen modules
issue. This sometimes leads to import failures in venv.
Running Python with the -Xfrozen_modules=off
flag resolves the import issues. However, this is more of a workaround than a permanent solution. Ideas on how to solve that are welcome.
I'm a little late to the party, but I noticed you all aren't using a notebook review tool and wanted to invite you to review this pull request with GitNotebooks: https://gitnotebooks.com/pranavgupta2603/OpenAI-Assistants-Template/pull/1
It lets you do things like comment on rendered markdown and code cells, so might be an easy win for your PR reviews.