From b7d9e75eb9f3763a7e67859fdca495c65fc83329 Mon Sep 17 00:00:00 2001 From: if Date: Mon, 13 Mar 2023 17:56:55 +0300 Subject: [PATCH] fix err handler --- chat.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/chat.py b/chat.py index 3bb5067..783cf90 100644 --- a/chat.py +++ b/chat.py @@ -56,14 +56,14 @@ def main() -> None: ] try: completion = send_ai_request(model, st.session_state["messages"]) - except OpenAIError as err: + ai_content = completion.get("choices")[0].get("message").get("content") + st.session_state["messages"].append({"role": "assistant", "content": ai_content}) + if ai_content: + show_conversation(ai_content, user_content) + st.markdown("---") + show_player(ai_content) + except (OpenAIError, UnboundLocalError) as err: st.error(err) - ai_content = completion.get("choices")[0].get("message").get("content") - st.session_state["messages"].append({"role": "assistant", "content": ai_content}) - if ai_content: - show_conversation(ai_content, user_content) - st.markdown("---") - show_player(ai_content) if __name__ == "__main__":