feat: add MMGame backend and frontend source code
This commit is contained in:
@@ -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"}
|
||||
Reference in New Issue
Block a user