Spaces:
Running
Running
from ..npc.npc_manager import NPCManager | |
from ..npc.npc_base import NPC | |
from ..npc.npc_memory_embedder import embed_npc_memories | |
def setup_initial_scenario() -> NPCManager: | |
""" | |
ํ ์คํธ๋ฅผ ์ํ ์ด๊ธฐ NPC ์๋๋ฅผ ์ค์ ํ๊ณ NPCManager๋ฅผ ๋ฐํํฉ๋๋ค. | |
- 5๋ช ์ NPC ์์ฑ | |
- ๊ฐ๊ธฐ ๋ค๋ฅธ ์ด๊ธฐ ์ฑ๊ฒฉ ๋ฐ ๊ธฐ์ต ๋ถ์ฌ | |
- NPC ๊ฐ์ ์ด๊ธฐ ๊ด๊ณ ์ค์ | |
""" | |
print("์๋ก์ด ์๋๋ฆฌ์ค๋ฅผ ์ค์ ํฉ๋๋ค.: '์์์๋ง์'") | |
npc_manager = NPCManager() | |
# --- 1. NPC ๊ฐ์ฒด ์์ฑ --- | |
# ์๋ฆฐ: ํธ๊ธฐ์ฌ ๋ง๊ณ ๊ฐ์ ์ ์ธ ๋ง๋ฒ์ฌ | |
personality_elin = {"sensitive": 0.8, "stoic": 0.3, "cognitive_bias": 0.7} | |
elin = NPC('elin', "์๋ฆฐ", "๋ง๋ฒ์ฌ", personality=personality_elin) | |
# ๋ฐฅ: ๋ฌด๋๋ํ์ง๋ง ์ ์งํ ๋์ฅ์ฅ์ด | |
personality_bob = {"sensitive": 0.2, "stoic": 0.8, "cognitive_bias": 0.4} | |
bob = NPC('bob', "๋ฐฅ", "๋์ฅ์ฅ์ด", personality=personality_bob) | |
# ์จ๋ฆฌ์ค: ์ฌ๊ต์ ์ด๊ณ ๊ณ์ฐ์ ์ธ ์์ธ | |
personality_alice = {"sensitive": 0.5, "stoic": 0.5, "cognitive_bias": 0.8} | |
alice = NPC('alice', "์จ๋ฆฌ์ค", "์์ธ", personality=personality_alice) | |
# ์ฐฐ๋ฆฌ: ์ฑ์คํ๊ณ ํํ๋ก์ด ๋๋ถ | |
personality_charlie = {"sensitive": 0.6, "stoic": 0.6, "cognitive_bias": 0.3} | |
charlie = NPC('charlie', "์ฐฐ๋ฆฌ", "๋๋ถ", personality=personality_charlie) | |
# ๋ค์ด์ ๋: ์กฐ์ฉํ๊ณ ๊ด์ฐฐ๋ ฅ ์๋ ์ฌ์ | |
personality_diana = {"sensitive": 0.7, "stoic": 0.7, "cognitive_bias": 0.9} | |
diana = NPC('diana', "๋ค์ด์ ๋", "์ฌ์", personality=personality_diana) | |
# ํ๋ ์ด์ด๋ฅผ ์ํ NPC ๊ฐ์ฒด๋ฅผ ์์ฑ | |
# ํ๋ ์ด์ด๋ ๊ณ ์ ID "Player"๋ฅผ ๊ฐ์ง๋ฉฐ, ์ฑ๊ฒฉ์ ๊ฐ์ฅ ๊ท ํ์กํ ์ํ๋ก ์์ | |
player_personality = {"sensitive": 0.5, "stoic": 0.5, "cognitive_bias": 0.5} | |
player = NPC("player", "ํ๋ ์ด์ด", "๋ชจํ๊ฐ", personality=player_personality) | |
# --- 2. ์ด๊ธฐ ๊ธฐ์ต ์ฃผ์ --- | |
elin.remember(content="์ด์ ฏ๋ฐค ์จ๋ฆฌ์ค์ ์์ฅ ๊ฐ๊ฒฉ ๋๋ฌธ์ ํฌ๊ฒ ๋คํ๋ค.", importance=8, emotion="anger") | |
alice.remember(content="์ด์ ฏ๋ฐค ์๋ฆฐ์ด ๋ด๊ฒ ๋ฌด๋กํ๊ฒ ์๋ฆฌ์ณค๋ค.", importance=8, emotion="resentment") | |
bob.remember(content="์ฐฐ๋ฆฌ๊ฐ ์ด์ ์ฐ๋ฆฌ ์ง ์ง๋ถ์ ๊ณ ์ณ์ฃผ์ด์ ๊ณ ๋ง๋ค.", importance=7, emotion="gratitude") | |
charlie.remember(content="๋ฐฅ์ ๋์ฅ๊ฐ ์ผ์ ๋์์ฃผ๊ณ ๋นต์ ์ป์๋ค. ๊ทธ๋ ์ข์ ์น๊ตฌ๋ค.", importance=6, emotion="joy") | |
diana.remember(content="๋์๊ด์์ ๋ฐฅ์ด ์ฑ ์ ๋น๋ ค๊ฐ๋ฉฐ ๊ฑฐ์น ๊ฒ ๋ค๋ฃจ์ด ์กฐ๊ธ ๊ธฐ๋ถ์ด ์ํ๋ค.", importance=5, emotion="disgust") | |
# --- 3. NPC ๋งค๋์ ์ ์ถ๊ฐ --- | |
npc_manager.add_npc(elin) | |
npc_manager.add_npc(bob) | |
npc_manager.add_npc(alice) | |
npc_manager.add_npc(charlie) | |
npc_manager.add_npc(diana) | |
npc_manager.add_npc(player) | |
# --- 4. ์ด๊ธฐ ๊ด๊ณ ์ค์ --- | |
# ์๋ฆฐ <-> ์จ๋ฆฌ์ค (๋์ ๊ด๊ณ) | |
elin.relationships.update_relationship("alice", "anger", strength=5.0) | |
alice.relationships.update_relationship("elin", "resentment", strength=4.0) | |
# ๋ฐฅ <-> ์ฐฐ๋ฆฌ (์ข์ ๊ด๊ณ) | |
bob.relationships.update_relationship("charlie", "gratitude", strength=6.0) | |
charlie.relationships.update_relationship("bob", "joy", strength=7.0) | |
# ๋ค์ด์ ๋ -> ๋ฐฅ (์ฝ๊ฐ ๋ถ์ ์ ) | |
diana.relationships.update_relationship("bob", "disgust", strength=3.0) | |
# ์๋ฆฐ, ์ฐฐ๋ฆฌ <-> ํ๋ ์ด์ด (๋ฏ์ ์ฌ๋) | |
elin.relationships.update_relationship("player", "neutral", strength=0.0) | |
charlie.relationships.update_relationship("player", "neutral", strength=0.0) | |
# --- 5. ์ด๊ธฐ ์ง์ ๋ฒ ์ด์ค ์ค์ --- | |
all_npc = npc_manager.get_all_npcs_except_player() # ํ๋ ์ด์ด๋ฅผ ์ ์ธํ NPC ๋ชฉ๋ก | |
for npc in all_npc: | |
for other_npc in all_npc: | |
if npc != other_npc: | |
npc.knowledge[other_npc.name] = { "job": other_npc.job, # ๋ชจ๋ NPC๊ฐ ์๋ก์ ์ง์ ์ ์๊ณ ์์ํ๋๋ก ์ค์ | |
"age": other_npc.age # ๋ชจ๋ NPC๊ฐ ์๋ก์ ๋์ด๋ฅผ ์๊ณ ์์ํ๋๋ก ์ค์ | |
} | |
# ๋ชจ๋ NPC์ ์ด๊ธฐ ๊ธฐ์ต์ FAISS ์ธ๋ฑ์ค๋ก ์ ์ฅ | |
print("๋ชจ๋ NPC์ ์ด๊ธฐ ๊ธฐ์ต์ ๋ํ FAISS ์ธ๋ฑ์ค๋ฅผ ์์ฑํฉ๋๋ค...") | |
for npc in npc_manager.all(): | |
embed_npc_memories(npc) | |
print("โ '์์์ ๋ง์' ์๋๋ฆฌ์ค ์ค์ ์ด ์๋ฃ๋์์ต๋๋ค.") | |
return npc_manager |