Merge branch 'feat/aws-provider-support' of https://github.com/xlang-ai/OSWorld into feat/aws-provider-support

This commit is contained in:
yuanmengqi
2025-06-07 11:40:26 +00:00
3 changed files with 61 additions and 1 deletions

4
.gitignore vendored
View File

@@ -195,4 +195,6 @@ vmware_vm_data
# result
**/result*/**/*
.vscode
.vscode
dataimpulse_proxy_config.json

View File

@@ -21,11 +21,20 @@ from requests_toolbelt.multipart.encoder import MultipartEncoder
from desktop_env.controllers.python import PythonController
from desktop_env.evaluators.metrics.utils import compare_urls
from desktop_env.providers.aws.proxy_pool import get_global_proxy_pool, init_proxy_pool, ProxyInfo
import dotenv
# Load environment variables from .env file
dotenv.load_dotenv()
CLIENT_PASSWORD = os.getenv("CLIENT_PASSWORD", "password") # Default password for sudo operations
PROXY_CONFIG_FILE = os.getenv("PROXY_CONFIG_FILE", "dataimpulse_proxy_config.json") # Default proxy config file
logger = logging.getLogger("desktopenv.setup")
FILE_PATH = os.path.dirname(os.path.abspath(__file__))
init_proxy_pool(PROXY_CONFIG_FILE) # initialize the global proxy pool
class SetupController:
def __init__(self, vm_ip: str, server_port: int = 5000, chromium_port: int = 9222, vlc_port: int = 8080, cache_dir: str = "cache"):
@@ -360,6 +369,51 @@ class SetupController:
except requests.exceptions.RequestException as e:
logger.error("An error occurred while trying to send the request: %s", e)
def _proxy_setup(self, client_password: str = CLIENT_PASSWORD):
"""Setup system-wide proxy configuration using proxy pool
Args:
client_password (str): Password for sudo operations, defaults to "password"
"""
# Get proxy from global proxy pool
proxy_pool = get_global_proxy_pool()
current_proxy = proxy_pool.get_next_proxy()
if not current_proxy:
logger.error("No proxy available from proxy pool")
raise Exception("No proxy available from proxy pool")
# Format proxy URL
proxy_url = proxy_pool._format_proxy_url(current_proxy)
logger.info(f"Setting up proxy: {current_proxy.host}:{current_proxy.port}")
# Configure system proxy environment variables
proxy_commands = [
f"echo '{client_password}' | sudo -S bash -c \"echo 'export http_proxy={proxy_url}' >> /etc/environment\"",
f"echo '{client_password}' | sudo -S bash -c \"echo 'export https_proxy={proxy_url}' >> /etc/environment\"",
f"echo '{client_password}' | sudo -S bash -c \"echo 'export HTTP_PROXY={proxy_url}' >> /etc/environment\"",
f"echo '{client_password}' | sudo -S bash -c \"echo 'export HTTPS_PROXY={proxy_url}' >> /etc/environment\"",
]
# Execute all proxy configuration commands
for cmd in proxy_commands:
try:
self._execute_setup([cmd], shell=True)
except Exception as e:
logger.error(f"Failed to execute proxy setup command: {e}")
proxy_pool.mark_proxy_failed(current_proxy)
raise
# Reload environment variables
reload_cmd = "source /etc/environment"
try:
logger.info(f"Proxy setup completed successfully for {current_proxy.host}:{current_proxy.port}")
proxy_pool.mark_proxy_success(current_proxy)
except Exception as e:
logger.error(f"Failed to reload environment variables: {e}")
proxy_pool.mark_proxy_failed(current_proxy)
raise
# Chrome setup
def _chrome_open_tabs_setup(self, urls_to_open: List[str]):
host = self.vm_ip

View File

@@ -191,6 +191,10 @@ class DesktopEnv(gym.Env):
logger.info("Setting up environment...")
self.setup_controller.setup(self.config)
logger.info("Environment setup complete.")
if task_config.get("proxy", False):
# If using proxy, set up the proxy configuration
self.setup_controller._proxy_setup()
observation = self._get_obs()
return observation