diff --git a/metagpt/actions/di/detect_intent.py b/metagpt/actions/di/detect_intent.py index d9b587e5c..68e7b5e62 100644 --- a/metagpt/actions/di/detect_intent.py +++ b/metagpt/actions/di/detect_intent.py @@ -29,7 +29,7 @@ class SOPItemDef(BaseModel): class SOPItem(Enum): SOFTWARE_DEVELOPMENT = SOPItemDef( name="software development", - description="Intentions related to or including software development, such as developing or building software, games, app, websites, etc. Excluding bug fixes, report any issues, environment setup, operations and pip install.", + description="Software development intention including developing or building software, games, app, websites, etc. EXCLUDING bug fixes, report any issues, environment setup, terminal operations, and pip install.", sop=[ "Writes a PRD based on software requirements.", "Writes a design to the project repository, based on the PRD of the project.", @@ -38,35 +38,29 @@ class SOPItem(Enum): "Stage and commit changes for the project repository using Git.", ], ) - FIX_BUGS = SOPItemDef( - name="fix bugs", - description="Fix bugs in a given project.", - sop=[ - "Fix bugs in the project repository.", - "Stage and commit changes for the project repository using Git.", - ], - ) - FORMAT_REPO = SOPItemDef( - name="format repo", - description="download repository from git and format the project to MetaGPT project", - sop=[ - "Imports a project from a Git website and formats it to MetaGPT project format to enable incremental appending requirements.", - "Stage and commit changes for the project repository using Git.", - ], - ) - WEBPAGE_IMITATION = SOPItemDef( - name="webpage_imitation", - description="webpage browsing, imitation and other applications etc.", - sop=[ - "Utilize Selenium and WebDriver for rendering.", - "Capture a screenshot of the rendered webpage.", - "Convert image to a webpage including HTML, CSS and JS in one go.", - ], + # FIX_BUGS = SOPItemDef( + # name="fix bugs", + # description="Fix bugs in a given project.", + # sop=[ + # "Fix bugs in the project repository.", + # "Stage and commit changes for the project repository using Git.", + # ], + # ) + # FORMAT_REPO = SOPItemDef( + # name="format repo", + # description="download repository from git and format the project to MetaGPT project", + # sop=[ + # "Imports a project from a Git website and formats it to MetaGPT project format to enable incremental appending requirements.", + # "Stage and commit changes for the project repository using Git.", + # ], + # ) + WEB_OPERATION = SOPItemDef( + name="web operation", + description="web browsing, scraping, imitation and other interaction with the web", ) OTHER = SOPItemDef( name="other", - description="Other intentions that do not fall into the above categories, including data science, machine learning, deep learning and text-to-image etc.", - sop=[], + description="Other intentions that do not fall into the above categories, including data science, data analysis, machine learning, deep learning and text-to-image etc.", ) @property @@ -128,7 +122,13 @@ class DetectIntent(Action): async def main(): # Example usage of the DetectIntent action - user_requirements = ["Develop a 2048 game.", "Run data analysis on sklearn wine dataset"] + user_requirements = [ + "Develop a 2048 game.", + "Run data analysis on sklearn wine dataset", + "帮我把pip的源设置成:https://pypi.tuna.tsinghua.edu.cn/simple", + "This is a website url does not require login: https://demosc.chinaz.net/Files/DownLoad//moban/202404/moban7767 please write a similar web page,developed in vue language, The package.json dependency must be generated", + "I would like to imitate the website available at https://demosc.chinaz.net/Files/DownLoad//moban/202404/moban7767. Could you please browse through it?", + ] detect_intent = DetectIntent() for user_requirement in user_requirements: diff --git a/metagpt/tools/tool_convert.py b/metagpt/tools/tool_convert.py index 829269b1b..a84cbeea0 100644 --- a/metagpt/tools/tool_convert.py +++ b/metagpt/tools/tool_convert.py @@ -20,8 +20,7 @@ def convert_code_to_tool_schema(obj, include: list[str] = None) -> dict: continue # method_doc = inspect.getdoc(method) method_doc = get_class_method_docstring(obj, name) - if method_doc: - schema["methods"][name] = function_docstring_to_schema(method, method_doc) + schema["methods"][name] = function_docstring_to_schema(method, method_doc) elif inspect.isfunction(obj): schema = function_docstring_to_schema(obj, docstring) @@ -39,7 +38,7 @@ def convert_code_to_tool_schema_ast(code: str) -> list[dict]: return visitor.get_tool_schemas() -def function_docstring_to_schema(fn_obj, docstring) -> dict: +def function_docstring_to_schema(fn_obj, docstring="") -> dict: """ Converts a function's docstring into a schema dictionary. diff --git a/tests/metagpt/tools/test_tool_convert.py b/tests/metagpt/tools/test_tool_convert.py index 4798d32b0..5aa53ce4f 100644 --- a/tests/metagpt/tools/test_tool_convert.py +++ b/tests/metagpt/tools/test_tool_convert.py @@ -48,6 +48,14 @@ class DummyClass: pass +class DummySubClass(DummyClass): + """sub class docstring""" + + def sub_method(self, df: pd.DataFrame): + """sub method""" + pass + + def dummy_fn( df: pd.DataFrame, s: str, @@ -117,6 +125,18 @@ def test_convert_code_to_tool_schema_class(): assert schema == expected +def test_convert_code_to_tool_schema_subclass(): + schema = convert_code_to_tool_schema(DummySubClass) + assert "sub_method" in schema["methods"] # sub class method should be included + assert "fit" in schema["methods"] # parent class method should be included + + +def test_convert_code_to_tool_schema_include(): + schema = convert_code_to_tool_schema(DummyClass, include=["fit"]) + assert "fit" in schema["methods"] + assert "transform" not in schema["methods"] + + def test_convert_code_to_tool_schema_function(): expected = { "type": "function",