humanda5 commited on
Commit
8411a77
ยท
1 Parent(s): 3b5daf4
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
- # ์ˆ˜์ • ํ•„์š”: ์ƒ๋Œ€ NPC๊ฐ€ ๋žœ๋ค์ด ์•„๋‹ˆ๋ผ, ์ƒํ˜ธ์ž‘์šฉํ•  ๋งŒํ•œ ๊ทผ๊ฑฐ๊ฐ€ ์žˆ์–ด์•ผํ•œ๋‹ค.
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