MetaGPT爆火出圈!2美元就能当老板,GitHub狂揽11.2k星,AI智能体「多面手」诞生

来源 | 新智元
作者 | 桃子 好困

智能体,就是未来!

近来,又一个AI智能体项目MetaGPT爆火了,短短一个月在GitHub上狂揽11.2k星。

这是一个多智能体框架,能够扮演不同的角色,一位工程师、产品经理、架构师和项目经理。

与AutoGPT类似,但针对产品需求、设计、竞争分析、API和文档量身定制。

地址:
https://github.com/geekan/MetaGPT

大模型研究测试传送门

GPT-4传送门(免墙,可直接测试,遇浏览器警告点高级/继续访问即可):
Hello, GPT4!

最重要的是,只输入老板一句话的需求,它就能输出软件公司的整个流程,以及精心安排的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的使用例子。

参考资料

[1]https://arxiv.org/pdf/2308.00352.pdf
[2]https://github.com/geekan/MetaGPT
[3]https://twitter.com/99aico/status/1684249002437668864

猜你喜欢

转载自blog.csdn.net/xixiaoyaoww/article/details/132173332