🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
integrate web scraping tool
yzlin88c4c8c90d25
diff --git a/metagpt/tools/__init__.py b/metagpt/tools/__init__.pyindex f18d1d276..bb87f1b62 100644--- a/metagpt/tools/__init__.py+++ b/metagpt/tools/__init__.py@@ -11,7 +11,7 @@ from metagpt.tools import tool_types # this registers all tool typesfrom metagpt.tools import libs # this registers all toolsfrom metagpt.tools.tool_registry import TOOL_REGISTRY-_, _, _ = tool_types, libs, TOOL_REGISTRY # Avoid pre-commit error+_ = tool_types, libs, TOOL_REGISTRY # Avoid pre-commit errorclass SearchEngineType(Enum):diff --git a/metagpt/tools/functions/libs/scrape_web/__init__.py b/metagpt/tools/functions/libs/scrape_web/__init__.pydeleted file mode 100644index d5cd1524b..000000000--- a/metagpt/tools/functions/libs/scrape_web/__init__.py+++ /dev/null@@ -1 +0,0 @@-from metagpt.tools.functions.libs.scrape_web.scrape_web import scrape_webdiff --git a/metagpt/tools/libs/__init__.py b/metagpt/tools/libs/__init__.pyindex b576997c9..442f57149 100644--- a/metagpt/tools/libs/__init__.py+++ b/metagpt/tools/libs/__init__.py@@ -9,6 +9,7 @@ from metagpt.tools.libs import (feature_engineering,sd_engine,gpt_v_generator,+ web_scrapping,)-_, _, _, _ = data_preprocess, feature_engineering, sd_engine, gpt_v_generator # Avoid pre-commit error+_ = data_preprocess, feature_engineering, sd_engine, gpt_v_generator, web_scrapping # Avoid pre-commit errordiff --git a/metagpt/tools/functions/libs/scrape_web/scrape_web.py b/metagpt/tools/libs/web_scrapping.pysimilarity index 76%rename from metagpt/tools/functions/libs/scrape_web/scrape_web.pyrename to metagpt/tools/libs/web_scrapping.pyindex e68ce0e64..e8e73f123 100644--- a/metagpt/tools/functions/libs/scrape_web/scrape_web.py+++ b/metagpt/tools/libs/web_scrapping.py@@ -1,9 +1,10 @@-import asyncio-+from metagpt.tools.tool_data_type import ToolTypeEnum+from metagpt.tools.tool_registry import register_toolfrom metagpt.tools.web_browser_engine_playwright import PlaywrightWrapper-async def scrape_web(url, *urls):+@register_tool(tool_type=ToolTypeEnum.WEBSCRAPING.value)+async def scrape_web_playwright(url, *urls):"""Scrape and save the HTML structure and inner text content of a web page using Playwright.@@ -19,5 +20,3 @@ async def scrape_web(url, *urls):# Return the inner text content of the web pagereturn {"inner_text": web.inner_text, "html": web.html}--# 需要改三个地方: yaml, 对应路径下init, MetaGPT/metagpt/prompts/ml_engineer.py中ML_MODULE_MAPdiff --git a/metagpt/tools/functions/schemas/scrape_web.yml b/metagpt/tools/schemas/web_scrapping/scrape_web_playwright.ymlsimilarity index 96%rename from metagpt/tools/functions/schemas/scrape_web.ymlrename to metagpt/tools/schemas/web_scrapping/scrape_web_playwright.ymlindex ecca3fbed..a6ff7d6c7 100644--- a/metagpt/tools/functions/schemas/scrape_web.yml+++ b/metagpt/tools/schemas/web_scrapping/scrape_web_playwright.yml@@ -1,4 +1,4 @@-scrape_web:+scrape_web_playwright:type: async funcitondescription: "Scrape and save the HTML structure and inner text content of a web page using Playwright."parameters:diff --git a/metagpt/tools/tool_data_type.py b/metagpt/tools/tool_data_type.pyindex 45fb539a6..0c4eea4cc 100644--- a/metagpt/tools/tool_data_type.py+++ b/metagpt/tools/tool_data_type.py@@ -11,6 +11,7 @@ class ToolTypeEnum(Enum):MODEL_EVALUATE = "model_evaluate"STABLE_DIFFUSION = "stable_diffusion"IMAGE2WEBPAGE = "image2webpage"+ WEBSCRAPING = "web_scraping"OTHER = "other"def __missing__(self, key):diff --git a/metagpt/tools/tool_types.py b/metagpt/tools/tool_types.pyindex b5b233d53..35c0772b1 100644--- a/metagpt/tools/tool_types.py+++ b/metagpt/tools/tool_types.py@@ -12,7 +12,7 @@ from metagpt.tools.tool_registry import register_tool_type@register_tool_typeclass EDA(ToolType):name: str = ToolTypeEnum.EDA.value- desc: str = "Useful for performing exploratory data analysis"+ desc: str = "For performing exploratory data analysis"@register_tool_type@@ -56,6 +56,12 @@ class Image2Webpage(ToolType):usage_prompt: str = IMAGE2WEBPAGE_PROMPT+@register_tool_type+class WebScraping(ToolType):+ name: str = ToolTypeEnum.WEBSCRAPING.value+ desc: str = "For scraping data from web pages."++@register_tool_typeclass Other(ToolType):name: str = ToolTypeEnum.OTHER.valuediff --git a/metagpt/tools/web_browser_engine_playwright.py b/metagpt/tools/web_browser_engine_playwright.pyindex a45f6a12e..15c8a78d7 100644--- a/metagpt/tools/web_browser_engine_playwright.py+++ b/metagpt/tools/web_browser_engine_playwright.py@@ -12,7 +12,6 @@ from typing import Literalfrom playwright.async_api import async_playwright-from metagpt.config import CONFIGfrom metagpt.logs import loggerfrom metagpt.utils.parse_html import WebPage@@ -32,6 +31,8 @@ class PlaywrightWrapper:launch_kwargs: dict | None = None,**kwargs,) -> None:+ from metagpt.config import CONFIG+if browser_type is None:browser_type = CONFIG.playwright_browser_typeself.browser_type = browser_type