feat&fix: add proxy support in setup and remove hardcoded proxy from example

This commit is contained in:
adlsdztony
2025-07-01 13:47:16 +00:00
parent 64f47d1a32
commit 2f9ae1f3ad
3 changed files with 7 additions and 3 deletions

View File

@@ -47,11 +47,12 @@ class SetupController:
self.http_server: str = f"http://{vm_ip}:{server_port}" self.http_server: str = f"http://{vm_ip}:{server_port}"
self.http_server_setup_root: str = f"http://{vm_ip}:{server_port}/setup" self.http_server_setup_root: str = f"http://{vm_ip}:{server_port}/setup"
self.cache_dir: str = cache_dir self.cache_dir: str = cache_dir
self.use_proxy: bool = False
def reset_cache_dir(self, cache_dir: str): def reset_cache_dir(self, cache_dir: str):
self.cache_dir = cache_dir self.cache_dir = cache_dir
def setup(self, config: List[Dict[str, Any]])-> bool: def setup(self, config: List[Dict[str, Any]], use_proxy: bool = False)-> bool:
""" """
Args: Args:
config (List[Dict[str, Any]]): list of dict like {str: Any}. each config (List[Dict[str, Any]]): list of dict like {str: Any}. each
@@ -63,6 +64,7 @@ class SetupController:
parameters parameters
} }
""" """
self.use_proxy = use_proxy
# make sure connection can be established # make sure connection can be established
logger.info(f"try to connect {self.http_server}") logger.info(f"try to connect {self.http_server}")
retry = 0 retry = 0
@@ -237,6 +239,9 @@ class SetupController:
if not shell and isinstance(command, str) and len(command.split()) > 1: if not shell and isinstance(command, str) and len(command.split()) > 1:
logger.warning("Command should be a list of strings. Now it is a string. Will split it by space.") logger.warning("Command should be a list of strings. Now it is a string. Will split it by space.")
command = command.split() command = command.split()
if command[0] == "google-chrome" and self.use_proxy:
command.append("--proxy-server=http://127.0.0.1:18888") # Use the proxy server set up by _proxy_setup
payload = json.dumps({"command": command, "shell": shell}) payload = json.dumps({"command": command, "shell": shell})
headers = {"Content-Type": "application/json"} headers = {"Content-Type": "application/json"}

View File

@@ -203,7 +203,7 @@ class DesktopEnv(gym.Env):
self._set_task_info(task_config) self._set_task_info(task_config)
self.setup_controller.reset_cache_dir(self.cache_dir) self.setup_controller.reset_cache_dir(self.cache_dir)
logger.info("Setting up environment...") logger.info("Setting up environment...")
success = self.setup_controller.setup(self.config) success = self.setup_controller.setup(self.config, task_config.get("proxy", False) and self.enable_proxy)
if success: if success:
break break
else: else:

View File

@@ -9,7 +9,6 @@
"parameters": { "parameters": {
"command": [ "command": [
"google-chrome", "google-chrome",
"--proxy-server=http://127.0.0.1:18888",
"--remote-debugging-port=1337" "--remote-debugging-port=1337"
] ]
} }