From 91f89e70453f2b812438680467d6a20a476b6f07 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Fri, 10 Jan 2025 13:55:10 +0330 Subject: [PATCH 1/4] feat: initialize browser and close it to resolve UnboundLocalError. --- webui.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/webui.py b/webui.py index f594569..d51ad61 100644 --- a/webui.py +++ b/webui.py @@ -199,6 +199,7 @@ async def run_custom_agent( controller = CustomController() playwright = None browser_context_ = None + browser = None # Initialize browser to None try: if use_own_browser: playwright = await async_playwright().start() @@ -278,14 +279,18 @@ async def run_custom_agent( model_actions = "" model_thoughts = "" finally: - # 显式关闭持久化上下文 + # Close persistent context if it was initialized if browser_context_: await browser_context_.close() - # 关闭 Playwright 对象 + # Stop Playwright if it was started if playwright: await playwright.stop() - await browser.close() + + # Close the browser if it was initialized + if browser: + await browser.close() + return final_result, errors, model_actions, model_thoughts # Define the theme map globally From dab1693bce5f11212539be7ecac51c4e7f55651e Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Fri, 10 Jan 2025 17:39:58 +0330 Subject: [PATCH 2/4] refactor(chore): read llm provider and model from dictionary --- webui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webui.py b/webui.py index ff3db24..c14029e 100644 --- a/webui.py +++ b/webui.py @@ -385,14 +385,14 @@ def create_ui(theme_name="Ocean"): with gr.TabItem("🔧 LLM Configuration", id=2): with gr.Group(): llm_provider = gr.Dropdown( - ["anthropic", "openai", "deepseek", "gemini", "ollama", "azure_openai"], + choices=[provider for provider,model in utils.model_names.items()], label="LLM Provider", value="openai", info="Select your preferred language model provider" ) llm_model_name = gr.Dropdown( label="Model Name", - choices=["gpt-4o", "gpt-4o-mini", "gpt-4", "gpt-3.5-turbo",], + choices=utils.model_names['openai'], value="gpt-4o", interactive=True, allow_custom_value=True, # Allow users to input custom model names From d988bf1c95dcf12ed7f0594e9b1b10707140a51d Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Fri, 10 Jan 2025 17:59:20 +0330 Subject: [PATCH 3/4] revert changes --- webui.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/webui.py b/webui.py index c14029e..f1b784b 100644 --- a/webui.py +++ b/webui.py @@ -199,7 +199,6 @@ async def run_custom_agent( controller = CustomController() playwright = None browser_context_ = None - browser = None # Initialize browser to None try: if use_own_browser: playwright = await async_playwright().start() @@ -279,17 +278,15 @@ async def run_custom_agent( model_actions = "" model_thoughts = "" finally: - # Close persistent context if it was initialized + # 显式关闭持久化上下文 if browser_context_: await browser_context_.close() - # Stop Playwright if it was started + # 关闭 Playwright 对象 if playwright: await playwright.stop() + await browser.close() - # Close the browser if it was initialized - if browser: - await browser.close() return final_result, errors, model_actions, model_thoughts From 8198d68e4dd7b6328fe957ad64f2e3cdfb0f1061 Mon Sep 17 00:00:00 2001 From: meshkatshb Date: Fri, 10 Jan 2025 18:00:10 +0330 Subject: [PATCH 4/4] revert changes --- webui.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/webui.py b/webui.py index f1b784b..8c603d0 100644 --- a/webui.py +++ b/webui.py @@ -286,8 +286,6 @@ async def run_custom_agent( if playwright: await playwright.stop() await browser.close() - - return final_result, errors, model_actions, model_thoughts # Define the theme map globally