byte-vortex commited on
Commit
f9703b3
·
verified ·
1 Parent(s): 6089f10

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. game/engine.py +41 -25
game/engine.py CHANGED
@@ -840,35 +840,51 @@ def check_auto_pickup(new_pos_x, new_pos_y, current, collection, active_mushroom
840
 
841
  # Myco narrative
842
  def get_myco_narrative(current=None):
843
- # 1. Personality Prompt - Made more aggressive
844
  prompt = (
845
- "You are Myco Poet, a tiny, emotional mushroom companion. "
846
- "Speak in one or two sentences about the forest. "
847
- "ABSOLUTELY NO JSON. NO BRACKETS. NO THOUGHT BLOCKS. "
848
- "Speak like a person, not a computer. "
849
- "Create a few sentences. "
 
850
  )
851
-
852
- context = {"name": current.get("name", "mystery"), "rarity": current.get("rarity", "common")} if current else {}
853
-
854
- # 2. Get the response
 
 
 
 
 
855
  reply = _llm(prompt, context=context)
856
-
857
  if not reply:
858
  return "The forest feels deep today... ✨"
859
 
860
- # 3. Aggressive Clean-up: If it contains JSON, strip it away
861
- # This regex removes anything inside {} or []
862
- cleaned_reply = re.sub(r'\{.*\}|\[.*\]', '', reply)
863
-
864
- # Remove keys like "thought": or "thought"
865
- cleaned_reply = re.sub(r'"thought":|thought:', '', cleaned_reply, flags=re.IGNORECASE)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
866
 
867
- # Remove extra quotes and whitespace
868
- cleaned_reply = cleaned_reply.replace('"', '').strip()
869
-
870
- # If the clean-up resulted in an empty string, fallback
871
- if not cleaned_reply:
872
- return "The forest feels deep today... ✨"
873
-
874
- return cleaned_reply
 
840
 
841
  # Myco narrative
842
  def get_myco_narrative(current=None):
843
+ # 1. Strong, format-constrained prompt (prevents structured leakage)
844
  prompt = (
845
+ "You are Myco Poet, a tiny emotional mushroom companion living in a forest.\n"
846
+ "Write EXACTLY 1–2 short poetic sentences.\n"
847
+ "Do NOT output JSON, brackets, lists, labels, or metadata.\n"
848
+ "Do NOT use {} or [].\n"
849
+ "Do NOT describe yourself as an AI or system.\n"
850
+ "Only output natural language forest poetry.\n"
851
  )
852
+
853
+ # 2. Context (kept minimal but useful)
854
+ context = None
855
+ if current:
856
+ context = {
857
+ "name": current.get("name", "mystery"),
858
+ "rarity": current.get("rarity", "common")
859
+ }
860
+
861
  reply = _llm(prompt, context=context)
862
+
863
  if not reply:
864
  return "The forest feels deep today... ✨"
865
 
866
+ # 3. Safer cleanup (non-greedy, avoids nuking valid text)
867
+ def strip_noise(text: str) -> str:
868
+ text = re.sub(r'\{[^{}]*\}', '', text) # remove simple JSON blocks only
869
+ text = re.sub(r'\[[^\[\]]*\]', '', text) # remove simple bracket blocks only
870
+ text = re.sub(r'"(thought|response|text)"\s*:\s*', '', text, flags=re.I)
871
+ text = text.replace('"', '')
872
+ return text.strip()
873
+
874
+ cleaned = strip_noise(reply)
875
+
876
+ # 4. Validation gate (prevents garbage passing through)
877
+ def is_valid(text: str) -> bool:
878
+ if not text:
879
+ return False
880
+ if text.strip().startswith(("{", "[")):
881
+ return False
882
+ if len(text) < 5:
883
+ return False
884
+ return True
885
+
886
+ if not is_valid(cleaned):
887
+ return "The forest hums softly with unseen life... ✨"
888
+
889
+ return cleaned
890