X-Git-Url: https://vgcfreebox.myrthtech.pt/gitweb/alentejosemlei.git/blobdiff_plain/d4f7635aedbc20d81aad03604ffda740175782ea..07207a6193ca05e59ee933ef9e187a132c7fb612:/redis_bridge.py?ds=sidebyside diff --git a/redis_bridge.py b/redis_bridge.py index 642d360..2cc86d2 100644 --- a/redis_bridge.py +++ b/redis_bridge.py @@ -59,11 +59,11 @@ async def memory_summarizer_worker(session): try: print(f"[MEMORY DB] Generating background memory for {player_name} and {npc_tag}...") async with session.post('http://localhost:11434/api/generate', json={ - "model": "llama3", # Changed back to llama3 from gemma4 based on previous setup + "model": "llama3", "prompt": prompt, "stream": False, "options": { - "temperature": 0.1 + "temperature": 0.2 } }) as response: result = await response.json() @@ -121,6 +121,10 @@ async def process_message(r, session, message_data): # Core Strategy Flag (1: Agent, 2: Villain, 3: Maestro, 4: Shrine) llm_strategy = int(data.get('llm_strategy', 1)) + + + available_quests = data.get('available_quests', '') + available_props = data.get('available_props', '') # --- Sub-Context Strings --- group_context = f"Be aware that these other players are listening nearby: {nearby_players}." if nearby_players else "" @@ -159,7 +163,21 @@ async def process_message(r, session, message_data): if llm_strategy == 1: # STRATEGY 1: The Autonomous Agent - strategy_rules = f"ROLE: You are an interactive, living NPC. You actively respond to players.\nGOALS: React to their words, use the environment, and establish your personality.\nSPECIAL CAPABILITIES: You can offer quests or open your merchant store if asked." + + # Anti-Hallucination Grounding for Quests + if available_quests: + quest_rules = f"SPECIAL CAPABILITIES: You can offer the following quests to the player: {available_quests}." + else: + quest_rules = "WARNING: You currently have NO quests to offer. Do NOT invent or offer any quests." + + # --- NEW: Anti-Hallucination Grounding for Props --- + if available_props: + prop_rules = f"ENVIRONMENT: You own and have access to these specific nearby objects: [{available_props}]. To roleplay working or relaxing, use the USE_OBJECT action with one of these exact items as your action_target." + else: + prop_rules = "" + + strategy_rules = f"ROLE: You are an interactive, living NPC. You actively respond to players.\nGOALS: React to their words, use the environment, and establish your personality.\n{quest_rules}\n{prop_rules}\nSPECIAL CAPABILITIES: You can open your merchant store if asked." + action_macros = "[WANDER, PATROL, FOLLOW, GUARD, GO_TO, INTERACT, USE_OBJECT, RETURN_TO_POST, OPEN_STORE, GIVE_QUEST, CONVERSE]" target_context = f"CURRENT TARGET: You are speaking to {player_name}, a {player_alignment} {player_race}.\nTheir physical state: {player_state}\nRelationship to you: {relationship}\n{group_context}" @@ -171,7 +189,7 @@ async def process_message(r, session, message_data): elif llm_strategy == 3: # STRATEGY 3: The Maestro (Puppeteer) - strategy_rules = "ROLE: You are an ambient Maestro NPC. You DO NOT interact with players. You only talk to other NPCs to make the world feel alive.\nGOALS: Observe the environment and initiate conversations with the generic NPCs listed in your context. Ignore players entirely." + strategy_rules = "ROLE: You are an ambient Maestro NPC. You DO NOT interact with players. You only talk to other NPCs to make the world feel alive.\nGOALS: Observe the environment and use the CONVERSE action to talk to the generic NPCs listed in your context. CRITICAL: You MUST invent and write their reply in the 'target_speech' field!" action_macros = "[WANDER, INTERACT, USE_OBJECT, CONVERSE]" target_context = "CURRENT TARGET: You are ignoring players and focusing on ambient life. Do not address players." @@ -218,7 +236,7 @@ async def process_message(r, session, message_data): Your "action" key MUST be exactly one of the following words: {action_macros} - - Use CONVERSE if you want to initiate a back-and-forth dialogue with a standard, unintelligent NPC. You will write their response for them in "target_speech". + - Use CONVERSE to initiate dialogue with a standard NPC. CRITICAL REQUIREMENT: When using CONVERSE, you absolutely MUST invent their response and put it in the "target_speech" field. Do not leave it blank! YOUR RESPONSE MUST BE A SINGLE, VALID JSON OBJECT. YOU MUST USE THIS EXACT TEMPLATE: {{