1- import json
21import inspect
2+ import json
33
44from .ai .ai import Ai
55from .browser .browser import Browser
@@ -58,14 +58,18 @@ def __init__(self, interpreter):
5858 self .interpreter .max_output
5959 ) # Should mirror interpreter.max_output
6060
61+ computer_tools = "\n " .join (
62+ self ._get_all_computer_tools_signature_and_description ()
63+ )
64+
6165 self .system_message = f"""
6266
6367# THE COMPUTER API
6468
6569A python `computer` module is ALREADY IMPORTED, and can be used for many tasks:
6670
6771```python
68- { " \n " . join ( self . _get_all_computer_tools_signature_and_description ()) }
72+ { computer_tools }
6973```
7074
7175Do not import the computer module, or any of its sub-modules. They are already imported.
@@ -82,7 +86,23 @@ def languages(self, value):
8286 self .terminal .languages = value
8387
8488 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+ ]
86106
87107 def _get_all_computer_tools_signature_and_description (self ):
88108 """
@@ -105,34 +125,41 @@ def _extract_tool_info(self, tool):
105125 """
106126 Helper function to extract the signature and description of a tool's methods.
107127 """
108- tool_info = {
109- "signature" : tool .__class__ .__name__ ,
110- "methods" : []
111- }
128+ tool_info = {"signature" : tool .__class__ .__name__ , "methods" : []}
112129 if tool .__class__ .__name__ == "Browser" :
113130 methods = []
114131 for name in dir (tool ):
115- if ' driver' in name :
132+ if " driver" in name :
116133 continue # Skip methods containing 'driver' in their name
117134 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+ ):
119141 # Construct the method signature manually
120142 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+ ]
122147 )
123148 full_signature = f"computer.{ tool .__class__ .__name__ .lower ()} .{ name } ({ param_str } )"
124149 # Get the method description
125150 method_description = attr .__doc__ or ""
126151 # 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
132159
133160 for name , method in inspect .getmembers (tool , predicate = inspect .ismethod ):
134161 # 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__" ):
136163 # Get the method signature
137164 method_signature = inspect .signature (method )
138165 # Construct the signature string without *args and **kwargs
@@ -143,17 +170,20 @@ def _extract_tool_info(self, tool):
143170 for param in method_signature .parameters .values ()
144171 if param .kind not in (param .VAR_POSITIONAL , param .VAR_KEYWORD )
145172 )
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+ )
147176 # Get the method description
148177 method_description = method .__doc__ or ""
149178 # 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+ )
154185 return tool_info
155186
156-
157187 def run (self , * args , ** kwargs ):
158188 """
159189 Shortcut for computer.terminal.run
0 commit comments