Generative agents 编译运行

部署比较简单,参考 github 的说明做就可以。下面做简要说明。

〇. 准备

  1. python 环境安装,建议版本 3.9.12。推荐使用 conda 安装环境
ini 复制代码
conda create -n genagent python=3.9.12 pip
conda activate genagent
  1. 申请 openai 的 api-key

platform.openai.com/settings/or...

  1. 下载代码

git clone https://github.com/joonspk-research/generative_agents.git

网络问题可以试试:gitclone.com/github.com/...

  1. 创建配置文件,在 reverie/backend_server目录下创建 utils.py,内容如下:
ini 复制代码
# 替换你的 api-key 
openai_api_key = "<Your OpenAI API>"
# Put your name
key_owner = "<Name>"

maze_assets_loc = "../../environment/frontend_server/static_dirs/assets"
env_matrix = f"{maze_assets_loc}/the_ville/matrix"
env_visuals = f"{maze_assets_loc}/the_ville/visuals"

fs_storage = "../../environment/frontend_server/storage"
fs_temp_storage = "../../environment/frontend_server/temp_storage"

collision_block_id = "32125"

# Verbose 
debug = True
  1. 安装依赖库,代码根目录执行 pip install -r requirements.txt

一. 启动

  1. 启动 environment 服务,系统是一个 Django 服务,默认端口是 8000,需要检查系统不要占用。
bash 复制代码
cd environment/frontend_server
python manage.py runserver

启动完成后,打开浏览器访问 http://localhost:8000,看到 Your environment server is up and running表示启动成功了。

  1. 启动 simulation 服务
bash 复制代码
cd reverie/backend_server
python reverie.py
# 启动完成后控制台会显示,Enter the name of the forked simulation: 
# 输入下面的脚本表示启动 3 个人物角色,有很多个模板,后面看代码的时候再解释。
base_the_ville_isabella_maria_klaus
# 接下来会显示 "Enter the name of the new simulation: "
# 随便输入一个名字就好
test-simulation
# 然后控制台会显示如下信息。
Enter option:
  1. 运行和保存 Simulation

浏览器打开 http://localhost:8000/simulator_home,就可以看到一个小镇的地图了,下面有 3 个角色列表。地图可以用键盘方向键移动。到现在所有的环境都已经准备好了,下面就可以开始模拟多 agnent 互动了。

在刚才的控制台 Enter option:中输入命令:

bash 复制代码
# 100,表示运行 100 步,每步 10s
run 100
# 开始运行后,地图上的 agent 就会开始移动了,结束后控制台又会显示
Enter option:
# 还有两个命令
# 不保存退出
exit
# 保存退出,保存的 simulation 下次启动时可以继续加载,比如我们这次创建的 simulation 叫 test-simulation
fin		
  1. 重放之前保存的 simulation

直接在浏览器打开 http://localhost:8000/replay/<simulation-name>/<starting-time-step>

  1. 演示 simulation

上面的重放的 simulation 文件包含了调试信息等内容,没有做压缩,如果要做演示,可以提前压缩文件。执行 reverie\compress_sim_storage.py的 compress 函数可以压缩文件,用于后续演示。

用浏览器访问呢 http://localhost:8000/demo/<simulation-name>/<starting-time-step>/<simulation-speed>打开演示文件

二. FAQ

  1. 没办法直接访问 openai 怎么办?
    如果没有 openai 访问条件,可以直接运行源代码中提供的 simulation 运行,查看效果。
  2. 有演示环境吗?
    25个角色的演示版本地址:https://reverie.herokuapp.com/arXiv_Demo/
相关推荐
GitLqr18 分钟前
AI洞察 | 一周动态: Manus 裁员、Kimi K2 开源、混元 3D 创作、Qwen Chat 桌面客户端
人工智能·agent·ai编程
柠檬豆腐脑3 小时前
构建高效智能体(Building Effective Agents)
llm·agent
聚客AI7 小时前
🔥 大模型开发进阶:基于LangChain的异步流式响应与性能优化
人工智能·langchain·agent
后端小肥肠9 小时前
效率革命!10分钟用Dify+Spring Boot打造AI热点雷达,自媒体选赛道再不难!(附保姆级教程)
人工智能·spring boot·agent
静Yu9 小时前
蚂蚁百宝箱|快速搭建会讲故事、读新闻的智能体
前端·agent
柠檬豆腐脑13 小时前
Trae-Agent中LLM Client深度分析
llm·agent
在努力的韩小豪1 天前
如何从0开始构建自己的第一个AI应用?(Prompt工程、Agent自定义、Tuning)
人工智能·python·llm·prompt·agent·ai应用·mcp
Baihai IDP1 天前
AI 系统架构的演进:LLM → RAG → AI Workflow → AI Agent
人工智能·ai·系统架构·llm·agent·rag·白海科技
柠檬豆腐脑1 天前
Trae-Agent 内置工具深度解析
python·llm·agent