-
Notifications
You must be signed in to change notification settings - Fork 72
How to use PostgresChatMessageHistory
with async connections when using RunnableWithMessageHistory
?
#122
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
Comments
Read the TU here |
Thanks, @pprados However, it's still unclear to me how to properly use RunnableWithMessageHistory. Even after reviewing the examples in the unit tests, I encountered the exact same error mentioned earlier (see the code below). Based on the error message, I believe the issue is that RunnableWithMessageHistory expects a function that returns an instance of BaseChatMessageHistory for a given session_id. The last few lines of the error indicate that the instance is being created with:
However, since hist is not awaited, its value remains a coroutine, which doesn't have the attribute aget_messages, as the error suggests. Here's a new approach, yet failing, based on the unit tests:
Let me know if there's something I'm still missing or if any adjustments are needed. Thanks! |
thank you for this analysis. Can you suggest a PR? |
@lgabs Any luck solving this issue? |
I found a workaround to for that problem, but before preparing a PR, I'll share the idea for discussion. I've made some changes to the async methods of PostgresChatMessageHistory to open an async connection when the class instance does not have the async conn created in its instantiation, using a new attribute conn_str. While this works, it opens a new connection every time, making it bad for connection reusage. What do you think? Here it is the full code:
|
I'm attempting to implement an asynchronous approach using PostgresChatMessageHistory in combination with RunnableWithMessageHistory, but I'm encountering some challenges. While PostgresChatMessageHistory appears to support asynchronous connections with async methods, I haven't found clear guidance on how to properly use them. Additionally, I couldn't locate any relevant documentation addressing this use case.
Any ideas on how to resolve this problem?
Here the a sample code I'm using and the traceback error:
Traceback error:
The error indicates that 'coroutine' object has no attribute 'aget_messages', which suggests the asynchronous method handling might not be correctly invoked.
The text was updated successfully, but these errors were encountered: