Closed GravityPhone closed 6 months ago
01ff9a5bbf
)[!TIP] I can email you next time I complete a pull request if you set up your email here!
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
src/logging_module.py
✓ https://github.com/GravityPhone/Hats/commit/6e2128a5e53686f05a6452f703b3389360204af6 Edit
Create src/logging_module.py with contents:
• Create a new Python file named logging_module.py in the src directory.
• Import the os and datetime modules at the top of the file.
• Define a function named create_log_file that creates a new log file in the same directory as the scripts. This function should use the os module to get the current directory and create a new file with a unique name based on the current timestamp.
• Define a function named write_log that takes a message as an argument and writes it to the log file. This function should include the current timestamp in the log message and handle any errors that occur during the writing process.
• Define a function named log_error that takes an error message as an argument and writes it to the log file. This function should include the current timestamp and the word "ERROR" in the log message.
src/logging_module.py
✓ Edit
Check src/logging_module.py with contents:
Ran GitHub Actions for 6e2128a5e53686f05a6452f703b3389360204af6:
main_controller.py
✓ https://github.com/GravityPhone/Hats/commit/1e00e2015a585996bf4b444a35959266156a9bc5 Edit
Modify main_controller.py with contents:
• Import the logging_module at the top of the file.
• Add calls to logging_module.create_log_file at the start of the initialize function.
• Add calls to logging_module.write_log at the start and end of each function, and whenever a message is printed to the console. The log messages should include the name of the function and any relevant information.
• Add calls to logging_module.log_error whenever an error occurs. The error messages should include the name of the function and a description of the error.
--- +++ @@ -1,4 +1,5 @@ import os +import logging_module import time from word_detector import setup_keyword_detection, set_message_handler from audio_recorder import start_recording, stop_recording @@ -20,7 +21,8 @@ last_interaction_time = None def handle_detected_words(words): - global is_recording, picture_mode, last_thread_id, last_interaction_time + global is_recording, picture_mode, last_thread_id, last_interaction_time, log_file_path + logging_module.write_log('handle_detected_words function started.', log_file_path) detected_phrase = ' '.join(words).lower().strip() print(f"Detected phrase: {detected_phrase}") @@ -36,11 +38,13 @@ is_recording = False print("Recording stopped. Processing...") process_recording() + logging_module.write_log('handle_detected_words function ended.', log_file_path) def process_recording(): - global picture_mode, last_thread_id, last_interaction_time + global picture_mode, last_thread_id, last_interaction_time, log_file_path + logging_module.write_log('process_recording function started.', log_file_path) transcription = assemblyai_transcriber.transcribe_audio_file("recorded_audio.wav") - print(f"Transcription result: '{transcription}'") + logging_module.write_log(f"Transcription result: '{transcription}'", log_file_path) if picture_mode: vision_module.capture_image_async() @@ -56,16 +60,18 @@ def interact_with_assistant(transcription): - global last_thread_id, last_interaction_time + global last_thread_id, last_interaction_time, log_file_path + logging_module.write_log('interact_with_assistant function started.', log_file_path) if not last_thread_id or time.time() - last_interaction_time > 90: last_thread_id = assistant_manager.create_thread() last_interaction_time = time.time() message_id = assistant_manager.add_message_to_thread(last_thread_id, transcription) - print(f"Message added with ID: {message_id}") + logging_module.write_log(f"Message added with ID: {message_id}", log_file_path) # Initiate a run on the thread for the assistant to process the message run_id = assistant_manager.run_assistant(last_thread_id, assistant_id="asst_3D8tACoidstqhbw5JE2Et2st", instructions=transcription) + logging_module.write_log(f"Assistant run initiated with ID: {run_id}", log_file_path) print(f"Assistant run initiated with ID: {run_id}") # Check if the run is completed and retrieve the processed response @@ -82,6 +88,8 @@ def initialize(): + log_file_path = logging_module.create_log_file() + logging_module.write_log('initialize function started.', log_file_path) print("System initializing...") set_message_handler(handle_detected_words) setup_keyword_detection()
main_controller.py
✓ Edit
Check main_controller.py with contents:
Ran GitHub Actions for 1e00e2015a585996bf4b444a35959266156a9bc5:
I have finished reviewing the code for completeness. I did not find errors for sweep/write_logging_code
.
💡 To recreate the pull request edit the issue title or description. Something wrong? Let us know.
This is an automated message generated by Sweep AI.
Details
write code so save a very detailed log to the same dir as the scripts
Branch
No response
Checklist
- [X] Create `src/logging_module.py` ✓ https://github.com/GravityPhone/Hats/commit/6e2128a5e53686f05a6452f703b3389360204af6 [Edit](https://github.com/GravityPhone/Hats/edit/sweep/write_logging_code/src/logging_module.py) - [X] Running GitHub Actions for `src/logging_module.py` ✓ [Edit](https://github.com/GravityPhone/Hats/edit/sweep/write_logging_code/src/logging_module.py) - [X] Modify `main_controller.py` ✓ https://github.com/GravityPhone/Hats/commit/1e00e2015a585996bf4b444a35959266156a9bc5 [Edit](https://github.com/GravityPhone/Hats/edit/sweep/write_logging_code/main_controller.py) - [X] Running GitHub Actions for `main_controller.py` ✓ [Edit](https://github.com/GravityPhone/Hats/edit/sweep/write_logging_code/main_controller.py)