From d576a9103f246e73ce489bdabae68e88d19c82ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Donges?= <103573423+xmlhead@users.noreply.github.com> Date: Thu, 5 Jun 2025 02:26:42 +0200 Subject: [PATCH] Fix logging setup and minor typos --- chat.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/chat.py b/chat.py index f0fe56b..64e95a3 100644 --- a/chat.py +++ b/chat.py @@ -86,9 +86,9 @@ def load_config(configfilename): config = json.load(configfile) configfile.close() print(f"Loaded Configfile: {configfilename}.") - except IOError as e: - print(f"Error loading configfile: {e}") - exit + except IOError as e: + print(f"Error loading configfile: {e}") + exit() # read API KEY from ENV Variable if set print("OpenAI Chat Client, type !help for help.") @@ -99,9 +99,9 @@ def save_config(configfilename): json.dump(config, configfile, indent=2) configfile.close() print(f"Saved Configfile: {configfilename}.") - except IOError as e: - print(f"Error saving configfile: {e}") - exit + except IOError as e: + print(f"Error saving configfile: {e}") + exit() def main(): @@ -111,11 +111,12 @@ def main(): except: load_config("chat_config.json") - response=response_msg='' - context=[] + response=response_msg='' + context=[] ###LOGGING - log_filename = f'logs/chat-session-{datetime.now().strftime("%Y%m%d-%H%M")}.log' + os.makedirs('logs', exist_ok=True) + log_filename = f'logs/chat-session-{datetime.now().strftime("%Y%m%d-%H%M")}.log' logging.basicConfig( level=logging.INFO, # Set the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) format=u'%(asctime)s - %(message)s', @@ -188,7 +189,7 @@ def main(): print(f"Unknown command: {user_input}\n Type !help for help") else: response = send_payload(user_input) - repsonse_msg=process_response(response) + response_msg=process_response(response) if enable_logging: logging.info(f'User: {user_input}') logging.info(f'{config["model"]}:{response}')