|
1 | 1 | import logging |
| 2 | +from abc import ABC, abstractmethod |
2 | 3 | from typing import Any, Callable, Literal |
3 | 4 |
|
4 | 5 | from langchain_core.utils.function_calling import convert_to_openai_tool |
@@ -73,30 +74,39 @@ def from_function(cls, function: Callable): |
73 | 74 | return cls.model_validate(convert_to_openai_tool(function)) |
74 | 75 |
|
75 | 76 |
|
76 | | -class BrowserBackend(BaseModel): |
| 77 | +class BrowserBackend(BaseModel, ABC): |
| 78 | + @abstractmethod |
77 | 79 | def initialize(self) -> None: |
78 | | - raise NotImplementedError |
| 80 | + pass |
79 | 81 |
|
| 82 | + @abstractmethod |
80 | 83 | def run_js(self, js: str): |
81 | | - raise NotImplementedError |
| 84 | + pass |
82 | 85 |
|
| 86 | + @abstractmethod |
83 | 87 | def goto(self, url: str) -> str: |
84 | | - raise NotImplementedError |
| 88 | + pass |
85 | 89 |
|
| 90 | + @abstractmethod |
86 | 91 | def page_html(self) -> str: |
87 | | - raise NotImplementedError |
| 92 | + pass |
88 | 93 |
|
| 94 | + @abstractmethod |
89 | 95 | def page_screenshot(self) -> Image: |
90 | | - raise NotImplementedError |
| 96 | + pass |
91 | 97 |
|
| 98 | + @abstractmethod |
92 | 99 | def page_axtree(self) -> str: |
93 | | - raise NotImplementedError |
| 100 | + pass |
94 | 101 |
|
| 102 | + @abstractmethod |
95 | 103 | def step(self, action: ToolCallAction) -> str: |
96 | | - raise NotImplementedError |
| 104 | + pass |
97 | 105 |
|
| 106 | + @abstractmethod |
98 | 107 | def actions(self) -> tuple[ToolSpec]: |
99 | | - raise NotImplementedError |
| 108 | + pass |
100 | 109 |
|
| 110 | + @abstractmethod |
101 | 111 | def close(self) -> None: |
102 | | - raise NotImplementedError |
| 112 | + pass |
0 commit comments