Generative Agents: Interactive Simulacra of Human Behavior 実装方法

本ページは個人利用目的のメモ程度のページであり、私のページによって生じたあらゆる損失に対して私は責任を負わないことをここに示す。


前置き

当ページは以下の論文(Generative Agents: Interactive Simulacra of Human Behavior)にて公開されているデモの実装方法を説明したものとなる。

GitHubにてコードが共有されている。

こちらのREADME.mdを見れば実装することが可能だが、本ページではより噛み砕いて説明する。

実装環境

チップ:Apple M1
macOS:Sonoma 14.3

リポジトリをクローン

  • カレントワーキングディレクトリをリポジトリをクローンしたい場所に移動

  • 以下のコードを入力し、リポジトリをクローン

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

環境の設定

  • Visual Studio Codeなどの任意のコードエディタを開き、クローンした"generative_agents"ファイルを開く

  •  reverie/backend_serverの下にutils.pyというファイルを作成

  • 以下のコードをutils.pyに貼り付ける

# Copy and paste your OpenAI 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
  • <Your OpenAI API>と<Name>を自身のものに変更

  • ターミナルでカレントワーキングディレクトリをgenerative_agentsに移動

  • 以下のコマンドを入力

pip install -r requirements.txt

シミュレーションの実行

環境サーバの起動

  • ターミナルでカレントワーキングディレクトリをenvironment/frontend_serverに移動

  • 以下のコードを入力

python3 manage.py runserver
  • http://localhost:8000/にアクセスして、以下の画面のようになっていれば成功。
    ※シミュレーションの実行中は環境サーバーが継続して実行されていることを確認するため、このコマンドライン タブを開いたままにしてください。

サーバの立ち上げに成功

シミュレーションサーバの起動

  • ターミナルでカレントワーキングディレクトリをreverie/backend_server に移動

  • そして 以下のコードを実行

python3 reverie.py
  • "Enter the name of the forked simulation: "と聞かれたら、以下のように入力

base_the_ville_isabella_maria_klaus
  • "Enter the name of the new simulation: "と聞かれたら、以下のように入力

test-simulation
  • "Enter option: "と聞かれたら、以下のコードの<step-count>を任意の数字に変え実行する。(例えばステップ500がよければrun 500のようにして実行)

run <step-count>

終わりに

ここまでがデモ実装の手順である。シミュレーションのリプレイ、保存場所、カスタマイズなどの説明は今回は省略した。さらに詳しく知りたい人はREADME.mdにて確認していただきたい。


この記事が気に入ったらサポートをしてみませんか?