add pre-commit
This commit is contained in:
parent
f197b2e3d2
commit
c6cd296108
@ -12,8 +12,8 @@
|
||||
|
||||
Manus 非常棒,但 OpenManus 无需邀请码即可实现任何创意 🛫!
|
||||
|
||||
我们的团队成员 [@mannaandpoem](https://github.com/mannaandpoem) [@XiangJinyu](https://github.com/XiangJinyu) [@MoshiQAQ](https://github.com/MoshiQAQ) [@didiforgithub](https://github.com/didiforgithub) https://github.com/stellaHSR 来自 [@MetaGPT](https://github.com/geekan/MetaGPT) 组织,我们在 3
|
||||
小时内完成了原型开发并持续迭代中!
|
||||
我们的团队成员 [@Xinbin Liang](https://github.com/mannaandpoem) 和 [@Jinyu Xiang](https://github.com/XiangJinyu)(核心作者),以及 [@Zhaoyang Yu](https://github.com/MoshiQAQ)、[@Jiayi Zhang](https://github.com/didiforgithub) 和 [@Sirui Hong](https://github.com/stellaHSR),来自 [@MetaGPT](https://github.com/geekan/MetaGPT)团队。我们在 3
|
||||
小时内完成了开发并持续迭代中!
|
||||
|
||||
这是一个简洁的实现方案,欢迎任何建议、贡献和反馈!
|
||||
|
||||
|
@ -33,17 +33,31 @@ class ProxySettings(BaseModel):
|
||||
|
||||
class BrowserSettings(BaseModel):
|
||||
headless: bool = Field(False, description="Whether to run browser in headless mode")
|
||||
disable_security: bool = Field(True, description="Disable browser security features")
|
||||
extra_chromium_args: List[str] = Field(default_factory=list, description="Extra arguments to pass to the browser")
|
||||
chrome_instance_path: Optional[str] = Field(None, description="Path to a Chrome instance to use")
|
||||
wss_url: Optional[str] = Field(None, description="Connect to a browser instance via WebSocket")
|
||||
cdp_url: Optional[str] = Field(None, description="Connect to a browser instance via CDP")
|
||||
proxy: Optional[ProxySettings] = Field(None, description="Proxy settings for the browser")
|
||||
disable_security: bool = Field(
|
||||
True, description="Disable browser security features"
|
||||
)
|
||||
extra_chromium_args: List[str] = Field(
|
||||
default_factory=list, description="Extra arguments to pass to the browser"
|
||||
)
|
||||
chrome_instance_path: Optional[str] = Field(
|
||||
None, description="Path to a Chrome instance to use"
|
||||
)
|
||||
wss_url: Optional[str] = Field(
|
||||
None, description="Connect to a browser instance via WebSocket"
|
||||
)
|
||||
cdp_url: Optional[str] = Field(
|
||||
None, description="Connect to a browser instance via CDP"
|
||||
)
|
||||
proxy: Optional[ProxySettings] = Field(
|
||||
None, description="Proxy settings for the browser"
|
||||
)
|
||||
|
||||
|
||||
class AppConfig(BaseModel):
|
||||
llm: Dict[str, LLMSettings]
|
||||
browser_config: Optional[BrowserSettings] = Field(None, description="Browser configuration")
|
||||
browser_config: Optional[BrowserSettings] = Field(
|
||||
None, description="Browser configuration"
|
||||
)
|
||||
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
@ -112,14 +126,18 @@ class Config:
|
||||
proxy_settings = None
|
||||
|
||||
if proxy_config and proxy_config.get("server"):
|
||||
proxy_settings = ProxySettings(**{
|
||||
k: v for k, v in proxy_config.items()
|
||||
proxy_settings = ProxySettings(
|
||||
**{
|
||||
k: v
|
||||
for k, v in proxy_config.items()
|
||||
if k in ["server", "username", "password"] and v
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
# filter valid browser config parameters.
|
||||
valid_browser_params = {
|
||||
k: v for k, v in browser_config.items()
|
||||
k: v
|
||||
for k, v in browser_config.items()
|
||||
if k in BrowserSettings.__annotations__ and v is not None
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,7 @@ from typing import Optional
|
||||
|
||||
from browser_use import Browser as BrowserUseBrowser
|
||||
from browser_use import BrowserConfig
|
||||
from browser_use.browser.context import BrowserContext
|
||||
from browser_use.browser.context import BrowserContextConfig
|
||||
from browser_use.browser.context import BrowserContext, BrowserContextConfig
|
||||
from browser_use.dom.service import DomService
|
||||
from pydantic import Field, field_validator
|
||||
from pydantic_core.core_schema import ValidationInfo
|
||||
@ -13,6 +12,7 @@ from pydantic_core.core_schema import ValidationInfo
|
||||
from app.config import config
|
||||
from app.tool.base import BaseTool, ToolResult
|
||||
|
||||
|
||||
MAX_LENGTH = 2000
|
||||
|
||||
_BROWSER_DESCRIPTION = """
|
||||
@ -116,12 +116,16 @@ class BrowserUseTool(BaseTool):
|
||||
browser_config_kwargs["proxy"] = ProxySettings(
|
||||
server=config.browser_config.proxy.server,
|
||||
username=config.browser_config.proxy.username,
|
||||
password=config.browser_config.proxy.password
|
||||
password=config.browser_config.proxy.password,
|
||||
)
|
||||
|
||||
browser_attrs = [
|
||||
"headless", "disable_security", "extra_chromium_args",
|
||||
"chrome_instance_path", "wss_url", "cdp_url"
|
||||
"headless",
|
||||
"disable_security",
|
||||
"extra_chromium_args",
|
||||
"chrome_instance_path",
|
||||
"wss_url",
|
||||
"cdp_url",
|
||||
]
|
||||
|
||||
for attr in browser_attrs:
|
||||
@ -136,9 +140,11 @@ class BrowserUseTool(BaseTool):
|
||||
context_config = BrowserContextConfig()
|
||||
|
||||
# if there is context config in the config, use it.
|
||||
if (config.browser_config and
|
||||
hasattr(config.browser_config, 'new_context_config') and
|
||||
config.browser_config.new_context_config):
|
||||
if (
|
||||
config.browser_config
|
||||
and hasattr(config.browser_config, "new_context_config")
|
||||
and config.browser_config.new_context_config
|
||||
):
|
||||
context_config = config.browser_config.new_context_config
|
||||
|
||||
self.context = await self.browser.new_context(context_config)
|
||||
@ -217,7 +223,9 @@ class BrowserUseTool(BaseTool):
|
||||
|
||||
elif action == "get_html":
|
||||
html = await context.get_page_html()
|
||||
truncated = html[:MAX_LENGTH] + "..." if len(html) > MAX_LENGTH else html
|
||||
truncated = (
|
||||
html[:MAX_LENGTH] + "..." if len(html) > MAX_LENGTH else html
|
||||
)
|
||||
return ToolResult(output=truncated)
|
||||
|
||||
elif action == "get_text":
|
||||
|
Loading…
x
Reference in New Issue
Block a user