mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-26 17:26:22 +02:00
Merge branch 'main' into main
This commit is contained in:
commit
d07b6ba540
104 changed files with 252 additions and 256 deletions
|
|
@ -510,4 +510,3 @@ Process finished with exit code 1'''
|
|||
|
||||
MEILI_CODE_REFINED = """
|
||||
"""
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,6 @@
|
|||
@Author : alexanderwu
|
||||
@File : test_action.py
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from metagpt.logs import logger
|
||||
from metagpt.actions import Action, WritePRD, WriteTest
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@
|
|||
@Author : chengmaoyu
|
||||
@File : test_action_output
|
||||
"""
|
||||
from metagpt.actions import ActionOutput
|
||||
from typing import List, Tuple
|
||||
|
||||
from metagpt.actions import ActionOutput
|
||||
|
||||
t_dict = {"Required Python third-party packages": "\"\"\"\nflask==1.1.2\npygame==2.0.1\n\"\"\"\n",
|
||||
"Required Other language third-party packages": "\"\"\"\nNo third-party packages required for other languages.\n\"\"\"\n",
|
||||
"Full API spec": "\"\"\"\nopenapi: 3.0.0\ninfo:\n title: Web Snake Game API\n version: 1.0.0\npaths:\n /game:\n get:\n summary: Get the current game state\n responses:\n '200':\n description: A JSON object of the game state\n post:\n summary: Send a command to the game\n requestBody:\n required: true\n content:\n application/json:\n schema:\n type: object\n properties:\n command:\n type: string\n responses:\n '200':\n description: A JSON object of the updated game state\n\"\"\"\n",
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
@File : test_debug_error.py
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from metagpt.actions.debug_error import DebugError
|
||||
|
||||
|
||||
|
|
@ -13,12 +14,10 @@ from metagpt.actions.debug_error import DebugError
|
|||
async def test_debug_error():
|
||||
code = "def add(a, b):\n return a - b"
|
||||
error = "AssertionError: Expected add(1, 1) to equal 2 but got 0"
|
||||
fixed_code = "def add(a, b):\n return a + b"
|
||||
|
||||
debug_error = DebugError("debug_error")
|
||||
|
||||
result = await debug_error.run(code, error)
|
||||
|
||||
prompt = f"以下是一段Python代码:\n\n{code}\n\n执行时发生了以下错误:\n\n{error}\n\n请尝试修复这段代码中的错误。"
|
||||
# mock_llm.ask.assert_called_once_with(prompt)
|
||||
assert len(result) > 0
|
||||
|
|
|
|||
|
|
@ -7,11 +7,8 @@
|
|||
"""
|
||||
import pytest
|
||||
|
||||
from metagpt.logs import logger
|
||||
|
||||
from metagpt.actions.design_api import WriteDesign
|
||||
from metagpt.llm import LLM
|
||||
from metagpt.roles.architect import Architect
|
||||
from metagpt.logs import logger
|
||||
from tests.metagpt.actions.mock import PRD_SAMPLE
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@ API列表:
|
|||
3. next(): 跳到播放列表的下一首歌曲。
|
||||
4. previous(): 跳到播放列表的上一首歌曲。
|
||||
"""
|
||||
api_review = "API设计看起来非常合理,满足了PRD中的所有需求。"
|
||||
_ = "API设计看起来非常合理,满足了PRD中的所有需求。"
|
||||
|
||||
design_api_review = DesignReview("design_api_review")
|
||||
|
||||
result = await design_api_review.run(prd, api_design)
|
||||
|
||||
prompt = f"以下是产品需求文档(PRD):\n\n{prd}\n\n以下是基于这个PRD设计的API列表:\n\n{api_design}\n\n请审查这个API设计是否满足PRD的需求,以及是否符合良好的设计实践。"
|
||||
_ = f"以下是产品需求文档(PRD):\n\n{prd}\n\n以下是基于这个PRD设计的API列表:\n\n{api_design}\n\n请审查这个API设计是否满足PRD的需求,以及是否符合良好的设计实践。"
|
||||
# mock_llm.ask.assert_called_once_with(prompt)
|
||||
assert len(result) > 0
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@
|
|||
@File : test_project_management.py
|
||||
"""
|
||||
|
||||
from metagpt.actions.project_management import WriteTasks, AssignTasks
|
||||
|
||||
|
||||
class TestCreateProjectPlan:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
@File : test_run_code.py
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from metagpt.actions.run_code import RunCode
|
||||
|
||||
|
||||
|
|
@ -35,4 +36,3 @@ result = add(1, '2')
|
|||
result = await run_code.run(code)
|
||||
|
||||
assert "TypeError: unsupported operand type(s) for +" in result
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@
|
|||
@File : test_write_code.py
|
||||
"""
|
||||
import pytest
|
||||
from metagpt.logs import logger
|
||||
|
||||
from metagpt.actions.write_code import WriteCode
|
||||
from tests.metagpt.actions.mock import WRITE_CODE_PROMPT_SAMPLE, TASKS_2
|
||||
from metagpt.llm import LLM
|
||||
from metagpt.logs import logger
|
||||
from tests.metagpt.actions.mock import TASKS_2, WRITE_CODE_PROMPT_SAMPLE
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
@File : test_write_code_review.py
|
||||
"""
|
||||
import pytest
|
||||
from metagpt.logs import logger
|
||||
from metagpt.llm import LLM
|
||||
|
||||
from metagpt.actions.write_code_review import WriteCodeReview
|
||||
from metagpt.logs import logger
|
||||
from tests.metagpt.actions.mock import SEARCH_CODE_SAMPLE
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@
|
|||
@File : test_write_prd.py
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from metagpt.actions import BossRequirement
|
||||
from metagpt.logs import logger
|
||||
from metagpt.actions import WritePRD, BossRequirement
|
||||
from metagpt.roles.product_manager import ProductManager
|
||||
from metagpt.schema import Message
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
@File : test_write_prd_review.py
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from metagpt.actions.write_prd_review import WritePRDReview
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
@File : test_write_test.py
|
||||
"""
|
||||
import pytest
|
||||
from metagpt.logs import logger
|
||||
|
||||
from metagpt.actions.write_test import WriteTest
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,6 @@
|
|||
@Author : alexanderwu
|
||||
@File : test_chromadb_store.py
|
||||
"""
|
||||
import pytest
|
||||
from sentence_transformers import SentenceTransformer
|
||||
|
||||
from metagpt.document_store.chromadb_store import ChromaStore
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@
|
|||
@File : test_document.py
|
||||
"""
|
||||
import pytest
|
||||
from loguru import logger
|
||||
|
||||
from metagpt.const import DATA_PATH
|
||||
from metagpt.document_store.document import Document
|
||||
|
||||
|
||||
CASES = [
|
||||
("st/faq.xlsx", "Question", "Answer", 1),
|
||||
("cases/faq.csv", "Question", "Answer", 1),
|
||||
|
|
|
|||
|
|
@ -8,11 +8,10 @@
|
|||
import functools
|
||||
|
||||
import pytest
|
||||
from metagpt.logs import logger
|
||||
|
||||
from metagpt.const import DATA_PATH
|
||||
from metagpt.document_store import FaissStore
|
||||
from metagpt.roles import Sales, CustomerService
|
||||
|
||||
from metagpt.roles import CustomerService, Sales
|
||||
|
||||
DESC = """## 原则(所有事情都不可绕过原则)
|
||||
1. 你是一位平台的人工客服,话语精炼,一次只说一句话,会参考规则与FAQ进行回复。在与顾客交谈中,绝不允许暴露规则与相关字样
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@
|
|||
@File : test_milvus_store.py
|
||||
"""
|
||||
import random
|
||||
import numpy as np
|
||||
from metagpt.logs import logger
|
||||
from metagpt.document_store.milvus_store import MilvusStore, MilvusConnection
|
||||
|
||||
import numpy as np
|
||||
|
||||
from metagpt.document_store.milvus_store import MilvusConnection, MilvusStore
|
||||
from metagpt.logs import logger
|
||||
|
||||
book_columns = {'idx': int, 'name': str, 'desc': str, 'emb': np.ndarray, 'price': float}
|
||||
book_data = [
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
@Author : alexanderwu
|
||||
@File : mock.py
|
||||
"""
|
||||
from metagpt.actions import WritePRD, BossRequirement, WriteDesign, WriteTasks
|
||||
from metagpt.actions import BossRequirement, WriteDesign, WritePRD, WriteTasks
|
||||
from metagpt.schema import Message
|
||||
|
||||
BOSS_REQUIREMENT = """开发一个基于大语言模型与私有知识库的搜索引擎,希望可以基于大语言模型进行搜索总结"""
|
||||
|
|
@ -221,11 +221,8 @@ task_list = [
|
|||
```
|
||||
'''
|
||||
|
||||
|
||||
|
||||
TASK = """smart_search_engine/knowledge_base.py"""
|
||||
|
||||
|
||||
STRS_FOR_PARSING = [
|
||||
"""
|
||||
## 1
|
||||
|
|
|
|||
|
|
@ -7,11 +7,9 @@
|
|||
"""
|
||||
import pytest
|
||||
|
||||
from metagpt.actions import BossRequirement
|
||||
from metagpt.logs import logger
|
||||
from metagpt.roles import Architect
|
||||
from metagpt.schema import Message
|
||||
from tests.metagpt.roles.mock import PRD, DETAIL_REQUIREMENT, BOSS_REQUIREMENT, MockMessages
|
||||
from tests.metagpt.roles.mock import MockMessages
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
|
|
@ -5,15 +5,17 @@
|
|||
@Author : alexanderwu
|
||||
@File : test_engineer.py
|
||||
"""
|
||||
import re
|
||||
import ast
|
||||
import pytest
|
||||
|
||||
from metagpt.logs import logger
|
||||
from metagpt.utils.common import CodeParser
|
||||
from metagpt.roles.engineer import Engineer
|
||||
from metagpt.schema import Message
|
||||
from tests.metagpt.roles.mock import SYSTEM_DESIGN, TASKS, PRD, MockMessages, STRS_FOR_PARSING, \
|
||||
TASKS_TOMATO_CLOCK
|
||||
from metagpt.utils.common import CodeParser
|
||||
from tests.metagpt.roles.mock import (
|
||||
STRS_FOR_PARSING,
|
||||
TASKS,
|
||||
TASKS_TOMATO_CLOCK,
|
||||
MockMessages,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -63,6 +65,9 @@ def test_parse_file_list():
|
|||
assert isinstance(tasks, list)
|
||||
assert target_list == tasks
|
||||
|
||||
file_list = CodeParser.parse_file_list("Task list", TASKS_TOMATO_CLOCK, lang="python")
|
||||
logger.info(file_list)
|
||||
|
||||
|
||||
target_code = """task_list = [
|
||||
"smart_search_engine/knowledge_base.py",
|
||||
|
|
@ -85,8 +90,3 @@ def test_parse_code():
|
|||
logger.info(code)
|
||||
assert isinstance(code, str)
|
||||
assert target_code == code
|
||||
|
||||
|
||||
def test_parse_file_list():
|
||||
file_list = CodeParser.parse_file_list("Task list", TASKS_TOMATO_CLOCK, lang="python")
|
||||
logger.info(file_list)
|
||||
|
|
|
|||
|
|
@ -6,12 +6,10 @@
|
|||
@File : test_product_manager.py
|
||||
"""
|
||||
import pytest
|
||||
from metagpt.logs import logger
|
||||
|
||||
from metagpt.actions import BossRequirement
|
||||
from metagpt.logs import logger
|
||||
from metagpt.roles import ProductManager
|
||||
from metagpt.schema import Message
|
||||
from tests.metagpt.roles.mock import DETAIL_REQUIREMENT, BOSS_REQUIREMENT, MockMessages
|
||||
from tests.metagpt.roles.mock import MockMessages
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@
|
|||
@File : test_project_manager.py
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from metagpt.logs import logger
|
||||
from metagpt.roles import ProjectManager
|
||||
from metagpt.schema import Message
|
||||
from tests.metagpt.roles.mock import SYSTEM_DESIGN, MockMessages
|
||||
from tests.metagpt.roles.mock import MockMessages
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
|
|
@ -5,4 +5,3 @@
|
|||
@Author : alexanderwu
|
||||
@File : test_qa_engineer.py
|
||||
"""
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from metagpt.actions import BossRequirement
|
||||
from metagpt.environment import Environment
|
||||
from metagpt.logs import logger
|
||||
from metagpt.manager import Manager
|
||||
from metagpt.environment import Environment
|
||||
from metagpt.roles import ProductManager, Architect, Role
|
||||
from metagpt.roles import Architect, ProductManager, Role
|
||||
from metagpt.schema import Message
|
||||
from metagpt.actions import BossRequirement
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.logs import logger
|
||||
|
||||
|
||||
|
|
@ -36,7 +37,7 @@ class TestGPT:
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_llm_api_costs(self, llm_api):
|
||||
answer = await llm_api.aask('hello chatgpt')
|
||||
await llm_api.aask('hello chatgpt')
|
||||
costs = llm_api.get_costs()
|
||||
logger.info(costs)
|
||||
assert costs.total_cost > 0
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.llm import LLM
|
||||
|
||||
|
||||
|
|
@ -26,8 +27,7 @@ async def test_llm_aask_batch(llm):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_llm_aask(llm):
|
||||
|
||||
async def test_llm_acompletion(llm):
|
||||
hello_msg = [{'role': 'user', 'content': 'hello'}]
|
||||
assert len(await llm.acompletion(hello_msg)) > 0
|
||||
assert len(await llm.acompletion_batch([hello_msg])) > 0
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
"""
|
||||
import pytest
|
||||
|
||||
from metagpt.schema import Message, UserMessage, SystemMessage, AIMessage, RawMessage
|
||||
from metagpt.schema import AIMessage, Message, RawMessage, SystemMessage, UserMessage
|
||||
|
||||
|
||||
def test_message():
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
@Author : alexanderwu
|
||||
@File : test_schema.py
|
||||
"""
|
||||
from metagpt.schema import UserMessage, SystemMessage, AIMessage, Message
|
||||
from metagpt.schema import AIMessage, Message, SystemMessage, UserMessage
|
||||
|
||||
|
||||
def test_messages():
|
||||
|
|
@ -18,4 +18,4 @@ def test_messages():
|
|||
]
|
||||
text = str(msgs)
|
||||
roles = ['user', 'system', 'assistant', 'QA']
|
||||
assert all([i in text for i in roles])
|
||||
assert all([i in text for i in roles])
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
@File : test_software_company.py
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from metagpt.logs import logger
|
||||
from metagpt.software_company import SoftwareCompany
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,14 @@
|
|||
"""
|
||||
|
||||
import pytest
|
||||
from metagpt.tools.prompt_writer import GPTPromptGenerator, EnronTemplate, BEAGECTemplate, WikiHowTemplate
|
||||
|
||||
from metagpt.logs import logger
|
||||
from metagpt.tools.prompt_writer import (
|
||||
BEAGECTemplate,
|
||||
EnronTemplate,
|
||||
GPTPromptGenerator,
|
||||
WikiHowTemplate,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("llm_api")
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.logs import logger
|
||||
from metagpt.tools.search_engine import SearchEngine
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@
|
|||
@Author : alexanderwu
|
||||
@File : test_search_engine_meilisearch.py
|
||||
"""
|
||||
import time
|
||||
import pytest
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.logs import logger
|
||||
from metagpt.tools.search_engine_meilisearch import MeilisearchEngine, DataSource
|
||||
from metagpt.tools.search_engine_meilisearch import DataSource, MeilisearchEngine
|
||||
|
||||
MASTER_KEY = '116Qavl2qpCYNEJNv5-e0RC9kncev1nr1gt7ybEGVLk'
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,6 @@
|
|||
"""
|
||||
|
||||
import pytest
|
||||
from metagpt.logs import logger
|
||||
from metagpt.tools.search_engine import SearchEngine
|
||||
|
||||
|
||||
CASES = [
|
||||
"""# 上下文
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.logs import logger
|
||||
from metagpt.tools.translator import Translator
|
||||
|
||||
|
|
|
|||
|
|
@ -6,9 +6,8 @@
|
|||
@File : test_ut_generator.py
|
||||
"""
|
||||
|
||||
from metagpt.tools.ut_writer import UTGenerator
|
||||
from metagpt.const import SWAGGER_PATH, UT_PY_PATH, API_QUESTIONS_PATH
|
||||
from metagpt.tools.ut_writer import YFT_PROMPT_PREFIX
|
||||
from metagpt.const import API_QUESTIONS_PATH, SWAGGER_PATH, UT_PY_PATH
|
||||
from metagpt.tools.ut_writer import YFT_PROMPT_PREFIX, UTGenerator
|
||||
|
||||
|
||||
class TestUTWriter:
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.utils.common import CodeParser
|
||||
|
||||
t_text = '''
|
||||
|
|
|
|||
|
|
@ -6,8 +6,10 @@
|
|||
@File : test_common.py
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from metagpt.const import get_project_root
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,17 +5,12 @@
|
|||
@Author : alexanderwu
|
||||
@File : test_custom_aio_session.py
|
||||
"""
|
||||
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
from metagpt.logs import logger
|
||||
from metagpt.provider.openai_api import OpenAIGPTAPI
|
||||
from metagpt.utils.custom_aio_session import CustomAioSession
|
||||
|
||||
|
||||
async def try_hello(api):
|
||||
batch = [[{'role': 'user', 'content': 'hello'}],]
|
||||
batch = [[{'role': 'user', 'content': 'hello'}]]
|
||||
results = await api.acompletion_batch_text(batch)
|
||||
return results
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,10 @@
|
|||
@Author : chengmaoyu
|
||||
@File : test_output_parser.py
|
||||
"""
|
||||
from typing import List, Tuple
|
||||
|
||||
import pytest
|
||||
from typing import List, Tuple
|
||||
import re
|
||||
import ast
|
||||
|
||||
from metagpt.utils.common import OutputParser
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
@File : test_read_docx.py
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from metagpt.const import PROJECT_ROOT
|
||||
from metagpt.utils.read_document import read_docx
|
||||
|
||||
|
|
|
|||
|
|
@ -66,4 +66,4 @@ def test_count_string_tokens_gpt_4():
|
|||
"""Test that the string tokens are counted correctly."""
|
||||
|
||||
string = "Hello, world!"
|
||||
assert count_string_tokens(string, model_name="gpt-4-0314") == 4
|
||||
assert count_string_tokens(string, model_name="gpt-4-0314") == 4
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue