18
18
from .compilers .instruction_compiler import InstructionCompiler
19
19
from .memories import Memory
20
20
21
+
21
22
TIME_BETWEEN_ACTIONS = 0.01
22
23
23
24
import logging
@@ -55,6 +56,7 @@ def __init__(
55
56
debug_html_folder = "" ,
56
57
instruction_output_file = None ,
57
58
close_after_completion = True ,
59
+ remote_url = None ,
58
60
):
59
61
"""Initialize the agent.
60
62
@@ -89,8 +91,8 @@ def __init__(
89
91
or instruction_output_file .endswith (".json" )
90
92
), "Instruction output file must be a YAML or JSON file or None."
91
93
assert (
92
- chromedriver_path is not None
93
- ), "Please provide a path to the chromedriver executable. "
94
+ ( chromedriver_path is not None ) ^ ( remote_url is not None ) # XOR
95
+ ), "Please provide a path to the chromedriver executable or Selenium Grid target "
94
96
self .model_for_instructions = model_for_instructions
95
97
self .model_for_responses = model_for_responses
96
98
logger .info (f"Using model for instructions: { model_for_instructions } " )
@@ -101,6 +103,7 @@ def __init__(
101
103
self .debug_html_folder = debug_html_folder
102
104
self .memory_folder = memory_folder
103
105
self .close_after_completion = close_after_completion
106
+ self .remote_url = remote_url
104
107
105
108
"""Fire up the compiler."""
106
109
self .instruction_compiler = InstructionCompiler (
@@ -116,26 +119,31 @@ def __init__(
116
119
117
120
"""Set up the driver."""
118
121
_chrome_options = webdriver .ChromeOptions ()
119
- _chrome_options .add_argument (f"user-data-dir={ user_data_dir } " )
120
122
# 🤫 Evade detection.
121
123
# https://stackoverflow.com/questions/53039551/selenium-webdriver-modifying-navigator-webdriver-flag-to-prevent-selenium-detec
122
124
_chrome_options .add_argument ('--disable-blink-features=AutomationControlled' )
123
125
_chrome_options .add_experimental_option ("excludeSwitches" , ["enable-automation" ])
124
126
_chrome_options .add_experimental_option ('useAutomationExtension' , False )
125
-
127
+ _chrome_options . add_argument ( f"user-data-dir= { user_data_dir } " )
126
128
self .headless = headless
127
129
if headless :
128
130
_chrome_options .add_argument ("--headless" )
129
131
for option in chrome_options :
130
- _chrome_options .add_argument (f"{ option } ={ chrome_options [option ]} " )
131
-
132
- # Instantiate Service with the path to the chromedriver and the options.
133
- service = Service (chromedriver_path )
134
- self .driver = webdriver .Chrome (service = service , options = _chrome_options )
132
+ if chrome_options [option ] == None :
133
+ _chrome_options .add_argument (f"{ option } " )
134
+ else :
135
+ _chrome_options .add_argument (f"{ option } ={ chrome_options [option ]} " )
136
+
137
+ # Check if remote_url is set and conditionally set the driver to a remote endpoint
138
+ if remote_url :
139
+ self .driver = webdriver .Remote (command_executor = remote_url , options = _chrome_options )
140
+ else :
141
+ # Instantiate Service with the path to the chromedriver and the options.
142
+ service = Service (chromedriver_path )
143
+ self .driver = webdriver .Chrome (service = service , options = _chrome_options )
135
144
# 🤫 Evade detection.
136
145
self .driver .execute_script ("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})" )
137
146
138
-
139
147
"""Helper functions"""
140
148
141
149
def _check_danger (self , action_str ):
0 commit comments