1
- import json
2
1
import inspect
2
+ import json
3
3
4
4
from .ai .ai import Ai
5
5
from .browser .browser import Browser
@@ -58,14 +58,18 @@ def __init__(self, interpreter):
58
58
self .interpreter .max_output
59
59
) # Should mirror interpreter.max_output
60
60
61
+ computer_tools = "\n " .join (
62
+ self ._get_all_computer_tools_signature_and_description ()
63
+ )
64
+
61
65
self .system_message = f"""
62
66
63
67
# THE COMPUTER API
64
68
65
69
A python `computer` module is ALREADY IMPORTED, and can be used for many tasks:
66
70
67
71
```python
68
- { " \n " . join ( self . _get_all_computer_tools_signature_and_description ()) }
72
+ { computer_tools }
69
73
```
70
74
71
75
Do not import the computer module, or any of its sub-modules. They are already imported.
@@ -82,7 +86,23 @@ def languages(self, value):
82
86
self .terminal .languages = value
83
87
84
88
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 ]
89
+ return [
90
+ self .mouse ,
91
+ self .keyboard ,
92
+ self .display ,
93
+ self .clipboard ,
94
+ self .mail ,
95
+ self .sms ,
96
+ self .calendar ,
97
+ self .contacts ,
98
+ self .browser ,
99
+ self .os ,
100
+ self .vision ,
101
+ self .skills ,
102
+ self .docs ,
103
+ self .ai ,
104
+ self .files ,
105
+ ]
86
106
87
107
def _get_all_computer_tools_signature_and_description (self ):
88
108
"""
@@ -105,34 +125,41 @@ def _extract_tool_info(self, tool):
105
125
"""
106
126
Helper function to extract the signature and description of a tool's methods.
107
127
"""
108
- tool_info = {
109
- "signature" : tool .__class__ .__name__ ,
110
- "methods" : []
111
- }
128
+ tool_info = {"signature" : tool .__class__ .__name__ , "methods" : []}
112
129
if tool .__class__ .__name__ == "Browser" :
113
130
methods = []
114
131
for name in dir (tool ):
115
- if ' driver' in name :
132
+ if " driver" in name :
116
133
continue # Skip methods containing 'driver' in their name
117
134
attr = getattr (tool , name )
118
- if callable (attr ) and not name .startswith ('_' ) and not hasattr (attr , '__wrapped__' ) and not isinstance (attr , property ):
135
+ if (
136
+ callable (attr )
137
+ and not name .startswith ("_" )
138
+ and not hasattr (attr , "__wrapped__" )
139
+ and not isinstance (attr , property )
140
+ ):
119
141
# Construct the method signature manually
120
142
param_str = ", " .join (
121
- param for param in attr .__code__ .co_varnames [:attr .__code__ .co_argcount ]
143
+ param
144
+ for param in attr .__code__ .co_varnames [
145
+ : attr .__code__ .co_argcount
146
+ ]
122
147
)
123
148
full_signature = f"computer.{ tool .__class__ .__name__ .lower ()} .{ name } ({ param_str } )"
124
149
# Get the method description
125
150
method_description = attr .__doc__ or ""
126
151
# Append the method details
127
- tool_info ["methods" ].append ({
128
- "signature" : full_signature ,
129
- "description" : method_description .strip ()
130
- })
131
- return tool_info
152
+ tool_info ["methods" ].append (
153
+ {
154
+ "signature" : full_signature ,
155
+ "description" : method_description .strip (),
156
+ }
157
+ )
158
+ return tool_info
132
159
133
160
for name , method in inspect .getmembers (tool , predicate = inspect .ismethod ):
134
161
# Check if the method should be ignored based on its decorator
135
- if not name .startswith ("_" ) and not hasattr (method , ' __wrapped__' ):
162
+ if not name .startswith ("_" ) and not hasattr (method , " __wrapped__" ):
136
163
# Get the method signature
137
164
method_signature = inspect .signature (method )
138
165
# Construct the signature string without *args and **kwargs
@@ -143,17 +170,20 @@ def _extract_tool_info(self, tool):
143
170
for param in method_signature .parameters .values ()
144
171
if param .kind not in (param .VAR_POSITIONAL , param .VAR_KEYWORD )
145
172
)
146
- full_signature = f"computer.{ tool .__class__ .__name__ .lower ()} .{ name } ({ param_str } )"
173
+ full_signature = (
174
+ f"computer.{ tool .__class__ .__name__ .lower ()} .{ name } ({ param_str } )"
175
+ )
147
176
# Get the method description
148
177
method_description = method .__doc__ or ""
149
178
# Append the method details
150
- tool_info ["methods" ].append ({
151
- "signature" : full_signature ,
152
- "description" : method_description .strip ()
153
- })
179
+ tool_info ["methods" ].append (
180
+ {
181
+ "signature" : full_signature ,
182
+ "description" : method_description .strip (),
183
+ }
184
+ )
154
185
return tool_info
155
186
156
-
157
187
def run (self , * args , ** kwargs ):
158
188
"""
159
189
Shortcut for computer.terminal.run
0 commit comments