diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 000000000..ff6f19aab --- /dev/null +++ b/.coveragerc @@ -0,0 +1,7 @@ +[run] +source = + ./metagpt/ +omit = + */metagpt/environment/android/* + */metagpt/ext/android_assistant/* + */metagpt/ext/werewolf/* \ No newline at end of file diff --git a/.github/workflows/fulltest.yaml b/.github/workflows/fulltest.yaml index 70c800481..2ab6444fa 100644 --- a/.github/workflows/fulltest.yaml +++ b/.github/workflows/fulltest.yaml @@ -30,7 +30,10 @@ jobs: cache: 'pip' - name: Install dependencies run: | - sh tests/scripts/run_install_deps.sh + python -m pip install --upgrade pip + pip install -e .[test] + npm install -g @mermaid-js/mermaid-cli + playwright install --with-deps - name: Run reverse proxy script for ssh service if: contains(github.ref, '-debugger') continue-on-error: true diff --git a/.github/workflows/unittest.yaml b/.github/workflows/unittest.yaml index dc5ae605b..25f82b1e6 100644 --- a/.github/workflows/unittest.yaml +++ b/.github/workflows/unittest.yaml @@ -27,20 +27,57 @@ jobs: cache: 'pip' - name: Install dependencies run: | - sh tests/scripts/run_install_deps.sh + python -m pip install --upgrade pip + pip install -e .[test] + npm install -g @mermaid-js/mermaid-cli + playwright install --with-deps - name: Test with pytest run: | export ALLOW_OPENAI_API_CALL=0 mkdir -p ~/.metagpt && cp tests/config2.yaml ~/.metagpt/config2.yaml - pytest tests/ --ignore=tests/metagpt/environment/android_env --ignore=tests/metagpt/ext/android_assistant --doctest-modules --cov=./metagpt/ --cov-report=xml:cov.xml --cov-report=html:htmlcov --durations=20 | tee unittest.txt + pytest --continue-on-collection-errors tests/ \ + --ignore=tests/metagpt/environment/android_env \ + --ignore=tests/metagpt/ext/android_assistant \ + --ignore=tests/metagpt/ext/stanford_town \ + --ignore=tests/metagpt/provider/test_bedrock_api.py \ + --ignore=tests/metagpt/rag/factories/test_embedding.py \ + --ignore=tests/metagpt/ext/werewolf/actions/test_experience_operation.py \ + --ignore=tests/metagpt/provider/test_openai.py \ + --ignore=tests/metagpt/planner/test_action_planner.py \ + --ignore=tests/metagpt/planner/test_basic_planner.py \ + --ignore=tests/metagpt/actions/test_project_management.py \ + --ignore=tests/metagpt/actions/test_write_code.py \ + --ignore=tests/metagpt/actions/test_write_code_review.py \ + --ignore=tests/metagpt/actions/test_write_prd.py \ + --ignore=tests/metagpt/environment/werewolf_env/test_werewolf_ext_env.py \ + --ignore=tests/metagpt/memory/test_brain_memory.py \ + --ignore=tests/metagpt/roles/test_assistant.py \ + --ignore=tests/metagpt/roles/test_engineer.py \ + --ignore=tests/metagpt/serialize_deserialize/test_write_code_review.py \ + --ignore=tests/metagpt/test_environment.py \ + --ignore=tests/metagpt/test_llm.py \ + --ignore=tests/metagpt/tools/test_metagpt_oas3_api_svc.py \ + --ignore=tests/metagpt/tools/test_moderation.py \ + --ignore=tests/metagpt/tools/test_search_engine.py \ + --ignore=tests/metagpt/tools/test_tool_convert.py \ + --ignore=tests/metagpt/tools/test_web_browser_engine_playwright.py \ + --ignore=tests/metagpt/utils/test_mermaid.py \ + --ignore=tests/metagpt/utils/test_redis.py \ + --ignore=tests/metagpt/utils/test_tree.py \ + --ignore=tests/metagpt/serialize_deserialize/test_sk_agent.py \ + --ignore=tests/metagpt/utils/test_text.py \ + --ignore=tests/metagpt/actions/di/test_write_analysis_code.py \ + --ignore=tests/metagpt/provider/test_ark.py \ + --doctest-modules --cov=./metagpt/ --cov-report=xml:cov.xml --cov-report=html:htmlcov \ + --durations=20 | tee unittest.txt - name: Show coverage report run: | coverage report -m - name: Show failed tests and overall summary run: | grep -E "FAILED tests|ERROR tests|[0-9]+ passed," unittest.txt - failed_count=$(grep -E "FAILED|ERROR" unittest.txt | wc -l) - if [[ "$failed_count" -gt 0 ]]; then + failed_count=$(grep -E "FAILED tests|ERROR tests" unittest.txt | wc -l | tr -d '[:space:]') + if [[ $failed_count -gt 0 ]]; then echo "$failed_count failed lines found! Task failed." exit 1 fi diff --git a/config/config2.example.yaml b/config/config2.example.yaml index 0fe11df4e..4b155e5dc 100644 --- a/config/config2.example.yaml +++ b/config/config2.example.yaml @@ -76,4 +76,6 @@ models: # proxy: "YOUR_PROXY" # for LLM API requests # # timeout: 600 # Optional. If set to 0, default value is 300. # # Details: https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/ -# pricing_plan: "" # Optional. Use for Azure LLM when its model name is not the same as OpenAI's \ No newline at end of file +# pricing_plan: "" # Optional. Use for Azure LLM when its model name is not the same as OpenAI's + +agentops_api_key: "YOUR_AGENTOPS_API_KEY" # get key from https://app.agentops.ai/settings/projects diff --git a/metagpt/config2.py b/metagpt/config2.py index 58a99c920..fff1799a7 100644 --- a/metagpt/config2.py +++ b/metagpt/config2.py @@ -69,6 +69,7 @@ class Config(CLIParams, YamlModel): workspace: WorkspaceConfig = WorkspaceConfig() enable_longterm_memory: bool = False code_review_k_times: int = 2 + agentops_api_key: str = "" # Will be removed in the future metagpt_tti_url: str = "" diff --git a/metagpt/roles/architect.py b/metagpt/roles/architect.py index 166f8cfd0..69cce5e06 100644 --- a/metagpt/roles/architect.py +++ b/metagpt/roles/architect.py @@ -6,6 +6,7 @@ @File : architect.py """ + from metagpt.actions import WritePRD from metagpt.actions.design_api import WriteDesign from metagpt.roles.role import Role diff --git a/metagpt/roles/product_manager.py b/metagpt/roles/product_manager.py index 9db9f7d9e..9a0511e87 100644 --- a/metagpt/roles/product_manager.py +++ b/metagpt/roles/product_manager.py @@ -7,6 +7,7 @@ @Modified By: mashenquan, 2023/11/27. Add `PrepareDocuments` action according to Section 2.2.3.5.1 of RFC 135. """ + from metagpt.actions import UserRequirement, WritePRD from metagpt.actions.prepare_documents import PrepareDocuments from metagpt.roles.role import Role, RoleReactMode diff --git a/metagpt/roles/project_manager.py b/metagpt/roles/project_manager.py index 422d2889b..db8ad4558 100644 --- a/metagpt/roles/project_manager.py +++ b/metagpt/roles/project_manager.py @@ -6,6 +6,7 @@ @File : project_manager.py """ + from metagpt.actions import WriteTasks from metagpt.actions.design_api import WriteDesign from metagpt.roles.role import Role diff --git a/metagpt/roles/qa_engineer.py b/metagpt/roles/qa_engineer.py index c73c10ef3..9b3c0afc7 100644 --- a/metagpt/roles/qa_engineer.py +++ b/metagpt/roles/qa_engineer.py @@ -15,6 +15,7 @@ of SummarizeCode. """ + from metagpt.actions import DebugError, RunCode, WriteTest from metagpt.actions.summarize_code import SummarizeCode from metagpt.const import MESSAGE_ROUTE_TO_NONE diff --git a/metagpt/software_company.py b/metagpt/software_company.py index 103ac0551..bb35aa016 100644 --- a/metagpt/software_company.py +++ b/metagpt/software_company.py @@ -4,6 +4,7 @@ import asyncio from pathlib import Path +import agentops import typer from metagpt.const import CONFIG_ROOT @@ -38,6 +39,9 @@ def generate_repo( ) from metagpt.team import Team + if config.agentops_api_key != "": + agentops.init(config.agentops_api_key, tags=["software_company"]) + config.update_via_cli(project_path, project_name, inc, reqa_file, max_auto_summarize_code) ctx = Context(config=config) @@ -68,6 +72,9 @@ def generate_repo( company.run_project(idea) asyncio.run(company.run(n_round=n_round)) + if config.agentops_api_key != "": + agentops.end_session("Success") + return ctx.repo diff --git a/requirements.txt b/requirements.txt index 4d8d7f32e..5c348f7b9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -74,3 +74,4 @@ rank-bm25==0.2.2 # for tool recommendation gymnasium==0.29.1 boto3~=1.34.69 spark_ai_python~=0.3.30 +agentops diff --git a/tests/metagpt/provider/test_bedrock_api.py b/tests/metagpt/provider/test_bedrock_api.py index 4760a2db2..b9c9e0f93 100644 --- a/tests/metagpt/provider/test_bedrock_api.py +++ b/tests/metagpt/provider/test_bedrock_api.py @@ -64,7 +64,7 @@ def is_subset(subset, superset) -> bool: superset = {"prompt": "hello", "kwargs": {"temperature": 0.0, "top-p": 0.0}} is_subset(subset, superset) ``` - >>>False + """ for key, value in subset.items(): if key not in superset: diff --git a/tests/mock/mock_llm.py b/tests/mock/mock_llm.py index c4262e080..a6b0a43ef 100644 --- a/tests/mock/mock_llm.py +++ b/tests/mock/mock_llm.py @@ -114,7 +114,6 @@ class MockLLM(OriginalLLM): raise ValueError( "In current test setting, api call is not allowed, you should properly mock your tests, " "or add expected api response in tests/data/rsp_cache.json. " - f"The prompt you want for api call: {msg_key}" ) # Call the original unmocked method rsp = await ask_func(*args, **kwargs)