Spaces:
Sleeping
Sleeping
humanda5
commited on
Commit
ยท
8411a77
1
Parent(s):
3b5daf4
corr
Browse files
npc_social_network/npc/npc_manager.py
CHANGED
@@ -26,8 +26,8 @@ class NPCManager:
|
|
26 |
def get_random_npc(self, exclude: Optional['NPC']=None) -> Optional['NPC']:
|
27 |
"""
|
28 |
ํน์ NPC๋ฅผ ์ ์ธํ๊ณ ๋๋คํ NPC๋ฅผ ์ ํ
|
29 |
-
|
30 |
-
|
31 |
"""
|
32 |
possible_targets = [n for n in self.npcs if n != exclude]
|
33 |
if not possible_targets:
|
@@ -41,11 +41,12 @@ class NPCManager:
|
|
41 |
def initiate_npc_to_npc_interaction(self, time_context: str):
|
42 |
"""
|
43 |
NPC ๊ฐ์ ์ํธ์์ฉ์ ์์์ํค๋ ํจ์
|
|
|
44 |
"""
|
45 |
from ..models.llm_helper import query_llm_with_prompt
|
46 |
|
47 |
if len(self.npcs) < 2:
|
48 |
-
return # ์ํธ์์ฉํ NPC๊ฐ ์ต์ 2๋ช
ํ์
|
49 |
|
50 |
# ์ํธ์์ฉ์ ์์ํ NPC (initiator)์ ๋์ NPC (target)๋ฅผ ๋๋ค์ผ๋ก ์ ํ
|
51 |
initiator = self.get_random_npc()
|
@@ -72,7 +73,7 @@ class NPCManager:
|
|
72 |
|
73 |
if "[LLM Error]" in initial_utterance:
|
74 |
print(f"[{initiator.name}] ๋ํ ์์์ ์คํจํ์ต๋๋ค.")
|
75 |
-
return
|
76 |
|
77 |
print(f"[{initiator.name}]: {initial_utterance}")
|
78 |
|
@@ -86,4 +87,5 @@ class NPCManager:
|
|
86 |
|
87 |
print(f"[{target.name}]: {response_utterance}")
|
88 |
print("-------------------------\n")
|
|
|
89 |
|
|
|
26 |
def get_random_npc(self, exclude: Optional['NPC']=None) -> Optional['NPC']:
|
27 |
"""
|
28 |
ํน์ NPC๋ฅผ ์ ์ธํ๊ณ ๋๋คํ NPC๋ฅผ ์ ํ
|
29 |
+
์์ ํ์: ์๋ NPC๊ฐ ๋๋ค์ด ์๋๋ผ, ์ํธ์์ฉํ ๋งํ ๊ทผ๊ฑฐ๊ฐ ์์ด์ผํ๋ค.
|
30 |
+
์) ๊ทผ์ฒ์ ์ฐ๋ค, ํน๋ณํ ์ด๋ฒคํธ๊ฐ ์์๋ค ๋ฑ ๊ณผ ๊ฐ์ ์ด์
|
31 |
"""
|
32 |
possible_targets = [n for n in self.npcs if n != exclude]
|
33 |
if not possible_targets:
|
|
|
41 |
def initiate_npc_to_npc_interaction(self, time_context: str):
|
42 |
"""
|
43 |
NPC ๊ฐ์ ์ํธ์์ฉ์ ์์์ํค๋ ํจ์
|
44 |
+
- ์ฐธ์ฌํ NPC๋ฅผ ๋ฐํํด์ ์๋ฌธ์ ํผํธ๋ฆด '๋ชฉ๊ฒฉ์' ์์ฑ
|
45 |
"""
|
46 |
from ..models.llm_helper import query_llm_with_prompt
|
47 |
|
48 |
if len(self.npcs) < 2:
|
49 |
+
return None, None # ์ํธ์์ฉํ NPC๊ฐ ์ต์ 2๋ช
ํ์
|
50 |
|
51 |
# ์ํธ์์ฉ์ ์์ํ NPC (initiator)์ ๋์ NPC (target)๋ฅผ ๋๋ค์ผ๋ก ์ ํ
|
52 |
initiator = self.get_random_npc()
|
|
|
73 |
|
74 |
if "[LLM Error]" in initial_utterance:
|
75 |
print(f"[{initiator.name}] ๋ํ ์์์ ์คํจํ์ต๋๋ค.")
|
76 |
+
return None, None
|
77 |
|
78 |
print(f"[{initiator.name}]: {initial_utterance}")
|
79 |
|
|
|
87 |
|
88 |
print(f"[{target.name}]: {response_utterance}")
|
89 |
print("-------------------------\n")
|
90 |
+
return initiator, target, initial_utterance
|
91 |
|
npc_social_network/simulation_core.py
CHANGED
@@ -70,38 +70,3 @@ def initialize_simulation():
|
|
70 |
simulation_thread = threading.Thread(target=simulation_loop, daemon=True)
|
71 |
simulation_thread.start()
|
72 |
|
73 |
-
def process_interaction_and_witness(npc1, npc2):
|
74 |
-
"""๋ NPC์ ์ํธ์์ฉ๊ณผ ์ด๋ฅผ ๋ชฉ๊ฒฉํ๋ ์ 3์๋ฅผ ์ฒ๋ฆฌํฉ๋๋ค."""
|
75 |
-
global npc_manager, event_log
|
76 |
-
|
77 |
-
# 1. ๋ NPC ๊ฐ์ ์ํธ์์ฉ (๊ธฐ์กด ๋ก์ง)
|
78 |
-
# ... (์: npc1์ด npc2์๊ฒ ๋ง์ ๊ฑฐ๋ ๋ก์ง) ...
|
79 |
-
# dialogue = npc1.generate_dialogue(f"{npc2.name}์๊ฒ ์ธ์ฌ๋ฅผ ๊ฑด๋ค.", "์คํ", target_npc=npc2)
|
80 |
-
# interaction_content = f"{npc1.name} -> {npc2.name}: {dialogue}"
|
81 |
-
# interaction_emotion = npc1.emotion.get_dominant_emotion()
|
82 |
-
|
83 |
-
# --- [ํต์ฌ ๋ก์ง ์์] ---
|
84 |
-
|
85 |
-
# 2. ๋ชฉ๊ฒฉ์ ์ ์ (๋ NPC๋ฅผ ์ ์ธํ ๋๋จธ์ง ์ค ๋๋ค ์ ํ)
|
86 |
-
potential_witnesses = [npc for npc in npc_manager.all() if npc not in [npc1, npc2]]
|
87 |
-
if not potential_witnesses:
|
88 |
-
return
|
89 |
-
|
90 |
-
witness = random.choice(potential_witnesses)
|
91 |
-
|
92 |
-
# 3. ๋ชฉ๊ฒฉํ ์ด๋ฒคํธ์ ๋ํ '์๋ฌธ' ๋ด์ฉ ์์ฑ
|
93 |
-
# (LLM์ ์ฌ์ฉํด ๋ ์์ฐ์ค๋ฌ์ด ์๋ฌธ์ ์์ฑํ ์๋ ์์ต๋๋ค)
|
94 |
-
gossip_content = f"'{npc1.name}'์(๊ณผ) '{npc2.name}'์ด(๊ฐ) ์๋ก ์ด์ผ๊ธฐํ๋ ๊ฒ์ ๋ดค๋ค."
|
95 |
-
# ๋ง์ฝ ์ํธ์์ฉ์ ๊ฐํ ๊ฐ์ ์ด ์์๋ค๋ฉด ์๋ฌธ์ ํฌํจ
|
96 |
-
# if interaction_emotion in ["anger", "sadness", "joy"]:
|
97 |
-
# gossip_content += f" ๋ถ์๊ธฐ๊ฐ ๋งค์ฐ {interaction_emotion}ํด ๋ณด์๋ค."
|
98 |
-
|
99 |
-
# 4. ๋ชฉ๊ฒฉ์๊ฐ '์๋ฌธ'์ ๊ธฐ์ตํ๋๋ก ํจ
|
100 |
-
# ์ค์๋: ์ง์ ๊ฒช์ ์ผ๋ณด๋ค ๋ฎ๊ฒ ์ค์
|
101 |
-
witness.remember(
|
102 |
-
content=gossip_content,
|
103 |
-
importance=4,
|
104 |
-
emotion="curiosity", # ์๋ฌธ์ ๋ค์์ ๋์ ๊ฐ์
|
105 |
-
memory_type="Gossip" # ์ด๊ฒ์ด ์๋ฌธ์์ ๋ช
์
|
106 |
-
)
|
107 |
-
add_log(f"[๋ชฉ๊ฒฉ] {witness.name}์ด(๊ฐ) {npc1.name}์(๊ณผ) {npc2.name}์ ์ํธ์์ฉ์ ๋ชฉ๊ฒฉํ์ต๋๋ค.")
|
|
|
70 |
simulation_thread = threading.Thread(target=simulation_loop, daemon=True)
|
71 |
simulation_thread.start()
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|