Replies: 1 comment 2 replies
-
Hey @byrocuy! I'm here to help you with any bugs, questions, or contributions. Let's tackle this together! Your implementation of You can modify your implementation to include explicit connection closing. Here is an example: def save_to_history(message, response, config):
user_id = config.get("configurable").get("user_id")
chat_history = SQLChatMessageHistory(session_id=user_id, connection_string=MYSQL_CONN_STRING, table_name="message_store")
try:
chat_history.add_messages(
[
HumanMessage(content=message),
AIMessage(content=response)
]
)
finally:
chat_history.session_maker.remove() # Explicitly close the session This ensures that the session is properly closed after the messages are added [1][2]. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I am trying to use
SQLChatMessageHistory()
in chatbot to store user message and AI response. The mechanisms is pretty simple, I just add them usingadd_messages()
. What I want to ask is, is my implementation is enough? Shouldn't I have to close the connection? But I don't see any implementation in theSQLChatMessageHistory
module.Thanks
System Info
pip freeze | grep langchain:
platform: windows using WSL
python version: 3.9
Beta Was this translation helpful? Give feedback.
All reactions