feat: merge geekan:cli-etc

This commit is contained in:
莘权 马 2023-11-29 16:22:05 +08:00
parent eff1cb7dc1
commit 7b44fccf8d
5 changed files with 26 additions and 92 deletions

View file

@ -12,7 +12,7 @@ from pathlib import Path
from metagpt.actions import Action, ActionOutput
from metagpt.config import CONFIG
from metagpt.const import DOCS_FILE_REPO, REQUIREMENT_FILENAME, WORKSPACE_ROOT
from metagpt.const import DEFAULT_WORKSPACE_ROOT, DOCS_FILE_REPO, REQUIREMENT_FILENAME
from metagpt.schema import Document
from metagpt.utils.file_repository import FileRepository
from metagpt.utils.git_repository import GitRepository
@ -28,8 +28,11 @@ class PrepareDocuments(Action):
return ActionOutput(content=doc.json(exclue="content"), instruct_content=doc)
# Create and initialize the workspace folder, initialize the Git environment.
default_workspace_root = CONFIG.project_path or DEFAULT_WORKSPACE_ROOT
default_project_name = CONFIG.project_name or FileRepository.new_filename()
default_workdir = Path(default_workspace_root) / default_project_name
CONFIG.git_repo = GitRepository()
workdir = Path(CONFIG.WORKDIR) if CONFIG.WORKDIR else WORKSPACE_ROOT / FileRepository.new_filename()
workdir = Path(CONFIG.WORKDIR) if CONFIG.WORKDIR else default_workdir
CONFIG.git_repo.open(local_path=workdir, auto_init=True)
# Write the newly added requirements from the main parameter idea to `docs/requirement.txt`.

View file

@ -4,6 +4,8 @@ import asyncio
import typer
from metagpt.config import CONFIG
app = typer.Typer()
@ -17,6 +19,10 @@ def startup(
implement: bool = typer.Option(True, help="Enable or disable code implementation."),
project_name: str = typer.Option("", help="Unique project name, such as 'game_2048'."),
inc: bool = typer.Option(False, help="Incremental mode. Use it to coop with existing repo."),
project_path: str = typer.Option(
help="Specify the directory path of the old version project to fulfill the " "incremental requirements."
),
reqa_file: str = typer.Option(help="Specify the source file name for rewriting the quality test code."),
):
"""Run a startup. Be a boss."""
from metagpt.roles import (
@ -28,6 +34,12 @@ def startup(
)
from metagpt.team import Team
# Use in the PrepareDocuments action according to Section 2.2.3.5.1 of RFC 135.
CONFIG.project_name = project_name
CONFIG.inc = inc
CONFIG.project_path = project_path
CONFIG.reqa_file = reqa_file
company = Team()
company.hire(
[
@ -44,9 +56,9 @@ def startup(
company.hire([QaEngineer()])
company.invest(investment)
company.run_project(idea, project_name=project_name, inc=inc)
company.run_project(idea)
asyncio.run(company.run(n_round=n_round))
if __name__ == "__main__":
startup(idea="Make a 2048 game.")
app()

View file

@ -11,6 +11,7 @@ from pydantic import BaseModel, Field
from metagpt.actions import UserRequirement
from metagpt.config import CONFIG
from metagpt.const import MESSAGE_ROUTE_TO_ALL
from metagpt.environment import Environment
from metagpt.logs import logger
from metagpt.roles import Role
@ -45,16 +46,14 @@ class Team(BaseModel):
if CONFIG.total_cost > CONFIG.max_budget:
raise NoMoneyException(CONFIG.total_cost, f"Insufficient funds: {CONFIG.max_budget}")
def run_project(self, idea, send_to: str = "", project_name: str = "", inc: bool = False):
def run_project(self, idea, send_to: str = ""):
"""Start a project from publishing user requirement."""
self.idea = idea
# If user set project_name, then use it.
if project_name:
path = CONFIG.workspace_path / project_name
self.env.load_existing_repo(path, inc=inc)
# Human requirement.
self.env.publish_message(Message(role="Human", content=idea, cause_by=UserRequirement, send_to=send_to))
self.env.publish_message(
Message(role="Human", content=idea, cause_by=UserRequirement, send_to=send_to or MESSAGE_ROUTE_TO_ALL)
)
def _save(self):
logger.info(self.json(ensure_ascii=False))

View file

@ -16,7 +16,7 @@ from typing import Dict
from git.repo import Repo
from git.repo.fun import is_git_dir
from metagpt.const import WORKSPACE_ROOT
from metagpt.const import DEFAULT_WORKSPACE_ROOT
from metagpt.logs import logger
from metagpt.utils.dependency_file import DependencyFile
from metagpt.utils.file_repository import FileRepository
@ -201,7 +201,7 @@ class GitRepository:
if __name__ == "__main__":
path = WORKSPACE_ROOT / "git"
path = DEFAULT_WORKSPACE_ROOT / "git"
path.mkdir(exist_ok=True, parents=True)
repo = GitRepository()

View file

@ -1,80 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
import fire
from metagpt.config import CONFIG
from metagpt.roles import (
Architect,
Engineer,
ProductManager,
ProjectManager,
QaEngineer,
)
from metagpt.software_company import SoftwareCompany
async def startup(
idea: str,
investment: float = 3.0,
n_round: int = 5,
code_review: bool = False,
run_tests: bool = False,
implement: bool = True,
):
"""Run a startup. Be a boss."""
company = SoftwareCompany()
company.hire(
[
ProductManager(),
Architect(),
ProjectManager(),
]
)
# if implement or code_review
if implement or code_review:
# developing features: implement the idea
company.hire([Engineer(n_borg=5, use_code_review=code_review)])
if run_tests:
# developing features: run tests on the spot and identify bugs
# (bug fixing capability comes soon!)
company.hire([QaEngineer()])
company.invest(investment)
company.start_project(idea)
await company.run(n_round=n_round)
def main(
idea: str,
investment: float = 3.0,
n_round: int = 5,
code_review: bool = True,
run_tests: bool = False,
implement: bool = True,
project_path: str = None,
reqa_file: str = None,
):
"""
We are a software startup comprised of AI. By investing in us,
you are empowering a future filled with limitless possibilities.
:param idea: Your innovative idea, such as "Creating a snake game."
:param investment: As an investor, you have the opportunity to contribute
a certain dollar amount to this AI company.
:param n_round:
:param code_review: Whether to use code review.
:param run_tests: Whether run unit tests.
:param implement: Whether to write codes.
:param project_path: The path of the old version project to improve.
:return:
"""
CONFIG.WORKDIR = project_path
CONFIG.REQA_FILENAME = reqa_file
asyncio.run(startup(idea, investment, n_round, code_review, run_tests, implement))
if __name__ == "__main__":
fire.Fire(main)