MetaGPT/startup.py

118 lines
4.2 KiB
Python
Raw Normal View History

2023-06-30 17:10:48 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2023-07-28 11:42:13 +08:00
"""
@Modified By: mashenquan, 2023-07-27, + `industry` concept
2023-07-28 11:42:13 +08:00
"""
2023-07-22 11:28:22 +08:00
2023-07-28 11:42:13 +08:00
import asyncio
from pathlib import Path
import aiofiles
2023-06-30 17:10:48 +08:00
import fire
2023-07-28 11:42:13 +08:00
from metagpt.logs import logger
from metagpt.actions.write_teaching_plan import TeachingPlanRequirement
2023-07-22 11:28:22 +08:00
from metagpt.roles import Architect, Engineer, ProductManager, ProjectManager
2023-07-28 11:42:13 +08:00
from metagpt.roles.teacher import Teacher
2023-06-30 17:10:48 +08:00
from metagpt.software_company import SoftwareCompany
async def software_startup(idea: str, investment: float = 3.0, n_round: int = 5, *args, **kwargs):
2023-07-28 11:42:13 +08:00
"""Run a startup. Be a boss in software industry."""
code_review = kwargs.get("code_review", False) # Whether to use code review.
2023-06-30 17:10:48 +08:00
company = SoftwareCompany()
2023-07-22 09:47:42 +08:00
company.hire([ProductManager(),
Architect(),
ProjectManager(),
Engineer(n_borg=5, use_code_review=code_review)])
2023-06-30 17:10:48 +08:00
company.invest(investment)
company.start_project(idea)
await company.run(n_round=n_round)
async def education_startup(lesson_file: str, investment: float = 3.0, n_round: int = 1, *args, **kwargs):
2023-07-28 11:42:13 +08:00
"""Run a startup. Be a teacher in education industry."""
demo_lesson = """
UNIT 1 Making New Friends
TOPIC 1 Welcome to China!
Section A
1a Listen and number the following names.
Jane Mari Kangkang Michael
Look, listen and understand. Then practice the conversation.
Work in groups. Introduce yourself using
I m ... Then practice 1a
with your own hometown or the following places.
1b Listen and number the following names
Jane Michael Maria Kangkang
1c Work in groups. Introduce yourself using I m ... Then practice 1a with your own hometown or the following places.
China the USA the UK Hong Kong Beijing
2a Look, listen and understand. Then practice the conversation
Hello!
Hello!
Hello!
Hello! Are you Maria?
No, Im not. Im Jane.
Oh, nice to meet you, Jane
Nice to meet you, too.
Hi, Maria!
Hi, Kangkang!
Welcome to China!
Thanks.
2b Work in groups. Make up a conversation with your own name and the
following structures.
A: Hello! / Good morning! / Hi! Im ... Are you ... ?
B: ...
3a Listen, say and trace
Aa Bb Cc Dd Ee Ff Gg
3b Listen and number the following letters. Then circle the letters withthe same sound as Bb.
Aa Bb Cc Dd Ee Ff Gg
3c Match the big letters with the small ones. Then write them on the lines.
"""
lesson = ""
if lesson_file is not None and Path(lesson_file).exists():
async with aiofiles.open(lesson_file, mode="r", encoding="utf-8") as reader:
lesson = await reader.read()
logger.info(f"Course content: {lesson}")
if not lesson:
logger.info("No course content provided, using the demo course.")
lesson = demo_lesson
company = SoftwareCompany()
company.hire([Teacher(*args, **kwargs)])
company.invest(investment)
company.start_project(lesson, role="Teacher", cause_by=TeachingPlanRequirement)
await company.run(n_round=1)
def main(idea: str, investment: float = 3.0, n_round: int = 5, *args, **kwargs):
2023-06-30 17:10:48 +08:00
"""
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 for `software` industry, such as "Creating a snake game."; lesson filename for `education` industry.
2023-06-30 17:10:48 +08:00
:param investment: As an investor, you have the opportunity to contribute a certain dollar amount to this AI company.
2023-07-22 09:47:42 +08:00
:param n_round:
2023-07-28 11:42:13 +08:00
:param args: Parameters passed in format: `python your_script.py arg1 arg2 arg3`
:param kwargs: Parameters passed in format: `python your_script.py a--param1=value1 --param2=value2`
2023-06-30 17:10:48 +08:00
:return:
"""
2023-07-28 11:42:13 +08:00
industry = kwargs.get("industry", "software")
industries = {
"software": software_startup,
"education": education_startup,
}
startup = industries.get(industry)
if startup is None:
print(f"Available industries:{list(industries.keys())}")
return
asyncio.run(startup(idea, investment, n_round, *args, **kwargs))
2023-06-30 17:10:48 +08:00
if __name__ == '__main__':
fire.Fire(main)