]> vgcfreebox.myrthtech.pt Git - alentejosemlei.git/blobdiff - redis_bridge.py
locking redis db to conections from machine only
[alentejosemlei.git] / redis_bridge.py
index 97f27e9b93e564982bdc16e6d563790fafa425fa..6c7be23673e29713b533a370ab281db03f739a4f 100644 (file)
@@ -33,10 +33,15 @@ async def process_message(r, session, message_data):
         if session_id not in chat_memory:
             chat_memory[session_id] = [{"role": "system", "content": NPC_SYSTEM_PROMPT}]
 
         if session_id not in chat_memory:
             chat_memory[session_id] = [{"role": "system", "content": NPC_SYSTEM_PROMPT}]
 
-        # 3. Add the player's new message to their specific history
-        print(f"\n[RECEIVED] {player_name} -> {npc_tag}: '{message}'")
+        # 3. Add the player's new message
         chat_memory[session_id].append({"role": "user", "content": f"{player_name} says: {message}"})
 
         chat_memory[session_id].append({"role": "user", "content": f"{player_name} says: {message}"})
 
+        # --- THE SLIDING WINDOW FIX ---
+        # If the memory gets longer than 11 messages (1 system prompt + 10 chat messages)
+        if len(chat_memory[session_id]) > 11:
+            # Keep the system prompt at index [0], and grab the 10 most recent messages
+            chat_memory[session_id] = [chat_memory[session_id][0]] + chat_memory[session_id][-10:]
+
         # 4. The Semaphore Bouncer: Wait in line if the GPU is currently full
         async with semaphore:
             print(f"[THINKING] Processing reply for {player_name}...")
         # 4. The Semaphore Bouncer: Wait in line if the GPU is currently full
         async with semaphore:
             print(f"[THINKING] Processing reply for {player_name}...")