Skip to content

Commit

Permalink
make pyright happy
Browse files Browse the repository at this point in the history
  • Loading branch information
husseinmozannar committed Dec 10, 2024
1 parent 5a7fbf4 commit 2a7a87f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
self.to_resize_viewport = to_resize_viewport
self._page_script: str = ""
self.last_cursor_position: Tuple[float, float] = (0.0, 0.0)
self._markdown_converter: Optional[MarkItDown] = None
self._markdown_converter: Optional[MarkItDown] | None = None

# Read page_script
with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), "page_script.js"), "rt") as fh:
Expand Down
29 changes: 12 additions & 17 deletions python/packages/autogen-ext/tests/test_websurfer_agent.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import asyncio
import json
import logging
import sys
from datetime import datetime
from typing import Any, AsyncGenerator, List

import pytest
from autogen_agentchat import EVENT_LOGGER_NAME
from autogen_agentchat.messages import (
HandoffMessage,
MultiModalMessage,
TextMessage,
ToolCallMessage,
ToolCallResultMessage,
)
from autogen_core.components.tools import FunctionTool
from autogen_ext.agents.web_surfer import MultimodalWebSurfer
from autogen_ext.models.openai import OpenAIChatCompletionClient
from openai.resources.chat.completions import AsyncCompletions
Expand Down Expand Up @@ -112,12 +107,12 @@ async def test_run_websurfer(monkeypatch: pytest.MonkeyPatch) -> None:
"WebSurfer", model_client=OpenAIChatCompletionClient(model=model, api_key=""), use_ocr=False
)
# Before lazy init
assert agent._name == "WebSurfer"
assert agent._playwright is None
assert agent._name == "WebSurfer" # pyright: ignore[reportPrivateUsage]
assert agent._playwright is None # pyright: ignore[reportPrivateUsage]
# After lazy init
result = await agent.run(task="task")
assert agent._playwright is not None
assert agent._page is not None
assert agent._playwright is not None # pyright: ignore[reportPrivateUsage]
assert agent._page is not None # pyright: ignore[reportPrivateUsage]
# now check result object
assert len(result.messages) == 3
# user message
Expand All @@ -132,21 +127,21 @@ async def test_run_websurfer(monkeypatch: pytest.MonkeyPatch) -> None:
assert result.messages[2].models_usage.prompt_tokens == 10
assert result.messages[2].content == "Hello"
# check internal web surfer state
assert len(agent._chat_history) == 2
assert agent._chat_history[0].content == "task"
assert agent._chat_history[1].content == "Hello"
url_after_no_tool = agent._page.url # type: ignore
assert len(agent._chat_history) == 2 # pyright: ignore[reportPrivateUsage]
assert agent._chat_history[0].content == "task" # pyright: ignore[reportPrivateUsage]
assert agent._chat_history[1].content == "Hello" # pyright: ignore[reportPrivateUsage]
url_after_no_tool = agent._page.url # pyright: ignore[reportPrivateUsage]

# run again
result = await agent.run(task="task")
assert len(result.messages) == 3
assert isinstance(result.messages[2], MultiModalMessage)
assert (
result.messages[2]
.content[0]
.startswith(
result.messages[2] # type: ignore
.content[0] # type: ignore
.startswith( # type: ignore
"I am waiting a short period of time before taking further action.\n\n Here is a screenshot of the webpage: [Search - Microsoft Bing](https://www.bing.com/)"
)
)
) # type: ignore
url_after_sleep = agent._page.url # type: ignore
assert url_after_no_tool == url_after_sleep

0 comments on commit 2a7a87f

Please sign in to comment.