File size: 789 Bytes
5fc69e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class ContextParser:
    def __init__(self, context: dict):
        self.player = context.get("player_status", {})  # items, actions, location λ“±
        self.game = context.get("game_state", {})       # quest_stage ν•„μˆ˜
        self.npc = context.get("npc_config", {})        # id ν•„μˆ˜
        self.history = context.get("dialogue_history", [])

    def get_filters(self) -> dict:
        return {
            "npc_id": self.npc.get("id"),
            "quest_stage": self.game.get("quest_stage"),
            "location": self.game.get("location") or self.player.get("location")
        }


    def get_dialogue_history(self, max_turns: int = 3) -> str:
        history = self.history[-max_turns:]
        return "\n".join([f"Player: {h['player']}\nNPC: {h['npc']}" for h in history])