fix conflict

This commit is contained in:
seehi 2024-08-12 17:36:21 +08:00
commit 24e03d97ac
25 changed files with 245 additions and 179 deletions

View file

@ -10,7 +10,7 @@ from pydantic import BaseModel, ConfigDict
from metagpt.logs import logger
from metagpt.tools.tool_registry import register_tool
from metagpt.utils import read_docx
from metagpt.utils.common import aread_bin, awrite_bin, run_coroutine_sync
from metagpt.utils.common import aread_bin, awrite_bin
from metagpt.utils.repo_to_markdown import is_text_file
from metagpt.utils.report import EditorReporter
@ -44,13 +44,13 @@ class Editor(BaseModel):
# self.resource.report(path, "path")
return f"The writing/coding the of the file {os.path.basename(path)}' is now completed. The file '{os.path.basename(path)}' has been successfully created."
def read(self, path: str) -> FileBlock:
async def read(self, path: str) -> FileBlock:
"""Read the whole content of a file. Using absolute paths as the argument for specifying the file location."""
is_text, mime_type = run_coroutine_sync(is_text_file, path)
is_text, mime_type = await is_text_file(path)
if is_text:
lines = self._read_text(path)
elif mime_type == "application/pdf":
lines = self._read_pdf(path)
lines = await self._read_pdf(path)
elif mime_type in {
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
@ -58,7 +58,7 @@ class Editor(BaseModel):
"application/vnd.openxmlformats-officedocument.wordprocessingml.template",
"application/vnd.ms-word.template.macroEnabled.12",
}:
lines = self._read_docx(path)
lines = await self._read_docx(path)
else:
return FileBlock(file_path=str(path), block_content="")
self.resource.report(str(path), "path")
@ -224,8 +224,8 @@ class Editor(BaseModel):
return lines
@staticmethod
def _read_pdf(path: Union[str, Path]) -> List[str]:
result = run_coroutine_sync(Editor._omniparse_read_file, path)
async def _read_pdf(path: Union[str, Path]) -> List[str]:
result = await Editor._omniparse_read_file(path)
if result:
return result
@ -236,8 +236,8 @@ class Editor(BaseModel):
return [i.text for i in lines]
@staticmethod
def _read_docx(path: Union[str, Path]) -> List[str]:
result = run_coroutine_sync(Editor._omniparse_read_file, path)
async def _read_docx(path: Union[str, Path]) -> List[str]:
result = await Editor._omniparse_read_file(path)
if result:
return result
return read_docx(str(path))

View file

@ -21,7 +21,6 @@ from metagpt.actions.requirement_analysis.trd import (
from metagpt.const import ASSISTANT_ALIAS, DEFAULT_WORKSPACE_ROOT, TEST_DATA_PATH
from metagpt.context import Context
from metagpt.logs import ToolLogItem, log_tool_output, logger
from metagpt.tools.tool_registry import register_tool
from metagpt.utils.common import aread
from metagpt.utils.cost_manager import CostManager
@ -86,7 +85,6 @@ async def mock_asearch_acknowledgement(use_case_actors: str):
return await aread(filename=TEST_DATA_PATH / "requirements/1.acknowledge.md")
@register_tool(tags=["system design", "write trd", "Write a TRD"])
async def write_trd(
use_case_actors: str,
user_requirements: str,
@ -155,7 +153,6 @@ async def write_trd(
return trd
@register_tool(tags=["system design", "write software framework", "Write a software framework based on a TRD"])
async def write_framework(
use_case_actors: str,
trd: str,
@ -240,7 +237,6 @@ async def write_framework(
return "## Software Framework" + "".join([f"\n- {i}" for i in file_list])
@register_tool(tags=["system design", "write trd and framework", "Write a TRD and the framework"])
async def write_trd_and_framework(
use_case_actors: str,
user_requirements: str,

View file

@ -26,6 +26,8 @@ class GoogleAPIWrapper(BaseModel):
api_key: str
cse_id: str
discovery_service_url: Optional[str] = None
loop: Optional[asyncio.AbstractEventLoop] = None
executor: Optional[futures.Executor] = None
proxy: Optional[str] = None
@ -56,7 +58,7 @@ class GoogleAPIWrapper(BaseModel):
@property
def google_api_client(self):
build_kwargs = {"developerKey": self.api_key}
build_kwargs = {"developerKey": self.api_key, "discoveryServiceUrl": self.discovery_service_url}
if self.proxy:
parse_result = urlparse(self.proxy)
proxy_type = parse_result.scheme

View file

@ -39,11 +39,9 @@ class PlaywrightWrapper(BaseModel):
if not any(str.startswith(i, "--proxy-server=") for i in args):
launch_kwargs["proxy"] = {"server": self.proxy}
if "ignore_https_errors" in kwargs:
self.context_kwargs["ignore_https_errors"] = kwargs["ignore_https_errors"]
if "java_script_enabled" in kwargs:
self.context_kwargs["java_script_enabled"] = kwargs["java_script_enabled"]
for key in ["ignore_https_errors", "java_script_enabled", "extra_http_headers", "user_agent"]:
if key in kwargs:
self.context_kwargs[key] = kwargs[key]
async def run(self, url: str, *urls: str, per_page_timeout: float = None) -> WebPage | list[WebPage]:
async with async_playwright() as ap: