Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'save_output_to_file = True' does not save the FULL chat history?? #1100

Open
SamuelDevdas opened this issue Aug 16, 2024 · 2 comments
Open

Comments

@SamuelDevdas
Copy link

Title: 'save_output_to_file = True' does not save the FULL chat history?

SCREENSHOTS

encodin-error2
save-history-file-issue
Description:

I'm encountering an issue where the save_output_to_file = True option does not seem to save the full chat history as expected.

Steps to Reproduce:

  1. Set the save_output_to_file parameter in the assistant configuration as follows:
    save_output_to_file="chat_history.md"

Note: disregard the timestamp fstring in the image attached, that is just to keep track of files

  1. Run the assistant and engage in multiple interactions.

Expected Behavior:

The full chat history should be saved to the specified file, capturing all interactions from start to finish.

Actual Behavior:

Only the assistants latest reply is saved, and previous interactions (including user message) seem to be missing from the file.

Configuration Details:

  • add_chat_history_to_prompt=True
  • num_history_messages=10

Attached are screenshots of the issue:

  1. The setup of the assistant configuration.
  2. The title of the issue that illustrates the problem.

Please let me know if additional details are needed or if there's a workaround for this issue.

SamuelDevdas added a commit to SamuelDevdas/phidata that referenced this issue Aug 16, 2024
…save the FULL chat history??


### **Title**: Fix for Incomplete Chat History Saving and UTF-8 Encoding Errors

### **Description**:

This pull request addresses two key issues in the current implementation:

1. **Incomplete Chat History Saving**:
   - The existing functionality for saving chat history to a file (`save_output_to_file`) does not capture the full chat history. The chat history was being saved partially, which led to incomplete records in the output file.
   - **Solution**: I modified the code to ensure that the complete chat history is captured and saved in the output file. This was achieved by adjusting how the `get_formatted_chat_history` method is called and handled within the file-saving routine.

2. **UTF-8 Encoding Error**:
   - There was a persistent `charmap` codec error that prevented the chat history from being saved, especially when the history contained special characters or emojis.
   - **Solution**: I changed the encoding method to `UTF-8` in the `write_text` method to handle all characters, including emojis and other special characters. This prevents the `charmap` codec error and ensures that all text is saved correctly without data loss or corruption.

### **Changes Made**:
- **File Saving Logic**: 
  - Adjusted the saving logic to properly handle and append the full chat history.
  - Ensured that the history file captures all user-assistant interactions.
  
- **Encoding Fix**:
  - Switched to `UTF-8` encoding for file operations, which resolves the issues related to saving text with special characters or emojis.
  - This change was necessary to prevent the `charmap` codec error from interrupting the saving process.



### **Testing**:
- The fix was manually tested in various scenarios, including interactions with special characters and emojis. The chat history was fully captured and saved without any errors.

### **Impact**:
- This fix ensures that users can rely on the `save_output_to_file` feature to capture the entire chat history.
- It also enhances the robustness of the application by handling diverse character sets without encountering encoding issues.

### **References**:
- The initial problem was identified during normal use when saving chat history resulted in partial content. 
- The encoding issue was encountered when interacting with text containing special characters.

### **Request**:
I kindly request a review of these changes and consider merging them into the main branch. The fixes are crucial for users who depend on the full and accurate recording of chat history.

Thank you for considering this contribution!
@ysolanky
Copy link
Contributor

Hello @SamuelDevdas!

Thanks for your contribution! The save_output_to_file flag is indeed intended to save the last message from the Assistant. However, I see the value in introducing a new parameter, save_chat_to_file, that would save the entire conversation. This would be a great addition to the functionality.

Would you be interested in working on this and creating a new PR? Let me know if you'd like to take this on!

@SamuelDevdas
Copy link
Author

Sure, makes sense. I can add the new input param as suggested and update my pull request.

Could you please review the pull request #1101 and let me know if that works for you? , then I can add the new input parameter as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants