Skip to content

Conversation

tianjing-li
Copy link
Collaborator

@tianjing-li tianjing-li commented Nov 29, 2024

Thanks @EugeneLightsOn for pointing out fix area

Right now if a chat stream fails after creating the initial Chatbot response message, it creates an empty chat in chat_history, which the chat model does not accept. This filters them out.

Ideally we go back and delete those previous messages, but I didn't want to introduce potentially janky logic.

AI Description

This PR introduces several changes to the chat functionality, enhancing the user experience and improving the backend logic.

Summary

The create_chat_history function in src/backend/services/chat.py now filters out the user's most recent message and any empty messages when generating chat history. This ensures that only relevant messages are included in the history, providing a more accurate context for the chat SDK call.

Additionally, a new function is_final_event is added to src/backend/chat/custom/custom.py, which appears to be related to event handling. However, the purpose of this function is not entirely clear from the provided code snippet.

Changes

  • src/backend/services/chat.py:
    • The create_chat_history function now filters out the user's most recent message and any empty messages.
  • src/backend/chat/custom/custom.py:
    • A new function is_final_event is introduced, which seems to be related to event handling.
  • src/backend/chat/custom/tool_calls.py:
    • A new function _call_tool_async is added, but its purpose is not evident from the provided code.

@codecov-commenter
Copy link

codecov-commenter commented Nov 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.01%. Comparing base (81a6f32) to head (f1f65d6).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #862   +/-   ##
=======================================
  Coverage   79.01%   79.01%           
=======================================
  Files         257      257           
  Lines       10975    10975           
=======================================
  Hits         8672     8672           
  Misses       2303     2303           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@EugeneLightsOn EugeneLightsOn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

@tianjing-li tianjing-li merged commit 8956b28 into main Dec 11, 2024
8 checks passed
@tianjing-li tianjing-li deleted the fix-errored-message branch December 11, 2024 17:58
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

Successfully merging this pull request may close these issues.

3 participants