GravityPhone / hatz

0 stars 0 forks source link

sweep: remove check run status from assistant manager #10

Closed GravityPhone closed 3 months ago

GravityPhone commented 3 months ago

we wanna remove the check run status methods and functions and use this new paradigm, refer to our docs,

Once all the user Messages have been added to the Thread, you can Run the Thread with any Assistant. Creating a Run uses the model and tools associated with the Assistant to generate a response. These responses are added to the Thread as assistant Messages.

You can use the 'create and stream' helpers in the Python SDK to create a run and stream the response.

from typing_extensions import override from openai import AssistantEventHandler

First, we create a EventHandler class to define

how we want to handle the events in the response stream.

class EventHandler(AssistantEventHandler):
@override def on_text_created(self, text) -> None: print(f"\nassistant > ", end="", flush=True)

@override def on_text_delta(self, delta, snapshot): print(delta.value, end="", flush=True)

def on_tool_call_created(self, tool_call): print(f"\nassistant > {tool_call.type}\n", flush=True)

def on_tool_call_delta(self, delta, snapshot): if delta.type == 'code_interpreter': if delta.code_interpreter.input: print(delta.code_interpreter.input, end="", flush=True) if delta.code_interpreter.outputs: print(f"\n\noutput >", flush=True) for output in delta.code_interpreter.outputs: if output.type == "logs": print(f"\n{output.logs}", flush=True)

Then, we use the create_and_stream SDK helper

with the EventHandler class to create the Run

and stream the response.

with client.beta.threads.runs.create_and_stream( thread_id=thread.id, assistant_id=assistant.id, instructions="Please address the user as Jane Doe. The user has a premium account.", event_handler=EventHandler(), ) as stream: stream.until_done()

Checklist - [X] Modify `assistant_manager.py` ✓ https://github.com/GravityPhone/hatz/commit/c3d14fc16a3145619f20024ef269212f63d79c2d [Edit](https://github.com/GravityPhone/hatz/edit/sweep/remove_check_run_status_from_assistant_m/assistant_manager.py) - [X] Running GitHub Actions for `assistant_manager.py` ✓ [Edit](https://github.com/GravityPhone/hatz/edit/sweep/remove_check_run_status_from_assistant_m/assistant_manager.py) - [X] Modify `assistant_manager.py` ✓ https://github.com/GravityPhone/hatz/commit/273913beff2ca6d61a951df8cf6e14c877c1dd39 [Edit](https://github.com/GravityPhone/hatz/edit/sweep/remove_check_run_status_from_assistant_m/assistant_manager.py) - [X] Running GitHub Actions for `assistant_manager.py` ✓ [Edit](https://github.com/GravityPhone/hatz/edit/sweep/remove_check_run_status_from_assistant_m/assistant_manager.py)
sweep-ai[bot] commented 3 months ago

🚀 Here's the PR! #11

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

[!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/e0d412df8667050d78d1d5811193f67d4255ad03/assistant_manager.py#L1-L58

Step 2: ⌨️ Coding

--- 
+++ 
@@ -1,6 +1,29 @@
 import openai
+from openai import AssistantEventHandler
 from typing_extensions import override
 import time
+
+class EventHandler(AssistantEventHandler):    
+  @override
+  def on_text_created(self, text) -> None:
+    print(f"\nassistant > ", end="", flush=True)
+      
+  @override
+  def on_text_delta(self, delta, snapshot):
+    print(delta.value, end="", flush=True)
+      
+  def on_tool_call_created(self, tool_call):
+    print(f"\nassistant > {tool_call.type}\n", flush=True)
+  
+  def on_tool_call_delta(self, delta, snapshot):
+    if delta.type == 'code_interpreter':
+      if delta.code_interpreter.input:
+        print(delta.code_interpreter.input, end="", flush=True)
+      if delta.code_interpreter.outputs:
+        print(f"\n\noutput >", flush=True)
+        for output in delta.code_interpreter.outputs:
+          if output.type == "logs":
+            print(f"\n{output.logs}", flush=True)

 class AssistantManager:
     def __init__(self, openai_api_key):

Ran GitHub Actions for c3d14fc16a3145619f20024ef269212f63d79c2d:

--- 
+++ 
@@ -1,6 +1,29 @@
 import openai
+from openai import AssistantEventHandler
 from typing_extensions import override
 import time
+
+class EventHandler(AssistantEventHandler):    
+  @override
+  def on_text_created(self, text) -> None:
+    print(f"\nassistant > ", end="", flush=True)
+      
+  @override
+  def on_text_delta(self, delta, snapshot):
+    print(delta.value, end="", flush=True)
+      
+  def on_tool_call_created(self, tool_call):
+    print(f"\nassistant > {tool_call.type}\n", flush=True)
+  
+  def on_tool_call_delta(self, delta, snapshot):
+    if delta.type == 'code_interpreter':
+      if delta.code_interpreter.input:
+        print(delta.code_interpreter.input, end="", flush=True)
+      if delta.code_interpreter.outputs:
+        print(f"\n\noutput >", flush=True)
+        for output in delta.code_interpreter.outputs:
+          if output.type == "logs":
+            print(f"\n{output.logs}", flush=True)

 class AssistantManager:
     def __init__(self, openai_api_key):
@@ -30,19 +53,13 @@
             return None

     def run_assistant(self, thread_id, assistant_id, instructions):
-      try:
-          with self.client.beta.threads.runs.create_and_stream(
-              thread_id=thread_id,
-              assistant_id=assistant_id,
-              instructions=instructions,
-              event_handler=EventHandler(),
-          ) as stream:
-              stream.until_done()
-          print(f'Successfully started the assistant on thread: {thread_id}')
-          return True
-      except Exception as e:
-          print(f"Failed to run assistant on thread {thread_id}: {e}")
-          return False
+        with self.client.beta.threads.runs.create_and_stream(
+            thread_id=thread_id,
+            assistant_id=assistant_id,
+            instructions=instructions,
+            event_handler=EventHandler(),
+        ) as stream:
+            stream.until_done()

Ran GitHub Actions for 273913beff2ca6d61a951df8cf6e14c877c1dd39:


Step 3: 🔁 Code Review

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


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