fix conflict

This commit is contained in:
程茂宇 2023-07-24 14:24:41 +08:00
commit 4975baa890
110 changed files with 950 additions and 248 deletions

View file

@ -9,20 +9,19 @@ from enum import Enum
from metagpt.actions.action import Action
from metagpt.actions.action_output import ActionOutput
from metagpt.actions.write_prd import WritePRD
from metagpt.actions.write_prd_review import WritePRDReview
from metagpt.actions.add_requirement import BossRequirement
from metagpt.actions.debug_error import DebugError
from metagpt.actions.design_api import WriteDesign
from metagpt.actions.design_api_review import DesignReview
from metagpt.actions.design_filenames import DesignFilenames
from metagpt.actions.project_management import AssignTasks, WriteTasks
from metagpt.actions.run_code import RunCode
from metagpt.actions.search_and_summarize import SearchAndSummarize
from metagpt.actions.write_code import WriteCode
from metagpt.actions.write_code_review import WriteCodeReview
from metagpt.actions.write_prd import WritePRD
from metagpt.actions.write_prd_review import WritePRDReview
from metagpt.actions.write_test import WriteTest
from metagpt.actions.run_code import RunCode
from metagpt.actions.debug_error import DebugError
from metagpt.actions.project_management import WriteTasks, AssignTasks
from metagpt.actions.add_requirement import BossRequirement
from metagpt.actions.search_and_summarize import SearchAndSummarize
class ActionType(Enum):

View file

@ -5,15 +5,15 @@
@Author : alexanderwu
@File : action.py
"""
from typing import Optional
from abc import ABC
from typing import Optional
from metagpt.llm import LLM
from metagpt.actions.action_output import ActionOutput
from tenacity import retry, stop_after_attempt, wait_fixed
from pydantic import BaseModel
from metagpt.utils.common import OutputParser
from metagpt.actions.action_output import ActionOutput
from metagpt.llm import LLM
from metagpt.utils.common import OutputParser
from metagpt.logs import logger
class Action(ABC):
def __init__(self, name: str = '', context=None, llm: LLM = None):
@ -55,8 +55,10 @@ class Action(ABC):
system_msgs = []
system_msgs.append(self.prefix)
content = await self.llm.aask(prompt, system_msgs)
logger.debug(content)
output_class = ActionOutput.create_model_class(output_class_name, output_data_mapping)
parsed_data = OutputParser.parse_data_with_mapping(content, output_data_mapping)
logger.debug(parsed_data)
instruct_content = output_class(**parsed_data)
return ActionOutput(content, instruct_content)

View file

@ -6,9 +6,10 @@
@File : action_output
"""
from pydantic import create_model, validator, root_validator, BaseModel
from typing import Dict, Type
from pydantic import BaseModel, create_model, root_validator, validator
class ActionOutput:
content: str

View file

@ -8,7 +8,6 @@
from metagpt.actions import Action
PROMPT = """You are an AI developer, trying to write a program that generates code for users based on their intentions.
For the user's prompt:

View file

@ -5,8 +5,9 @@
@Author : Leo Xiao
@File : azure_tts.py
"""
from azure.cognitiveservices.speech import AudioConfig, SpeechConfig, SpeechSynthesizer
from metagpt.actions.action import Action
from azure.cognitiveservices.speech import SpeechConfig, SpeechSynthesizer, AudioConfig
from metagpt.config import Config

View file

@ -7,14 +7,12 @@
"""
import shutil
from pathlib import Path
from typing import List, Tuple
from typing import List
from metagpt.actions import ActionOutput
from metagpt.actions import Action
from metagpt.actions import Action, ActionOutput
from metagpt.const import WORKSPACE_ROOT
from metagpt.utils.common import CodeParser
from metagpt.schema import Message
from metagpt.logs import logger
from metagpt.utils.common import CodeParser
from metagpt.utils.mermaid import mermaid_to_file
PROMPT_TEMPLATE = """

View file

@ -5,9 +5,8 @@
@Author : alexanderwu
@File : design_filenames.py
"""
from metagpt.logs import logger
from metagpt.actions import Action
from metagpt.logs import logger
PROMPT = """You are an AI developer, trying to write a program that generates code for users based on their intentions.
When given their intentions, provide a complete and exhaustive list of file paths needed to write the program for the user.

View file

