Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- game/engine.py +21 -9
game/engine.py
CHANGED
|
@@ -692,24 +692,36 @@ def eat_current(current=None, collection=None, history=None):
|
|
| 692 |
return coll, _append(hist, "assistant", reply)
|
| 693 |
|
| 694 |
|
| 695 |
-
#
|
|
|
|
| 696 |
def get_myco_narrative(current=None):
|
| 697 |
-
#
|
| 698 |
prompt = (
|
| 699 |
"You are Myco, a tiny, emotional mushroom companion. "
|
| 700 |
-
"
|
| 701 |
-
"
|
| 702 |
-
"Be warm, curious, or a little nervous."
|
| 703 |
)
|
| 704 |
|
| 705 |
-
# We pass the 'current' mushroom context so the AI actually
|
| 706 |
-
# knows what it's looking at, but we tell it NOT to output JSON.
|
| 707 |
context = {}
|
| 708 |
if current:
|
| 709 |
context = {"name": current.get("name"), "rarity": current.get("rarity")}
|
| 710 |
|
| 711 |
-
#
|
| 712 |
reply = _llm(prompt, context=context)
|
| 713 |
|
| 714 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 715 |
|
|
|
|
| 692 |
return coll, _append(hist, "assistant", reply)
|
| 693 |
|
| 694 |
|
| 695 |
+
# Myco narrative
|
| 696 |
+
|
| 697 |
def get_myco_narrative(current=None):
|
| 698 |
+
# 1. Personality Prompt
|
| 699 |
prompt = (
|
| 700 |
"You are Myco, a tiny, emotional mushroom companion. "
|
| 701 |
+
"Write a whimsical, mysterious thought about the forest. "
|
| 702 |
+
"DO NOT use JSON. Do NOT use action tags. Just speak naturally."
|
|
|
|
| 703 |
)
|
| 704 |
|
|
|
|
|
|
|
| 705 |
context = {}
|
| 706 |
if current:
|
| 707 |
context = {"name": current.get("name"), "rarity": current.get("rarity")}
|
| 708 |
|
| 709 |
+
# 2. Get the response
|
| 710 |
reply = _llm(prompt, context=context)
|
| 711 |
|
| 712 |
+
# 3. CRITICAL: Aggressive Clean-up
|
| 713 |
+
# If the LLM ignored our "no JSON" instruction, we parse it ourselves.
|
| 714 |
+
if reply:
|
| 715 |
+
# If it's wrapped in JSON, extract the 'thought'
|
| 716 |
+
if reply.strip().startswith("{"):
|
| 717 |
+
try:
|
| 718 |
+
data = json.loads(reply)
|
| 719 |
+
return data.get("thought", "The forest feels deep today... ✨")
|
| 720 |
+
except:
|
| 721 |
+
pass # If it's broken JSON, just return the reply
|
| 722 |
+
|
| 723 |
+
# If it's just raw text, return it
|
| 724 |
+
return reply
|
| 725 |
+
|
| 726 |
+
return "The forest feels deep today... ✨"
|
| 727 |
|