GravityPhone / hatz

0 stars 0 forks source link

Sweep: implement logging #22

Open GravityPhone opened 6 months ago

GravityPhone commented 6 months ago

Details

using mostly assistant manager and main controller, implement basic logging of state changes. use popular simple libraries and standard methods but simplistic and low on code

Branch

No response

Checklist - [X] Modify `assistant_manager.py` ✓ https://github.com/GravityPhone/hatz/commit/64c1c39e7200f203a5469eec1a60e9d73d300d03 [Edit](https://github.com/GravityPhone/hatz/edit/sweep/implement_logging/assistant_manager.py) - [X] Running GitHub Actions for `assistant_manager.py` ✓ [Edit](https://github.com/GravityPhone/hatz/edit/sweep/implement_logging/assistant_manager.py) - [X] Modify `main_controller.py` ✓ https://github.com/GravityPhone/hatz/commit/dfda1f5c3388b7cf2b83e21aaedff8b493ab4da8 [Edit](https://github.com/GravityPhone/hatz/edit/sweep/implement_logging/main_controller.py) - [X] Running GitHub Actions for `main_controller.py` ✓ [Edit](https://github.com/GravityPhone/hatz/edit/sweep/implement_logging/main_controller.py)
sweep-ai[bot] commented 6 months ago

🚀 Here's the PR! #23

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: 8d25212f3b)

[!TIP] I can email you next time I complete a pull request if you set up your email here!


Actions (click)


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/GravityPhone/hatz/blob/185609eb64b8effecc5344441fc0fb8450c0d4e0/assistant_manager.py#L1-L75 https://github.com/GravityPhone/hatz/blob/185609eb64b8effecc5344441fc0fb8450c0d4e0/main_controller.py#L1-L94

Step 2: ⌨️ Coding

--- 
+++ 
@@ -2,6 +2,7 @@
 from openai import Assistant
 from typing_extensions import override
 import time
+import logging

 class EventHandler(Assistant):    
   @override
@@ -33,10 +34,10 @@
     def create_thread(self):
         try:
             thread = self.client.beta.threads.create()
-            print(f'Successfully created thread with ID: {thread.id}')
+            logging.info(f'Successfully created thread with ID: {thread.id}')
             return thread.id
         except Exception as e:
-            print(f"Failed to create a thread: {e}")
+            logging.info(f"Failed to create a thread: {e}")
             return None

     def add_message_to_thread(self, thread_id, message_content, role="user"):
@@ -46,10 +47,10 @@
                 role=role,
                 content=message_content
             )
-            print(f'Successfully added the message with ID: {message.id} to thread: {thread_id}')
+            logging.info(f'Successfully added the message with ID: {message.id} to thread: {thread_id}')
             return message.id
         except Exception as e:
-            print(f"Failed to add message to thread {thread_id}: {e}")
+            logging.info(f"Failed to add message to thread {thread_id}: {e}")
             return None

     def run_assistant(self, thread_id, assistant_id, instructions):
@@ -69,8 +70,8 @@
             # Assuming response.data contains the messages and taking the first one
             recent_message = response.data[0] if response.data else None
             if recent_message:
-                print(f'Retrieved the most recent message: {recent_message.id} from thread: {thread_id}')
+                logging.info(f'Retrieved the most recent message: {recent_message.id} from thread: {thread_id}')
             return recent_message
         except Exception as e:
-            print(f"Failed to retrieve the most recent message from thread {thread_id}: {e}")
+            logging.info(f"Failed to retrieve the most recent message from thread {thread_id}: {e}")
             return None

Ran GitHub Actions for 64c1c39e7200f203a5469eec1a60e9d73d300d03:

--- 
+++ 
@@ -1,5 +1,8 @@
 import os
 import time
+import logging
+
+logging.basicConfig(filename='main_controller.log', level=logging.INFO)
 from word_detector import setup_keyword_detection, set_message_handler
 from audio_recorder import start_recording, stop_recording
 from assemblyai_transcriber import AssemblyAITranscriber
@@ -22,7 +25,7 @@
 def handle_detected_words(words):
     global is_recording, picture_mode, last_thread_id, last_interaction_time
     detected_phrase = ' '.join(words).lower().strip()
-    print(f"Detected phrase: {detected_phrase}")
+    logging.info(f"Detected phrase: {detected_phrase}")

     if "computer" in detected_phrase and not is_recording:
         start_recording()
@@ -39,9 +42,9 @@

 def process_recording():
     global picture_mode, last_thread_id, last_interaction_time
-    print("Processing recorded audio...")
+    logging.info("Processing recorded audio...")
     transcription = assemblyai_transcriber.transcribe_audio_file("recorded_audio.wav")
-    print(f"Transcription result: '{transcription}'")
+    logging.info(f"Transcription result: '{transcription}'")

     if picture_mode:
         vision_module.capture_image_async()
@@ -58,15 +61,15 @@

 def interact_with_assistant(transcription):
     global last_thread_id, last_interaction_time
-    print(f"Initiating interaction with assistant with transcription: {transcription}")
+    logging.info(f"Initiating interaction with assistant with transcription: {transcription}")
     if not last_thread_id or time.time() - last_interaction_time > 90:
         last_thread_id = assistant_manager.create_thread()
-    print(f"Using thread ID: {last_thread_id} for the current interaction")
+    logging.info(f"Using thread ID: {last_thread_id} for the current interaction")

     last_interaction_time = time.time()

     message_id = assistant_manager.add_message_to_thread(last_thread_id, transcription)
-    print(f"Message added to the thread with ID: {message_id}")
+    logging.info(f"Message added to the thread with ID: {message_id}")
     # 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)
     print(f"Assistant run initiated with run ID: {run_id}")
@@ -85,7 +88,7 @@

 def initialize():
-    print("System initializing...")
+    logging.info("System initializing...")
     set_message_handler(handle_detected_words)
     setup_keyword_detection()

Ran GitHub Actions for dfda1f5c3388b7cf2b83e21aaedff8b493ab4da8:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/implement_logging.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 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.