MCPcopy Index your code
hub / github.com/AmberSahdev/Open-Interface / execute_function

Method execute_function

app/interpreter.py:51–86  ·  view source on GitHub ↗

We are expecting only two types of function calls below 1. time.sleep() - to wait for web pages, applications, and other things to load. 2. pyautogui calls to interact with system's mouse and keyboard.

(self, function_name: str, parameters: dict[str, Any])

Source from the content-addressed store, hash-verified

49 return False
50
51 def execute_function(self, function_name: str, parameters: dict[str, Any]) -> None:
52 """
53 We are expecting only two types of function calls below
54 1. time.sleep() - to wait for web pages, applications, and other things to load.
55 2. pyautogui calls to interact with system's mouse and keyboard.
56 """
57 # Sometimes pyautogui needs warming up i.e. sometimes first call isn't executed hence padding a random call here
58 pyautogui.press("command", interval=0.2)
59
60 if function_name == "sleep" and parameters.get("secs"):
61 sleep(parameters.get("secs"))
62 elif hasattr(pyautogui, function_name):
63 # Execute the corresponding pyautogui function i.e. Keyboard or Mouse commands.
64 function_to_call = getattr(pyautogui, function_name)
65
66 # Special handling for the 'write' function
67 if function_name == 'write' and ('string' in parameters or 'text' in parameters):
68 # 'write' function expects a string, not a 'text' keyword argument but LLM sometimes gets confused on the parameter name.
69 string_to_write = parameters.get('string') or parameters.get('text')
70 interval = parameters.get('interval', 0.1)
71 function_to_call(string_to_write, interval=interval)
72 elif function_name == 'press' and ('keys' in parameters or 'key' in parameters):
73 # 'press' can take a list of keys or a single key
74 keys_to_press = parameters.get('keys') or parameters.get('key')
75 presses = parameters.get('presses', 1)
76 interval = parameters.get('interval', 0.2)
77 function_to_call(keys_to_press, presses=presses, interval=interval)
78 elif function_name == 'hotkey':
79 # 'hotkey' function expects multiple key arguments, not a list
80 keys = list(parameters.values())
81 function_to_call(*keys)
82 else:
83 # For other functions, pass the parameters as they are
84 function_to_call(**parameters)
85 else:
86 print(f'No such function {function_name} in our interface\'s interpreter')

Callers 1

process_commandMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected