Spaces:
Sleeping

byte-vortex commited on
Commit
2f03292
·
verified ·
1 Parent(s): 624ae2f

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. game/engine.py +61 -9
game/engine.py CHANGED
@@ -694,17 +694,69 @@ def eat_current(current=None, collection=None, history=None):
694
 
695
  # Updated get_myco_narrative to use the real engine
696
 
 
 
 
 
 
 
 
 
 
697
  def get_myco_narrative():
698
- prompt = "Write a very short, friendly thought about mushrooms or the forest."
699
- reply = _llm(prompt, context={})
 
 
 
 
 
 
 
 
 
 
 
 
700
 
 
 
 
 
 
 
 
 
701
  if not reply:
702
- return "The mycelium is dreaming... ✨"
703
-
704
- # Attempt to extract just the 'thought' field if it's JSON
705
  try:
706
  data = json.loads(reply)
707
- return data.get("thought", reply) # Return 'thought' if it exists, else raw reply
708
- except:
709
- return reply # Return raw if it's not JSON
710
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
694
 
695
  # Updated get_myco_narrative to use the real engine
696
 
697
+ FALLBACK_NARRATIVES = [
698
+ "🌲 The trees lean closer, listening for something only Myco can hear.",
699
+ "🌌 A forgotten memory drifts through the roots beneath your feet.",
700
+ "🍂 Somewhere in the forest, a mushroom blooms where none should grow.",
701
+ "📖 The MycoDex trembles as if trying to remember a missing page.",
702
+ "✨ Strange spores glitter briefly before vanishing into the darkness.",
703
+ "🔮 Myco pauses. This clearing feels familiar, though it has never been here before.",
704
+ ]
705
+
706
  def get_myco_narrative():
707
+ prompt = """
708
+ You are the narrator of Myco, a cozy mushroom adventure game.
709
+
710
+ Write a short story fragment (1-3 sentences, under 200 characters).
711
+
712
+ Requirements:
713
+ - Cute and wholesome.
714
+ - Feature Myco, a tiny sentient mushroom.
715
+ - Set in a magical forest.
716
+ - Include wonder, curiosity, friendship, or discovery.
717
+ - No dialogue.
718
+ - No explanations.
719
+ - No lists.
720
+ - Plain text only.
721
 
722
+ Examples:
723
+ 🍄 Myco found a dewdrop larger than its cap and spent the morning studying the tiny rainbow inside.
724
+ 🌿 A sleepy snail shared a patch of moss with Myco while fireflies painted the forest gold.
725
+ ✨ Myco discovered a glowing mushroom ring and carefully counted every sparkle before sunset.
726
+ """
727
+
728
+ reply = _llm(prompt, context={})
729
+
730
  if not reply:
731
+ return random.choice(FALLBACK_NARRATIVES)
732
+
 
733
  try:
734
  data = json.loads(reply)
735
+
736
+ if isinstance(data, dict):
737
+ text = (
738
+ data.get("narrative")
739
+ or data.get("story")
740
+ or data.get("thought")
741
+ or data.get("text")
742
+ )
743
+
744
+ if text:
745
+ return str(text).strip()
746
+
747
+ except Exception:
748
+ pass
749
+
750
+ text = str(reply).strip()
751
+
752
+ # Guard against broken model outputs
753
+ if (
754
+ not text
755
+ or len(text) < 10
756
+ or "unused" in text.lower()
757
+ or "\\" in text
758
+ or "{" in text
759
+ ):
760
+ return random.choice(FALLBACK_NARRATIVES)
761
+
762
+ return text