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三位角色进行的对话。