From 748d253c31d1945ca46686c3bb0e121bbe88f2f9 Mon Sep 17 00:00:00 2001 From: vvincent1234 Date: Fri, 24 Jan 2025 09:42:42 +0800 Subject: [PATCH 1/3] fix CHROME_PERSISTENT_SESSION error --- Dockerfile | 1 + src/browser/custom_browser.py | 1 + src/utils/default_config_settings.py | 2 +- supervisord.conf | 2 +- tests/test_llm_api.py | 4 ++-- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1fdeaca..0d635ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,6 +61,7 @@ RUN pip install --no-cache-dir -r requirements.txt ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright RUN playwright install --with-deps chromium RUN playwright install-deps +RUN apt-get install -y google-chrome-stable # Copy the application code COPY . . diff --git a/src/browser/custom_browser.py b/src/browser/custom_browser.py index 829e06e..5f4943c 100644 --- a/src/browser/custom_browser.py +++ b/src/browser/custom_browser.py @@ -5,6 +5,7 @@ # @FileName: browser.py import asyncio +import pdb from playwright.async_api import Browser as PlaywrightBrowser from playwright.async_api import ( diff --git a/src/utils/default_config_settings.py b/src/utils/default_config_settings.py index b4c08cf..02f9129 100644 --- a/src/utils/default_config_settings.py +++ b/src/utils/default_config_settings.py @@ -17,7 +17,7 @@ def default_config(): "llm_temperature": 1.0, "llm_base_url": "", "llm_api_key": "", - "use_own_browser": False, + "use_own_browser": os.getenv("CHROME_PERSISTENT_SESSION", False), "keep_browser_open": False, "headless": False, "disable_security": True, diff --git a/supervisord.conf b/supervisord.conf index 9aac183..0515578 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -58,7 +58,7 @@ startsecs=3 depends_on=x11vnc [program:persistent_browser] -command=bash -c 'if [ "%(ENV_CHROME_PERSISTENT_SESSION)s" = "true" ]; then mkdir -p /app/data/chrome_data && sleep 8 && google-chrome --user-data-dir=/app/data/chrome_data --window-position=0,0 --window-size=%(ENV_RESOLUTION_WIDTH)s,%(ENV_RESOLUTION_HEIGHT)s --start-maximized --no-sandbox --disable-dev-shm-usage --disable-gpu --disable-software-rasterizer --disable-setuid-sandbox --no-first-run --no-default-browser-check --no-experiments --ignore-certificate-errors --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0 "data:text/html,

Browser Ready for AI Interaction

"; else echo "Persistent browser disabled"; fi' +command=bash -c 'mkdir -p /app/data/chrome_data && sleep 8 && google-chrome --user-data-dir=/app/data/chrome_data --window-position=0,0 --window-size=%(ENV_RESOLUTION_WIDTH)s,%(ENV_RESOLUTION_HEIGHT)s --start-maximized --no-sandbox --disable-dev-shm-usage --disable-gpu --disable-software-rasterizer --disable-setuid-sandbox --no-first-run --no-default-browser-check --no-experiments --ignore-certificate-errors --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0 "data:text/html,

Browser Ready for AI Interaction

