掘金 人工智能 07月13日
Generative agents 编译运行
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文提供了一份详细的Generative Agents部署指南,指导用户如何在本地搭建和运行该项目。内容涵盖了Python环境的准备、OpenAI API Key的申请、代码下载与配置、依赖库的安装、以及environment和simulation服务的启动流程。此外,还介绍了如何运行、保存、重放simulation,以及压缩simulation文件用于演示。最后,针对无法访问OpenAI和演示环境的问题,提供了相应的解决方案和演示地址,帮助用户快速上手。

🔑环境准备:首先,需要安装Python环境,推荐使用conda创建一个Python 3.9.12的虚拟环境,并安装必要的pip包。

🔑API Key与配置:申请OpenAI API Key,并在reverie/backend_server目录下创建utils.py文件,配置API Key、用户名称以及相关路径。

🚀服务启动:启动environment服务,通过访问http://localhost:8000验证是否成功。接着,启动simulation服务,并在控制台中输入命令启动人物角色和创建simulation。

🎬运行与重放:通过http://localhost:8000/simulator_home访问小镇地图,运行simulation。可以保存simulation以便后续加载,并通过http://localhost:8000/replay/访问重放simulation。

💡演示与FAQ:如果无法访问OpenAI,可以直接运行源代码提供的simulation。文章还提供了25个角色的演示版本地址,方便用户体验。此外,还介绍了如何压缩simulation文件用于演示。

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

〇. 准备

    python 环境安装,建议版本 3.9.12。推荐使用 conda 安装环境
conda create -n genagent python=3.9.12 pipconda activate genagent

2. 申请 openai 的 api-key

platform.openai.com/settings/or…

    下载代码

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

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

    创建配置文件,在 reverie/backend_server目录下创建 utils.py,内容如下:
# 替换你的 api-key openai_api_key = "<Your OpenAI API>"# Put your namekey_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

5. 安装依赖库,代码根目录执行 pip install -r requirements.txt

一. 启动

    启动 environment 服务,系统是一个 Django 服务,默认端口是 8000,需要检查系统不要占用。
cd environment/frontend_serverpython manage.py runserver

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

    启动 simulation 服务
cd reverie/backend_serverpython 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:

3. 运行和保存 Simulation

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

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

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

4. 重放之前保存的 simulation

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

    演示 simulation

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

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

二. FAQ

    没办法直接访问 openai 怎么办?
    如果没有 openai 访问条件,可以直接运行源代码中提供的 simulation 运行,查看效果。有演示环境吗?
    25个角色的演示版本地址:https://reverie.herokuapp.com/arXiv_Demo/

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Generative Agents 部署 环境搭建 simulation
相关文章