Skip to content

Commit cf36dc5

Browse files
committed
Updates for 01.1
1 parent 3004f2a commit cf36dc5

File tree

6 files changed

+1193
-1345
lines changed

6 files changed

+1193
-1345
lines changed

interpreter/core/async_core.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(self, *args, **kwargs):
6060
self.server = Server(self)
6161

6262
# For the 01. This lets the OAI compatible server accumulate context before responding.
63-
self.context_mode = False
63+
self.context_mode = True
6464

6565
async def input(self, chunk):
6666
"""
@@ -737,6 +737,7 @@ async def openai_compatible_generator():
737737
for i, chunk in enumerate(
738738
async_interpreter.chat(message=message, stream=True, display=True)
739739
):
740+
await asyncio.sleep(0) # Yield control to the event loop
740741
made_chunk = True
741742

742743
if async_interpreter.stop_event.is_set():
@@ -832,6 +833,11 @@ async def chat_completion(request: ChatCompletionRequest):
832833
# Remove that {START} message that would have just been added
833834
async_interpreter.messages = async_interpreter.messages[:-1]
834835
last_start_time = time.time()
836+
if (
837+
async_interpreter.messages
838+
and async_interpreter.messages[-1].get("role") != "user"
839+
):
840+
return
835841
else:
836842
# Check if we're within 6 seconds of last_start_time
837843
current_time = time.time()

interpreter/core/computer/browser/browser.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import threading
12
import time
23

34
import html2text
@@ -34,6 +35,33 @@ def search(self, query):
3435
)
3536
return response.json()["result"]
3637

38+
def fast_search(self, query):
39+
"""
40+
Searches the web for the specified query and returns the results.
41+
"""
42+
43+
# Start the request in a separate thread
44+
response_thread = threading.Thread(
45+
target=lambda: setattr(
46+
threading.current_thread(),
47+
"response",
48+
requests.get(
49+
f'{self.computer.api_base.strip("/")}/browser/search',
50+
params={"query": query},
51+
),
52+
)
53+
)
54+
response_thread.start()
55+
56+
# Perform the Google search
57+
self.search_google(query, delays=False)
58+
59+
# Wait for the request to complete and get the result
60+
response_thread.join()
61+
response = response_thread.response
62+
63+
return response.json()["result"]
64+
3765
def setup(self):
3866
self.service = Service(ChromeDriverManager().install())
3967
self.options = webdriver.ChromeOptions()
@@ -42,9 +70,9 @@ def setup(self):
4270
def go_to_url(self, url):
4371
"""Navigate to a URL"""
4472
self.driver.get(url)
45-
time.sleep(3)
73+
time.sleep(1)
4674

47-
def search_google(self, query):
75+
def search_google(self, query, delays=True):
4876
"""Perform a Google search"""
4977
self.driver.get("https://www.perplexity.ai")
5078
# search_box = self.driver.find_element(By.NAME, 'q')
@@ -56,13 +84,16 @@ def search_google(self, query):
5684
active_element = self.driver.switch_to.active_element
5785
active_element.send_keys(query)
5886
active_element.send_keys(Keys.RETURN)
59-
time.sleep(5)
87+
if delays:
88+
time.sleep(3)
6089

6190
def analyze_page(self, intent):
6291
"""Extract HTML, list interactive elements, and analyze with AI"""
6392
html_content = self.driver.page_source
6493
text_content = html2text.html2text(html_content)
6594

95+
# text_content = text_content[:len(text_content)//2]
96+
6697
elements = (
6798
self.driver.find_elements(By.TAG_NAME, "a")
6899
+ self.driver.find_elements(By.TAG_NAME, "button")

interpreter/core/computer/skills/skills.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class Skills:
2424
def __init__(self, computer):
2525
self.computer = computer
2626
self.path = str(Path(oi_dir) / "skills")
27-
self.new_skill = NewSkill()
28-
self.new_skill.path = self.path
27+
self.new_skill = NewSkill(self)
2928

3029
def list(self):
3130
return [
@@ -97,8 +96,9 @@ def import_skills(self):
9796

9897

9998
class NewSkill:
100-
def __init__(self):
99+
def __init__(self, skills):
101100
self.path = ""
101+
self.skills = skills
102102

103103
def create(self):
104104
self.steps = []
@@ -180,18 +180,27 @@ def {normalized_name}(step=0):
180180
if step + 1 < len(steps):
181181
print("After completing the above, I need you to run {normalized_name}(step=" + str(step + 1) + ") immediatly.")
182182
else:
183-
print("You have completed all the steps, the task/skill has been run!")
183+
print("After executing the code, you have completed all the steps, the task/skill has been run!")
184184
else:
185185
print("The specified step number exceeds the available steps. Please run with a valid step number.")
186186
'''.strip()
187187

188-
if not os.path.exists(self.path):
189-
os.makedirs(self.path)
190-
with open(self.path + "/" + normalized_name + ".py", "w") as file:
188+
skill_file_path = os.path.join(self.skills.path, f"{normalized_name}.py")
189+
190+
if not os.path.exists(self.skills.path):
191+
os.makedirs(self.skills.path)
192+
193+
with open(skill_file_path, "w") as file:
191194
file.write(skill_string)
192195

193-
print("SKILL SAVED:", self.name.upper())
196+
# Execute the code in skill_string to define the function
197+
exec(skill_string)
194198

195-
print(
196-
"Teaching session finished. Tell the user that the skill above has been saved. Great work!"
197-
)
199+
# Verify that the file was written
200+
if os.path.exists(skill_file_path):
201+
print("SKILL SAVED:", self.name.upper())
202+
print(
203+
"Teaching session finished. Tell the user that the skill above has been saved. Great work!"
204+
)
205+
else:
206+
print(f"Error: Failed to write skill file to {skill_file_path}")

0 commit comments

Comments
 (0)