feat: add MMGame backend and frontend source code

This commit is contained in:
gmh01
2026-08-01 21:30:23 +08:00
parent 26ce0dd600
commit c176c04aab
42 changed files with 3606 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
from app.agents.ai import npc_generate
class NPCAgent:
def __init__(self, role: dict, background: str, public_info: str):
self.role = role
self.background = background
self.public_info = public_info
self.memory = []
async def respond(self, phase_name: str, recent_messages: list = None, player_message: str = "", is_private: bool = False,
known_clues: list[str] = None, phase_goal: str = "", all_roles: list[dict] = None) -> dict:
if recent_messages is None:
recent_messages = []
recent = [
f"{m.get('sender_name', m.get('sender', ''))}: {m.get('content', '')}"
for m in recent_messages[-5:]
]
result = await npc_generate(self.role, self.background, phase_name, recent, player_message, is_private,
known_clues, phase_goal, all_roles)
if result:
content = result.get("content", "")
if content:
self.memory.append({"role": "assistant", "content": content})
return result
return {"content": f"{self.role['name']}陷入了沉思……", "action": "speak"}