mirror of
https://github.com/velocitatem/PHANTOM.git
synced 2026-05-31 08:33:36 +00:00
refactored import structure and created full tests
This commit is contained in:
0
experiments/__init__.py
Normal file
0
experiments/__init__.py
Normal file
@@ -1,5 +1,4 @@
|
|||||||
from os import environ
|
from experiments.agents.base import Agent as BaseAgent
|
||||||
from base import Agent as BaseAgent
|
|
||||||
from browser_use import Browser, Agent, ChatOpenAI
|
from browser_use import Browser, Agent, ChatOpenAI
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
@@ -28,6 +27,7 @@ class GenericBrowserUseAgent(BaseAgent):
|
|||||||
browser=self.browser)
|
browser=self.browser)
|
||||||
async def act(self) -> str:
|
async def act(self) -> str:
|
||||||
self.result = await self.agent.run()
|
self.result = await self.agent.run()
|
||||||
|
# https://github.com/browser-use/browser-use/blob/main/browser_use/agent/views.py#L301
|
||||||
return self.result.final_result()
|
return self.result.final_result()
|
||||||
|
|
||||||
def get_agent(agent_type: AgentTypes, **kwargs) -> Agent:
|
def get_agent(agent_type: AgentTypes, **kwargs) -> Agent:
|
||||||
|
|||||||
@@ -1,3 +1,27 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
import asyncio
|
||||||
|
from experiments.agents.agent import get_agent, AgentTypes
|
||||||
|
|
||||||
from agent import get_agent
|
|
||||||
|
def test_agent_init():
|
||||||
|
agent = get_agent(AgentTypes.GENERIC_BROWSER_USE_AGENT, goal="test", url="http://example.com", timeout=100)
|
||||||
|
assert agent.goal == "test"
|
||||||
|
assert agent.url == "http://example.com"
|
||||||
|
assert agent.timeout == 100
|
||||||
|
|
||||||
|
|
||||||
|
def test_invalid_agent():
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
get_agent("invalid", goal="test")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_agent_execution():
|
||||||
|
agent = get_agent(AgentTypes.GENERIC_BROWSER_USE_AGENT, goal="get page title", url="https://example.com", timeout=60)
|
||||||
|
result = await agent.act()
|
||||||
|
assert result
|
||||||
|
assert agent.final_result()
|
||||||
|
assert agent.final_result().history[-1].result[-1].is_done == True
|
||||||
|
assert isinstance(result, str)
|
||||||
|
assert "example" in result.lower()
|
||||||
|
assert len(result) > 0
|
||||||
|
|||||||
@@ -6,3 +6,5 @@ ipykernel
|
|||||||
matplotlib
|
matplotlib
|
||||||
graphviz
|
graphviz
|
||||||
browser-use
|
browser-use
|
||||||
|
pytest
|
||||||
|
pytest-asyncio
|
||||||
|
|||||||
Reference in New Issue
Block a user