Only clean up chat log if it was stored (#137399)

This commit is contained in:
Paulus Schoutsen
2025-02-05 08:25:05 -05:00
committed by GitHub
parent eded99a059
commit 417a595b73

View File

@@ -43,13 +43,6 @@ def async_get_chat_log(
else:
history = ChatLog(hass, session.conversation_id)
@callback
def do_cleanup() -> None:
"""Handle cleanup."""
all_history.pop(session.conversation_id)
session.async_on_cleanup(do_cleanup)
if user_input is not None:
history.async_add_user_content(UserContent(content=user_input.text))
@@ -63,6 +56,15 @@ def async_get_chat_log(
)
return
if session.conversation_id not in all_history:
@callback
def do_cleanup() -> None:
"""Handle cleanup."""
all_history.pop(session.conversation_id)
session.async_on_cleanup(do_cleanup)
all_history[session.conversation_id] = history