基于MetaGPT的智能体理论与实践-Task01

Task01:  MetaGPT环境配置

学习教程:https://github.com/datawhalechina/hugging-multi-agent

1  环境准备

1.1  安装python3.9+

通过:python3 --version, 查看此python版本为3.10.3

1.2  下载MetaGPT

开始,借用清华镜像,拉取metagpt==0.6.6,失败。

 然后直接用pip install metagpt==0.6.6 进行下载与安装。

 1.3  获取MetaGPT仓库源码

首先git clone命令获取源码

git clone https://github.com/geekan/MetaGPT.git

 然后进入 MetaGPT 目录

cd MetaGPT/

最后安装该仓库环境依赖

pip install -e .

 2   配置MetaGPT

下面使用ZHIPUAI为例,来MetaGPT

首先,需要在https://open.bigmodel.cn/  获取智谱的api_key。

然后使用config.yaml文件进行配置。

在MetaGPT/config/ 文件下,创建config.yaml文件,然后在文件中,添加如下配置信息。

llm:
  api_type: "zhipuai"  
  model: "glm-3-turbo"  
  base_url: "https://open.bigmodel.cn/api/paas/v4/chat/completions"  
  api_key: "your api_key"

3   DEMO测试 

异步相关的代码在ipython或者notebook环境下,asyncio.run(xxx)得改成await xxx

eg:asyncio.run(main())需要改成await main() 

代码中创建了两个角色,分别代表民主党候选人Alex和共和党候选人Bob。他们将在一个名为"US election live broadcast"的环境中进行对话。您的代码还定义了两个动作,分别是"AlexSay"和"BobSay",以及一个团队,其中包括了这两个角色。目标是模拟两位候选人在直播环境中就气候变化这一话题进行对话。这将有助于模拟候选人在现实选举中的表现和对话。 

import asyncio

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

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))

由于,这里使用的notebook,所以把上面代码最后一行改成:

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

 

 

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值