mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-27 17:56:23 +02:00
Revert "Merge branch 'dynamic_think' into 'mgx_ops'"
This reverts merge request !98
This commit is contained in:
parent
476e6256a7
commit
de27855c56
8 changed files with 60 additions and 154 deletions
|
|
@ -12,7 +12,7 @@ from metagpt.tools.libs import (
|
|||
# web_scraping,
|
||||
# email_login,
|
||||
terminal,
|
||||
editor,
|
||||
file_manager,
|
||||
browser,
|
||||
deployer,
|
||||
git,
|
||||
|
|
@ -27,7 +27,7 @@ _ = (
|
|||
# web_scraping,
|
||||
# email_login,
|
||||
terminal,
|
||||
editor,
|
||||
file_manager,
|
||||
browser,
|
||||
deployer,
|
||||
git,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from playwright.async_api import async_playwright
|
||||
|
||||
from metagpt.const import DEFAULT_WORKSPACE_ROOT
|
||||
|
|
@ -7,10 +5,10 @@ from metagpt.tools.tool_registry import register_tool
|
|||
from metagpt.utils.report import BrowserReporter
|
||||
|
||||
|
||||
@register_tool(tags=["web", "browse", "scrape"])
|
||||
@register_tool()
|
||||
class Browser:
|
||||
"""
|
||||
A tool for browsing the web and scraping. Don't initialize a new instance of this class if one already exists.
|
||||
A tool for browsing the web. Don't initialize a new instance of this class if one already exists.
|
||||
Note: Combine searching and scrolling together to achieve most effective browsing. DON'T stick to one method.
|
||||
"""
|
||||
|
||||
|
|
@ -33,7 +31,7 @@ class Browser:
|
|||
self.current_page = page
|
||||
self.current_page_url = url
|
||||
print("Now on page ", url)
|
||||
await self._view()
|
||||
print(await self._view())
|
||||
|
||||
async def open_new_page(self, url: str):
|
||||
"""open a new page in the browser and view the page"""
|
||||
|
|
@ -53,12 +51,6 @@ class Browser:
|
|||
else:
|
||||
print(f"Page not found: {url}")
|
||||
|
||||
async def _view_page_html(self, keep_len: int = 5000) -> str:
|
||||
"""view the HTML content of current page, return the HTML content as a string. When executed, the content will be printed out"""
|
||||
html = await self.current_page.content()
|
||||
html_content = html.strip()[:keep_len]
|
||||
return html_content
|
||||
|
||||
async def search_content_all(self, search_term: str) -> list[dict]:
|
||||
"""search all occurences of search term in the current page and return the search results with their position.
|
||||
Useful if you have a keyword or sentence in mind and want to quickly narrow down the content relevant to it.
|
||||
|
|
@ -150,12 +142,10 @@ class Browser:
|
|||
await self.current_page.screenshot(path=path)
|
||||
print(f"Screenshot saved to: {path}")
|
||||
|
||||
async def _view(self, keep_len: int = 5000) -> str:
|
||||
async def _view(self) -> str:
|
||||
"""simulate human viewing the current page, return the visible text with links"""
|
||||
visible_text_with_links = await self.current_page.evaluate(VIEW_CONTENT_JS)
|
||||
print("The visible text and their links (if any): ", visible_text_with_links[:keep_len])
|
||||
# html_content = await self._view_page_html(keep_len=keep_len)
|
||||
# print("The html content: ", html_content)
|
||||
return visible_text_with_links
|
||||
|
||||
async def scroll_current_page(self, offset: int = 500):
|
||||
"""scroll the current page by offset pixels, negative value means scrolling up, will print out observed content after scrolling"""
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class FileBlock(BaseModel):
|
|||
|
||||
|
||||
@register_tool()
|
||||
class Editor:
|
||||
class FileManager:
|
||||
"""A tool for reading, understanding, writing, and editing files"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
|
|
@ -42,8 +42,6 @@ class Editor:
|
|||
"""
|
||||
Search symbol in all files under root_path, return the context of symbol with window size
|
||||
Useful for locating class or function in a large codebase. Example symbol can be "def some_function", "class SomeClass", etc.
|
||||
When both search_content and find_file are feasible, search_content is used in priority.
|
||||
In searching, attempt different symbols of different granualities, e.g. "def some_function", "class SomeClass", a certain line of code, etc.
|
||||
|
||||
Args:
|
||||
symbol (str): The symbol to search.
|
||||
|
|
@ -60,9 +58,6 @@ class Editor:
|
|||
symbol: str = Field(default="", description="The symbol of interest in the block, empty if not applicable.")
|
||||
symbol_line: int = Field(default=-1, description="The line number of the symbol in the file, -1 if not applicable")
|
||||
"""
|
||||
if not os.path.exists(root_path):
|
||||
print(f"Currently at {os.getcwd()}. Path {root_path} does not exist.")
|
||||
return None
|
||||
for root, _, files in os.walk(root_path or "."):
|
||||
for file in files:
|
||||
file_path = os.path.join(root, file)
|
||||
|
|
@ -88,9 +83,6 @@ class Editor:
|
|||
)
|
||||
self.resource.report(result.file_path, "path")
|
||||
return result
|
||||
print(
|
||||
"symbol not found, you may try searching another one, or break down your search term to search a part of it"
|
||||
)
|
||||
return None
|
||||
|
||||
def write_content(self, file_path: str, start_line: int, end_line: int, new_block_content: str = "") -> str:
|
||||
|
|
@ -120,8 +112,8 @@ class Editor:
|
|||
|
||||
# Lint the modified temporary file
|
||||
lint_passed, lint_message = self._lint_file(temp_file_path)
|
||||
# if not lint_passed:
|
||||
# return f"Linting the content at a temp file, failed with:\n{lint_message}"
|
||||
if not lint_passed:
|
||||
return f"Linting the content at a temp file, failed with:\n{lint_message}"
|
||||
|
||||
# If linting passes, overwrite the original file with the temporary file
|
||||
shutil.move(temp_file_path, file_path)
|
||||
Loading…
Add table
Add a link
Reference in a new issue