Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rjambrecic committed Jan 24, 2025
1 parent 4e5c3c1 commit ad74086
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
12 changes: 4 additions & 8 deletions autogen/tools/experimental/browser_use/browser_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ class BrowserUseTool(Tool):
def __init__( # type: ignore[no-any-unimported]
self,
*,
llm_config: dict[str, Any],
model: str,
api_key: str,
browser: Optional["Browser"] = None,
agent_kwargs: Optional[dict[str, Any]] = None,
browser_config: Optional[dict[str, Any]] = None,
):
"""Use the browser to perform a task.
Args:
llm_config: The LLM configuration.
model: The model to use.
api_key: The API key to use.
browser: The browser to use. If defined, browser_config must be None
agent_kwargs: Additional keyword arguments to pass to the Agent
browser_config: The browser configuration to use. If defined, browser must be None
Expand All @@ -81,12 +83,6 @@ def __init__( # type: ignore[no-any-unimported]
if "generate_gif" not in agent_kwargs:
agent_kwargs["generate_gif"] = False

try:
model: str = llm_config["config_list"][0]["model"] # type: ignore[index]
api_key: str = llm_config["config_list"][0]["api_key"] # type: ignore[index]
except (KeyError, TypeError):
raise ValueError("llm_config must be a valid config dictionary.")

async def browser_use( # type: ignore[no-any-unimported]
task: Annotated[str, "The task to perform."],
api_key: Annotated[str, Depends(on(api_key))],
Expand Down
4 changes: 3 additions & 1 deletion notebook/tools_browser_use.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@
"metadata": {},
"outputs": [],
"source": [
"browser_use_tool = BrowserUseTool(llm_config=llm_config, browser_config={\"headless\": False})\n",
"browser_use_tool = BrowserUseTool(\n",
" model=config_list[0][\"model\"], api_key=config_list[0][\"api_key\"], browser_config={\"headless\": False}\n",
")\n",
"\n",
"browser_use_tool.register_for_execution(user_proxy)\n",
"browser_use_tool.register_for_llm(assistant)"
Expand Down
11 changes: 9 additions & 2 deletions test/tools/experimental/browser_use/test_browser_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def _use_imports(self) -> None:
self._Agent = Agent

def test_broser_use_tool_init(self, mock_credentials: Credentials) -> None:
browser_use_tool = BrowserUseTool(llm_config=mock_credentials.llm_config)
config = mock_credentials.config_list[0]
model: str = config["model"] # type: ignore[index]
api_key: str = config["api_key"] # type: ignore[index]

browser_use_tool = BrowserUseTool(model=model, api_key=api_key)
assert browser_use_tool.name == "browser_use"
assert browser_use_tool.description == "Use the browser to perform a task."
assert isinstance(browser_use_tool.func, Callable) # type: ignore[arg-type]
Expand All @@ -46,7 +50,10 @@ def test_broser_use_tool_init(self, mock_credentials: Credentials) -> None:

@pytest.fixture()
def browser_use_tool(self, credentials_gpt_4o_mini: Credentials) -> BrowserUseTool:
return BrowserUseTool(llm_config=credentials_gpt_4o_mini.llm_config)
config = credentials_gpt_4o_mini.config_list[0]
model = config["model"]
api_key = config["api_key"]
return BrowserUseTool(model=model, api_key=api_key)

@pytest.mark.openai
@pytest.mark.asyncio
Expand Down

0 comments on commit ad74086

Please sign in to comment.