2024.2 DataWhale 多智能体实战 第一章 MetaGPT环境配置

项目地址: GitHub - datawhalechina/hugging-multi-agent: A tutorial to quickly help you understand the concept of agent and muti-agent and get started with coding development

AutoDL租用实例

conda环境配置

逐行输入以下三条命令:

bash

conda create -n metagpt python=3.9

conda activate metagpt

metagpt安装

(0.6.6版本): 时间比较久

pip install metagpt==0.6.6

智谱AI API获取与配置

API获取,请登录智谱AI官网(智谱AI开放平台)申请使用权限。

新建metagpt文件夹,进入metagpt文件夹内并新建config文件夹,在config文件夹内创建config.yaml并填写以下内容(ZHIPU_API_KEY替换为自己的key):

mkdir metagpt
cd metagpt
mkdir config
cd config
vim config.yaml

角色对话demo

在metagpt目录下,创建demo.py,复制以下代码:

import asyncio

from metagpt.actions import Action
from metagpt.environment import Environment
from metagpt.roles import Role
from metagpt.team import Team

from metagpt.const import DEFAULT_WORKSPACE_ROOT, METAGPT_ROOT, OPTIONS
default_yaml_file = METAGPT_ROOT / "config/config.yaml"
print(METAGPT_ROOT / "config/config.yaml")

action1 = Action(name="AlexSay", instruction="Express your opinion with emotion and don't repeat it")
action2 = Action(name="BobSay", instruction="Express your opinion with emotion and don't repeat it")
alex = Role(name="Alex", profile="Democratic candidate", goal="Win the election", actions=[action1], watch=[action2])
bob = Role(name="Bob", profile="Republican candidate", goal="Win the election", actions=[action2], watch=[action1])
env = Environment(desc="US election live broadcast")
team = Team(investment=10.0, env=env, roles=[alex, bob])

asyncio.run(team.run(idea="Topic: climate change. Under 80 words per message.", send_to="Alex", n_round=5))

运行demo

python demo.py

可以看到,demo中包含了AI,Alex和Bob三位角色进行的对话。

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值