Skip to content

Commit 0ec3a9f

Browse files
committed
done coding, tests still dont pass
1 parent cbb044e commit 0ec3a9f

File tree

5 files changed

+91
-18
lines changed

5 files changed

+91
-18
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,7 @@ misc/
236236
# Ignore litellm_uuid.txt
237237
litellm_uuid.txt
238238
.aider*
239+
file.txt
240+
numbers.txt
241+
poetry.lock
242+
poetry.lock

interpreter/core/computer/computer.py

+54-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import inspect
23

34
from .ai.ai import Ai
45
from .browser.browser import Browser
@@ -57,24 +58,14 @@ def __init__(self, interpreter):
5758
self.interpreter.max_output
5859
) # Should mirror interpreter.max_output
5960

60-
self.system_message = """
61+
self.system_message = f"""
6162
6263
# THE COMPUTER API
6364
6465
A python `computer` module is ALREADY IMPORTED, and can be used for many tasks:
6566
6667
```python
67-
computer.browser.search(query) # Google search results will be returned from this function as a string
68-
computer.files.edit(path_to_file, original_text, replacement_text) # Edit a file
69-
computer.calendar.create_event(title="Meeting", start_date=datetime.datetime.now(), end_date=datetime.datetime.now() + datetime.timedelta(hours=1), notes="Note", location="") # Creates a calendar event
70-
computer.calendar.get_events(start_date=datetime.date.today(), end_date=None) # Get events between dates. If end_date is None, only gets events for start_date
71-
computer.calendar.delete_event(event_title="Meeting", start_date=datetime.datetime) # Delete a specific event with a matching title and start date, you may need to get use get_events() to find the specific event object first
72-
computer.contacts.get_phone_number("John Doe")
73-
computer.contacts.get_email_address("John Doe")
74-
computer.mail.send("[email protected]", "Meeting Reminder", "Reminder that our meeting is at 3pm today.", ["path/to/attachment.pdf", "path/to/attachment2.pdf"]) # Send an email with a optional attachments
75-
computer.mail.get(4, unread=True) # Returns the [number] of unread emails, or all emails if False is passed
76-
computer.mail.unread_count() # Returns the number of unread emails
77-
computer.sms.send("555-123-4567", "Hello from the computer!") # Send a text message. MUST be a phone number, so use computer.contacts.get_phone_number frequently here
68+
{self._get_all_computer_tools_signature_and_description()}
7869
```
7970
8071
Do not import the computer module, or any of its sub-modules. They are already imported.
@@ -90,6 +81,57 @@ def languages(self):
9081
def languages(self, value):
9182
self.terminal.languages = value
9283

84+
def _get_all_computer_tools_list(self):
85+
return [self.mouse, self.keyboard, self.display, self.clipboard, self.mail, self.sms, self.calendar, self.contacts, self.browser, self.os, self.vision, self.skills, self.docs, self.ai, self.files]
86+
87+
def _get_all_computer_tools_signature_and_description(self):
88+
"""
89+
This function returns a list of all the computer tools that are available with their signature and description from the function docstrings.
90+
for example:
91+
computer.browser.search(query) # Searches the web for the specified query and returns the results.
92+
computer.calendar.create_event(title: str, start_date: datetime.datetime, end_date: datetime.datetime, location: str = "", notes: str = "", calendar: str = None) -> str # Creates a new calendar event in the default calendar with the given parameters using AppleScript.
93+
"""
94+
tools = self._get_all_computer_tools_list()
95+
tools_signature_and_description = []
96+
for tool in tools:
97+
tool_info = self._extract_tool_info(tool)
98+
for method in tool_info["methods"]:
99+
# Format as tool_signature # tool_description
100+
formatted_info = f"{method['signature']} # {method['description']}"
101+
tools_signature_and_description.append(formatted_info)
102+
return tools_signature_and_description
103+
104+
def _extract_tool_info(self, tool):
105+
"""
106+
Helper function to extract the signature and description of a tool's methods.
107+
"""
108+
tool_info = {
109+
"signature": tool.__class__.__name__,
110+
"methods": []
111+
}
112+
for name, method in inspect.getmembers(tool, predicate=inspect.ismethod):
113+
if not name.startswith("_"):
114+
# Get the method signature
115+
method_signature = inspect.signature(method)
116+
# Construct the signature string without *args and **kwargs
117+
param_str = ", ".join(
118+
f"{param.name}"
119+
if param.default == param.empty
120+
else f"{param.name}={param.default!r}"
121+
for param in method_signature.parameters.values()
122+
if param.kind not in (param.VAR_POSITIONAL, param.VAR_KEYWORD)
123+
)
124+
full_signature = f"computer.{tool.__class__.__name__.lower()}.{name}({param_str})"
125+
# Get the method description
126+
method_description = method.__doc__ or ""
127+
# Append the method details
128+
tool_info["methods"].append({
129+
"signature": full_signature,
130+
"description": method_description.strip()
131+
})
132+
return tool_info
133+
134+
93135
def run(self, *args, **kwargs):
94136
"""
95137
Shortcut for computer.terminal.run

poetry.lock

+11-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ isort = "^5.12.0"
8383
pre-commit = "^3.5.0"
8484
pytest = "^7.4.0"
8585
sniffio = "^1.3.0"
86+
websockets = "^13.1"
8687

8788
[build-system]
8889
requires = ["poetry-core>=1.0.0"]

tests/core/computer/test_computer.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import unittest
2+
from unittest import mock
3+
from interpreter.core.computer.computer import Computer
4+
5+
class TestComputer(unittest.TestCase):
6+
def setUp(self):
7+
self.computer = Computer(mock.Mock())
8+
9+
def test_get_all_computer_tools_list(self):
10+
# Act
11+
tools_list = self.computer._get_all_computer_tools_list()
12+
13+
# Assert
14+
self.assertEqual(len(tools_list), 15)
15+
16+
def test_get_all_computer_tools_signature_and_description(self):
17+
# Act
18+
tools_description = self.computer._get_all_computer_tools_signature_and_description()
19+
20+
# Assert
21+
self.assertGreater(len(tools_description), 64)

0 commit comments

Comments
 (0)