Spaces:
Running
Running
주제가 있는 대화 기능 추가 완료
Browse files
npc_social_network/npc/npc_manager.py
CHANGED
@@ -52,45 +52,56 @@ class NPCManager:
|
|
52 |
"""관리 중인 모든 NPC의 리스트를 반환합니다."""
|
53 |
return self.npcs
|
54 |
|
55 |
-
def initiate_npc_to_npc_interaction(self,
|
|
|
56 |
"""
|
57 |
NPC 간의 상호작용을 시작시키는 함수
|
58 |
- 참여한 NPC를 반환해서 소문을 퍼트릴 '목격자' 생성
|
|
|
59 |
"""
|
60 |
from ..models.llm_helper import query_llm_with_prompt
|
61 |
|
62 |
if len(self.npcs) < 2:
|
63 |
return None, None # 상호작용할 NPC가 최소 2명 필요
|
64 |
|
65 |
-
# 상호작용을 시작할 NPC (initiator)와 대상 NPC (target)를 랜덤으로 선택
|
66 |
-
initiator = self.get_random_npc()
|
67 |
-
target = self.get_random_npc(exclude=initiator)
|
68 |
-
|
69 |
-
if not initiator or not target:
|
70 |
-
return
|
71 |
-
|
72 |
initiator_postposition = get_korean_postposition(initiator.korean_name, "이", "가")
|
73 |
target_postposition = get_korean_postposition(target.korean_name, "에게", "에게")
|
74 |
|
75 |
print(f"\n---[NPC 상호작용 이벤트]---\n{initiator.korean_name}{initiator_postposition} {target.korean_name}{target_postposition} 상호작용을 시도합니다.")
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
83 |
|
84 |
-
|
85 |
-
|
86 |
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
initial_utterance = query_llm_with_prompt(prompt).replace("'", "").strip()
|
90 |
|
91 |
if "[LLM Error]" in initial_utterance:
|
92 |
print(f"[{initiator.korean_name}] 대화 시작에 실패했습니다.")
|
93 |
-
return None, None
|
94 |
|
95 |
print(f"[{initiator.korean_name}]: {initial_utterance}")
|
96 |
|
|
|
52 |
"""관리 중인 모든 NPC의 리스트를 반환합니다."""
|
53 |
return self.npcs
|
54 |
|
55 |
+
def initiate_npc_to_npc_interaction(self, initiator: 'NPC', target: 'NPC',
|
56 |
+
time_context: str, topic: Optional[str] = None):
|
57 |
"""
|
58 |
NPC 간의 상호작용을 시작시키는 함수
|
59 |
- 참여한 NPC를 반환해서 소문을 퍼트릴 '목격자' 생성
|
60 |
+
- 주제가 있을 경우, 목표 지향적 대화를 생성
|
61 |
"""
|
62 |
from ..models.llm_helper import query_llm_with_prompt
|
63 |
|
64 |
if len(self.npcs) < 2:
|
65 |
return None, None # 상호작용할 NPC가 최소 2명 필요
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
initiator_postposition = get_korean_postposition(initiator.korean_name, "이", "가")
|
68 |
target_postposition = get_korean_postposition(target.korean_name, "에게", "에게")
|
69 |
|
70 |
print(f"\n---[NPC 상호작용 이벤트]---\n{initiator.korean_name}{initiator_postposition} {target.korean_name}{target_postposition} 상호작용을 시도합니다.")
|
71 |
+
|
72 |
+
if topic:
|
73 |
+
# 주제가 있는 경우
|
74 |
+
prompt = f"""
|
75 |
+
# 지시사항
|
76 |
+
나는 '{initiator.korean_name}'입니다.
|
77 |
+
지금 나는 '{target.korean_name}'와 마주쳤습니다.
|
78 |
+
나는 상대에게 '{topic}'에 대해 이야기하고 싶습니다.
|
79 |
+
이 주제로 대화를 시작할 자연스러운 첫 마디를 생성하세요.
|
80 |
|
81 |
+
# 당신의 정보
|
82 |
+
- '{target.korean_name}'와의 관계: {initiator.relationships.get_relationship_summary(target.name)}
|
83 |
|
84 |
+
→ 첫 마디:
|
85 |
+
"""
|
86 |
+
else:
|
87 |
+
# 주제가 없는 경우 (기존의 가벼운 인사)
|
88 |
+
prompt = f"""
|
89 |
+
# 지시사항
|
90 |
+
나는 '{initiator.korean_name}'입니다.
|
91 |
+
지금 나는 '{target.korean_name}'와 마주쳤습니다.
|
92 |
+
'{target.korean_name}'에 대한 당신의 현재 생각과 감정을 바탕으로, 먼저 건넬 자연스러운 첫 마디를 생성하세요.
|
93 |
+
(예: "앨리스, 어제 시장에서 파는 그 옷 정말 예쁘더라.", "밥, 요즘 허리가 아프다던데 괜찮아?")
|
94 |
+
|
95 |
+
# 나의 정보
|
96 |
+
- '{target.korean_name}'와의 관계: {initiator.relationships.get_relationship_summary(target.name)}
|
97 |
+
|
98 |
+
→ 첫 마디:
|
99 |
+
"""
|
100 |
initial_utterance = query_llm_with_prompt(prompt).replace("'", "").strip()
|
101 |
|
102 |
if "[LLM Error]" in initial_utterance:
|
103 |
print(f"[{initiator.korean_name}] 대화 시작에 실패했습니다.")
|
104 |
+
return None, None, None
|
105 |
|
106 |
print(f"[{initiator.korean_name}]: {initial_utterance}")
|
107 |
|