Skip to content

Commit

Permalink
refactor(hitl): pass playwright context to web interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
idiotWu committed Jan 26, 2025
1 parent 75d8449 commit 5cc479a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions npiai/core/__test__/captcha_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Literal

from npiai import BrowserTool, HITL
from npiai.core import PlaywrightContext
from npiai.utils.test_utils import DebugContext


Expand Down Expand Up @@ -40,6 +41,7 @@ async def web_interaction(
message: str,
url: str,
action: Literal["captcha", "login"],
playwright: PlaywrightContext,
) -> str:
print(f"[HITL] web_interaction: {message=}, {url=}, {action=}")
return "web_interaction"
Expand Down
2 changes: 2 additions & 0 deletions npiai/core/hitl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import List, Literal

from npiai.context import Context
from npiai.core import PlaywrightContext


class HITL(ABC):
Expand Down Expand Up @@ -42,4 +43,5 @@ async def web_interaction(
message: str,
url: str,
action: Literal["captcha", "login"],
playwright: PlaywrightContext,
) -> str: ...
2 changes: 2 additions & 0 deletions npiai/core/tool/_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,15 @@ async def handle_captcha(captcha_type: Literal["none", "captcha", "login"]):
message="Would you please help me solve the captcha?",
url=url,
action="captcha",
playwright=self.playwright,
)
case "login":
await ctx.hitl.web_interaction(
tool_name=self.name,
message="Would you please help me login to the website?",
url=url,
action="login",
playwright=self.playwright,
)

return captcha_type
Expand Down
2 changes: 2 additions & 0 deletions npiai/tools/scrapers/web/__test__/interactive.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
from typing import Literal

from npiai.core import PlaywrightContext
from npiai.utils.test_utils import DebugContext

# from npiai import Context
Expand Down Expand Up @@ -44,6 +45,7 @@ async def web_interaction(
message: str,
url: str,
action: Literal["captcha", "login"],
playwright: PlaywrightContext,
) -> str:
print(f"[HITL] web_interaction: {message=}, {url=}, {action=}")
return "web_interaction"
Expand Down

0 comments on commit 5cc479a

Please sign in to comment.