@ -8,11 +8,8 @@
from typing import List, Tuple
from metagpt.actions.action import Action
from metagpt.actions.action_output import ActionOutput
from metagpt.const import WORKSPACE_ROOT
from metagpt.logs import logger
from metagpt.utils.common import OutputParser, CodeParser
from tenacity import retry, stop_after_attempt, wait_fixed
from metagpt.utils.common import CodeParser
PROMPT_TEMPLATE = '''
# Context

View file

@ -20,6 +20,6 @@ class RunCode(Action):
namespace = {}
exec(code, namespace)
return namespace.get('result', None)
except Exception as e:
except Exception:
# If there is an error in the code, return the error message
return traceback.format_exc()

View file

@ -5,15 +5,12 @@
@Author : alexanderwu
@File : search_google.py
"""
import asyncio
from metagpt.logs import logger
from metagpt.config import SearchEngineType, Config
from metagpt.actions import Action
from metagpt.config import Config
from metagpt.logs import logger
from metagpt.schema import Message
from metagpt.tools.search_engine import SearchEngine
SEARCH_AND_SUMMARIZE_SYSTEM = """### Requirements
1. Please summarize the latest dialogue based on the reference information (secondary) and dialogue history (primary). Do not include text that is irrelevant to the conversation.
- The context is for reference only. If it is irrelevant to the user's search request history, please reduce its reference and usage.
@ -112,7 +109,7 @@ class SearchAndSummarize(Action):
async def run(self, context: list[Message], system_text=SEARCH_AND_SUMMARIZE_SYSTEM) -> str:
no_serpapi = not self.config.serpapi_api_key or 'YOUR_API_KEY' == self.config.serpapi_api_key
no_serper = not self.config.serper_api_key or 'YOUR_API_KEY' == self.config.serper_api_key
no_google= not self.config.google_api_key or 'YOUR_API_KEY' == self.config.google_api_key
no_google = not self.config.google_api_key or 'YOUR_API_KEY' == self.config.google_api_key
if no_serpapi and no_google and no_serper:
logger.warning('Configure one of SERPAPI_API_KEY, SERPER_API_KEY, GOOGLE_API_KEY to unlock full feature')
@ -131,10 +128,10 @@ class SearchAndSummarize(Action):
prompt = SEARCH_AND_SUMMARIZE_PROMPT.format(
# PREFIX = self.prefix,
ROLE = self.profile,
CONTEXT = rsp,
QUERY_HISTORY = '\n'.join([str(i) for i in context[:-1]]),
QUERY = str(context[-1])
ROLE=self.profile,
CONTEXT=rsp,
QUERY_HISTORY='\n'.join([str(i) for i in context[:-1]]),
QUERY=str(context[-1])
)
result = await self._aask(prompt, system_prompt)
logger.debug(prompt)

View file

@ -5,12 +5,12 @@
@Author : alexanderwu
@File : write_prd.py
"""
from metagpt.actions import Action, ActionOutput
from metagpt.actions.search_and_summarize import SEARCH_AND_SUMMARIZE_SYSTEM, SearchAndSummarize, \
SEARCH_AND_SUMMARIZE_PROMPT, SEARCH_AND_SUMMARIZE_SYSTEM_EN_US
from metagpt.logs import logger
from typing import List, Tuple
from metagpt.actions import Action, ActionOutput
from metagpt.actions.search_and_summarize import SearchAndSummarize
from metagpt.logs import logger
PROMPT_TEMPLATE = """
# Context
## Original Requirements
@ -59,6 +59,7 @@ ATTENTION: Use '##' to SPLIT SECTIONS, not '#'. AND '## <SECTION_NAME>' SHOULD W
## Requirement Pool: Provided as Python list[str, str], the parameters are requirement description, priority(P0/P1/P2), respectively, comply with PEP standards; no more than 5 requirements and consider to make its difficulty lower
## UI Design draft: Provide as Plain text. Be simple. Describe the elements and functions, also provide a simple style description and layout description.
## Anything UNCLEAR: Provide as Plain text. Make clear here.
"""
FORMAT_EXAMPLE = """
@ -105,6 +106,9 @@ The product should be a ...
]
```
## UI Design draft
Give a basic function description, and a draft
## Anything UNCLEAR
There are no unclear points.
---
@ -117,6 +121,7 @@ OUTPUT_MAPPING = {
"Competitive Quadrant Chart": (str, ...),
"Requirement Analysis": (str, ...),
"Requirement Pool": (List[Tuple[str, str]], ...),
"UI Design draft":(str, ...),
"Anything UNCLEAR": (str, ...),
}
@ -136,5 +141,6 @@ class WritePRD(Action):
prompt = PROMPT_TEMPLATE.format(requirements=requirements, search_information=info,
format_example=FORMAT_EXAMPLE)
logger.debug(prompt)
prd = await self._aask_v1(prompt, "prd", OUTPUT_MAPPING)
return prd