Spaces:
Sleeping

byte-vortex commited on
Commit
5b53e04
·
verified ·
1 Parent(s): d6a5873

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. game/engine.py +25 -1
game/engine.py CHANGED
@@ -667,11 +667,35 @@ def _pattern_notice(current, collection):
667
  def _recent_conversation(history):
668
  """Return a compact summary of recent player/Myco conversation turns."""
669
  turns = []
 
670
  for entry in _safe_history(history)[-6:]:
671
  role = entry.get("role", "assistant")
672
- content = entry.get("content", "").replace("\n", " ").strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673
  if content:
674
  turns.append(f"{role}: {content[:120]}")
 
675
  return " | ".join(turns) if turns else "No conversation yet."
676
 
677
 
 
667
  def _recent_conversation(history):
668
  """Return a compact summary of recent player/Myco conversation turns."""
669
  turns = []
670
+
671
  for entry in _safe_history(history)[-6:]:
672
  role = entry.get("role", "assistant")
673
+ content = entry.get("content", "")
674
+
675
+ # 1. Handle Gradio's list format (multimodal messages)
676
+ if isinstance(content, list):
677
+ pieces = []
678
+ for item in content:
679
+ if isinstance(item, dict):
680
+ # Extract text from dict, fallback to empty string if it's purely a file
681
+ if "text" in item:
682
+ pieces.append(item["text"])
683
+ elif isinstance(item, str):
684
+ pieces.append(item)
685
+ elif isinstance(item, tuple):
686
+ pieces.append("[Attachment]")
687
+ content = " ".join(pieces)
688
+
689
+ # 2. Handle Gradio's tuple format (old-style direct file uploads)
690
+ elif isinstance(content, tuple):
691
+ content = "[Attachment]"
692
+
693
+ # 3. Force to string and safely clean up
694
+ content = str(content).replace("\n", " ").strip()
695
+
696
  if content:
697
  turns.append(f"{role}: {content[:120]}")
698
+
699
  return " | ".join(turns) if turns else "No conversation yet."
700
 
701