MetaGPT爆火出圈!2美元就能當老板,GitHub狂攬11.2k星,AI智能體「多面手」誕生
智能體,就是未來!
近來,又一個AI智能體項目MetaGPT爆火了,短短一個月在GitHub上狂攬11.2k星。
這是一個多智能體框架,能夠扮演不同的角色,一位工程師、產品經理、架構師和項目經理。
與AutoGPT類似,但針對產品需求、設計、競爭分析、API和文檔量身定制。
圖片
地址:https://github.com/geekan/MetaGPT
最重要的是,只輸入老板一句話的需求,它就能輸出軟件公司的整個流程,以及精心安排的SOP。
其中,Code = SOP(Team)是核心哲學。將SOP具象化,并且用于LLM構成的團隊。
軟件公司多角色示意圖(正在逐步實現)
MetaGPT
圖片
示例(均由GPT-4生成)
比如,輸入python startup.py "寫個類似今日頭條的推薦系統",就會獲得一系列輸出,其一是數據結構與API設計:
圖片
生成一個包含分析和設計的示例大約需要0.2美元(GPT-4 API的費用),而一個完整的項目大約需要2.0美元。
如下是,MetaGPT與人類團隊的軟件開發SOP比較圖。
MetaGPT的方法展示了,將高層次任務分解為由不同角色,比如產品經理、架構師、項目經理、工程師,處理的詳細可操作組件的能力。
這種方法與人類軟件開發團隊類似,但優勢在于能夠提高效率、精確性和一致性。
圖片
MetaGPT核心組成部分如下:
圖片
網友實現
有網友用MetaGPT十分鐘,就做出了一個小游戲Flappy Bird。
圖片
她表示,MetaGPT功能過于強大,也許真的可以取代軟件公司!
圖片
以下是這位網友制作游戲的全過程。
首先,在電腦上通過「傳統安裝」過程安裝MetaGPT,并輸入OpenAI API密鑰。
把自己的需求通過prompt的形式告訴系統后,就可以看著MetaGPT給你寫代碼了。
python startup.py "write p5.js code for Flappy Bird where you control a yellow bird continuously flying between a series of green pipes. The bird flaps every time you left click the mouse. If the bird falls to the ground or hits a pipe, you lose. This game goes on infinitely until you lose and you get points the further you go" --code_review True
圖片
接著,運行python main.py。然而,此時程序卻報出了一堆bug。
圖片
問題不大,把這堆代碼直接扔給Code Interpreter,讓GPT-4來debug。
圖片
代碼改完之后,再用Midjourney生成一只紅色小鳥。
圖片
順便問一下GPT-4圖片的格式和尺寸。
圖片
再用canva調整小鳥和管道的大小。
圖片
最后,運行游戲。
網友表示,雖然有一些小問題,比如頂部的管道沒有殺死小鳥。但它還是成功了,而且我沒有寫一行代碼,甚至都不用調試?。。。?!
只要別讓小鳥碰到底部的管道就行。
圖片
也有網友做了同樣的游戲,效果如下:
圖片
另外,還有日本網友還用其制作了「二十一點」。
圖片
圖片
安裝
傳統安裝
# 步驟1:確保已經安裝了NPM。并使用npm安裝mermaid-js
npm --version
sudo npm install -g @mermaid-js/mermaid-cli
# 步驟2:確保已經安裝了Python 3.9+。可以使用以下命令進行檢查:
python --version
# 步驟3:克隆倉庫到本機,并進行安裝。
git clone https://github.com/geekan/metagpt
cd metagpt
python setup.py install
Docker安裝
# 步驟1: 下載metagpt官方鏡像并準備好config.yaml
docker pull metagpt/metagpt:v0.3
mkdir -p /opt/metagpt/{config,workspace}
docker run --rm metagpt/metagpt:v0.3 cat /app/metagpt/config/config.yaml > /opt/metagpt/config/config.yaml
vim /opt/metagpt/config/config.yaml # 修改config
# 步驟2: 使用容器運行metagpt演示
docker run --rm \
--privileged \
-v /opt/metagpt/config:/app/metagpt/config \
-v /opt/metagpt/workspace:/app/metagpt/workspace \
metagpt/metagpt:v0.3 \
python startup.py "Write a cli snake game"
# 也可以啟動一個容器并在其中執行命令
docker run --name metagpt -d \
--privileged \
-v /opt/metagpt/config:/app/metagpt/config \
-v /opt/metagpt/workspace:/app/metagpt/workspace \
metagpt/metagpt:v0.3
docker exec -it metagpt /bin/bash
$ python startup.py "Write a cli snake game"
docker run ...做了以下事情:
以特權模式運行,有權限運行瀏覽器
將主機目錄/opt/metagpt/config映射到容器目錄/app/metagpt/config
將主機目錄/opt/metagpt/workspace映射到容器目錄/app/metagpt/workspace
執行演示命令python startup.py "Write a cli snake game"
自己構建鏡像
# 也可以自己構建metagpt鏡像
git clone https://github.com/geekan/MetaGPT.git
cd MetaGPT && docker build -t metagpt:custom .
配置
在config/key.yaml / config/config.yaml / env中配置你的OPENAI_API_KEY
優先級順序:config/key.yaml > config/config.yaml > env
# 復制配置文件并進行必要的修改
cp config/config.yaml config/key.yaml
圖片
演示:啟動一個創業公司
python startup.py "Write a cli snake game"
# 使用code review模式會增加開銷,但同時也會提升代碼質量和成功率
python startup.py "Write a cli snake game" --code_review True
運行腳本后,就可以在workspace/目錄中找到你的新項目了。
平臺或工具的偏好
你可以在陳述需求時,說明自己想要使用的平臺或工具。
python startup.py "Write a cli snake game based on pygame"
使用
NAME
startup.py - We are a software startup comprised of AI. By investing in us, you are empowering a future filled with limitless possibilities.
SYNOPSIS
startup.py IDEA <flags>
DESCRIPTION
We are a software startup comprised of AI. By investing in us, you are empowering a future filled with limitless possibilities.
# 我們是一家AI軟件創業公司。通過投資我們,您將賦能一個充滿無限可能的未來。
POSITIONAL ARGUMENTS
IDEA
Type: str
你的創新想法,例如"Creating a snake game."
FLAGS
--investment=INVESTMENT
Type: float
Default: 3.0
As an investor, you have the opportunity to contribute a certain dollar amount to this AI company.
# 作為投資者,您有機會向這家AI公司投入一定的美元金額。
--n_round=N_ROUND
Type: int
Default: 5
NOTES
也可以用FLAGS的語法,來處理POSITIONAL ARGUMENTS。
代碼實現
from metagpt.software_company import SoftwareCompany
from metagpt.roles import ProjectManager, ProductManager, Architect, Engineer
async def startup(idea: str, investment: float = 3.0, n_round: int = 5):
"""Run a startup. Be a boss."""
company = SoftwareCompany()
company.hire([ProductManager(), Architect(), ProjectManager(), Engineer()])
company.invest(investment)
company.start_project(idea)
await company.run(n_round=n_round)
你可以查看examples,其中有單角色(帶知識庫)的使用例子與僅LLM的使用例子。
參考資料:
https://arxiv.org/pdf/2308.00352.pdf
https://github.com/geekan/MetaGPT
https://twitter.com/99aico/status/1684249002437668864