"' autorestart=%(ENV_CHROME_PERSISTENT_SESSION)s stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 diff --git a/tests/test_llm_api.py b/tests/test_llm_api.py index 9e2a1d6..dc1d8b7 100644 --- a/tests/test_llm_api.py +++ b/tests/test_llm_api.py @@ -127,5 +127,5 @@ def test_ollama_model(): # test_openai_model() # test_gemini_model() # test_azure_openai_model() - # test_deepseek_model() - test_ollama_model() + test_deepseek_model() + # test_ollama_model() From b3f6324ddb5291c1564361a81873d5971ba16ad0 Mon Sep 17 00:00:00 2001 From: vvincent1234 Date: Fri, 24 Jan 2025 19:56:34 +0800 Subject: [PATCH 2/3] fix docker build --- .dockerignore | 2 ++ Dockerfile | 2 +- docker-compose.yml | 4 ---- src/utils/utils.py | 2 +- supervisord.conf | 2 +- tests/test_browser_use.py | 16 ++++++++-------- tests/test_llm_api.py | 4 ++-- 7 files changed, 15 insertions(+), 17 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9635889 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +data +tmp \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0d635ac..2302df0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,7 +55,7 @@ WORKDIR /app # Copy requirements and install Python dependencies COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt +RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple # Install Playwright and browsers with system dependencies ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright diff --git a/docker-compose.yml b/docker-compose.yml index 6253a4a..864391b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,13 +28,9 @@ services: - RESOLUTION_WIDTH=${RESOLUTION_WIDTH:-1920} - RESOLUTION_HEIGHT=${RESOLUTION_HEIGHT:-1080} - VNC_PASSWORD=${VNC_PASSWORD:-vncpassword} - - PERSISTENT_BROWSER_PORT=9222 - - PERSISTENT_BROWSER_HOST=localhost - CHROME_DEBUGGING_PORT=9222 - CHROME_DEBUGGING_HOST=localhost volumes: - - ./data:/app/data - - ./data/chrome_data:/app/data/chrome_data - /tmp/.X11-unix:/tmp/.X11-unix restart: unless-stopped shm_size: '2gb' diff --git a/src/utils/utils.py b/src/utils/utils.py index 3ab3897..cfe24d3 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -88,7 +88,7 @@ def get_llm_model(provider: str, **kwargs): return ChatOllama( model=kwargs.get("model_name", "qwen2.5:7b"), temperature=kwargs.get("temperature", 0.0), - num_ctx=128000, + num_ctx=kwargs.get("num_ctx", 32000), base_url=kwargs.get("base_url", "http://localhost:11434"), ) elif provider == "azure_openai": diff --git a/supervisord.conf b/supervisord.conf index 0515578..4408373 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -59,7 +59,7 @@ depends_on=x11vnc [program:persistent_browser] command=bash -c 'mkdir -p /app/data/chrome_data && sleep 8 && google-chrome --user-data-dir=/app/data/chrome_data --window-position=0,0 --window-size=%(ENV_RESOLUTION_WIDTH)s,%(ENV_RESOLUTION_HEIGHT)s --start-maximized --no-sandbox --disable-dev-shm-usage --disable-gpu --disable-software-rasterizer --disable-setuid-sandbox --no-first-run --no-default-browser-check --no-experiments --ignore-certificate-errors --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0 "data:text/html,

Browser Ready for AI Interaction

"' -autorestart=%(ENV_CHROME_PERSISTENT_SESSION)s +autorestart=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr diff --git a/tests/test_browser_use.py b/tests/test_browser_use.py index b13aa26..aa86c29 100644 --- a/tests/test_browser_use.py +++ b/tests/test_browser_use.py @@ -247,18 +247,18 @@ async def test_browser_use_custom_v2(): # api_key=os.getenv("GOOGLE_API_KEY", "") # ) - llm = utils.get_llm_model( - provider="deepseek", - model_name="deepseek-chat", - temperature=0.8 - ) - # llm = utils.get_llm_model( - # provider="ollama", model_name="qwen2.5:7b", temperature=0.8 + # provider="deepseek", + # model_name="deepseek-chat", + # temperature=0.8 # ) + llm = utils.get_llm_model( + provider="ollama", model_name="qwen2.5:7b", temperature=0.5 + ) + controller = CustomController() - use_own_browser = True + use_own_browser = False disable_security = True use_vision = False # Set to False when using DeepSeek tool_call_in_content = True # Set to True when using Ollama diff --git a/tests/test_llm_api.py b/tests/test_llm_api.py index dc1d8b7..9e2a1d6 100644 --- a/tests/test_llm_api.py +++ b/tests/test_llm_api.py @@ -127,5 +127,5 @@ def test_ollama_model(): # test_openai_model() # test_gemini_model() # test_azure_openai_model() - test_deepseek_model() - # test_ollama_model() + # test_deepseek_model() + test_ollama_model() From d26ebe8fb63e8387df38eb25afec84035fbae1c9 Mon Sep 17 00:00:00 2001 From: vvincent1234 Date: Fri, 24 Jan 2025 20:00:04 +0800 Subject: [PATCH 3/3] fix docker build --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2302df0..0d635ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,7 +55,7 @@ WORKDIR /app # Copy requirements and install Python dependencies COPY requirements.txt . -RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple +RUN pip install --no-cache-dir -r requirements.txt # Install Playwright and browsers with system dependencies ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright