基于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命令获取源码

bash 复制代码
git clone https://github.com/geekan/MetaGPT.git

然后进入 MetaGPT 目录

bash 复制代码
cd MetaGPT/

最后安装该仓库环境依赖

bash 复制代码
pip install -e .

2 配置MetaGPT

下面使用ZHIPUAI为例,来MetaGPT

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

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

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

bash 复制代码
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",以及一个团队,其中包括了这两个角色。目标是模拟两位候选人在直播环境中就气候变化这一话题进行对话。这将有助于模拟候选人在现实选举中的表现和对话。

python 复制代码
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,所以把上面代码最后一行改成:

python 复制代码
await team.run(idea="Topic: climate change. Under 80 words per message.", send_to="Alex", n_round=5)
相关推荐
白-胖-子4 小时前
深入剖析大模型在文本生成式 AI 产品架构中的核心地位
人工智能·架构
想要成为计算机高手5 小时前
11. isaacsim4.2教程-Transform 树与Odometry
人工智能·机器人·自动驾驶·ros·rviz·isaac sim·仿真环境
静心问道6 小时前
InstructBLIP:通过指令微调迈向通用视觉-语言模型
人工智能·多模态·ai技术应用
宇称不守恒4.06 小时前
2025暑期—06神经网络-常见网络2
网络·人工智能·神经网络
_Kayo_7 小时前
VUE2 学习笔记6 vue数据监测原理
vue.js·笔记·学习
小楓12017 小时前
醫護行業在未來會被AI淘汰嗎?
人工智能·醫療·護理·職業
数据与人工智能律师7 小时前
数字迷雾中的安全锚点:解码匿名化与假名化的法律边界与商业价值
大数据·网络·人工智能·云计算·区块链
chenchihwen7 小时前
大模型应用班-第2课 DeepSeek使用与提示词工程课程重点 学习ollama 安装 用deepseek-r1:1.5b 分析PDF 内容
人工智能·学习
说私域7 小时前
公域流量向私域流量转化策略研究——基于开源AI智能客服、AI智能名片与S2B2C商城小程序的融合应用
人工智能·小程序
Java樱木7 小时前
AI 编程工具 Trae 重要的升级。。。
人工智能