app.py
1 from pathlib import Path 2 3 import chainlit as cl 4 from init_setup import ChainlitEnv 5 6 from metagpt.roles import ( 7 Architect, 8 Engineer, 9 ProductManager, 10 ProjectManager, 11 QaEngineer, 12 ) 13 from metagpt.team import Team 14 15 16 # https://docs.chainlit.io/concepts/starters 17 @cl.set_chat_profiles 18 async def chat_profile() -> list[cl.ChatProfile]: 19 """Generates a chat profile containing starter messages which can be triggered to run MetaGPT 20 21 Returns: 22 list[chainlit.ChatProfile]: List of Chat Profile 23 """ 24 return [ 25 cl.ChatProfile( 26 name="MetaGPT", 27 icon="/public/MetaGPT-new-log.jpg", 28 markdown_description="It takes a **one line requirement** as input and outputs **user stories / competitive analysis / requirements / data structures / APIs / documents, etc.**, But `everything in UI`.", 29 starters=[ 30 cl.Starter( 31 label="Create a 2048 Game", 32 message="Create a 2048 game", 33 icon="/public/2048.jpg", 34 ), 35 cl.Starter( 36 label="Write a cli Blackjack Game", 37 message="Write a cli Blackjack Game", 38 icon="/public/blackjack.jpg", 39 ), 40 ], 41 ) 42 ] 43 44 45 # https://docs.chainlit.io/concepts/message 46 @cl.on_message 47 async def startup(message: cl.Message) -> None: 48 """On Message in UI, Create a MetaGPT software company 49 50 Args: 51 message (chainlit.Message): message by chainlist 52 """ 53 idea = message.content 54 company = Team(env=ChainlitEnv()) 55 56 # Similar to software_company.py 57 company.hire( 58 [ 59 ProductManager(), 60 Architect(), 61 ProjectManager(), 62 Engineer(n_borg=5, use_code_review=True), 63 QaEngineer(), 64 ] 65 ) 66 67 company.invest(investment=3.0) 68 company.run_project(idea=idea) 69 70 await company.run(n_round=5) 71 72 workdir = Path(company.env.context.config.project_path) 73 files = [file.name for file in workdir.iterdir() if file.is_file()] 74 files = "\n".join([f"{workdir}/{file}" for file in files if not file.startswith(".git")]) 75 76 await cl.Message( 77 content=f""" 78 Codes can be found here: 79 {files} 80 81 --- 82 83 Total cost: `{company.cost_manager.total_cost}` 84 """ 85 ).send()