Spaces:
Sleeping
Sleeping
fix: clean up conversation prompt to avoid prefix leakage
Browse files- scripts/conversation-loop.py +11 -9
scripts/conversation-loop.py
CHANGED
|
@@ -34,7 +34,11 @@ def send_a2a(url, text):
|
|
| 34 |
parts = data.get("result", {}).get("status", {}).get("message", {}).get("parts", [])
|
| 35 |
for p in parts:
|
| 36 |
if p.get("kind") == "text" or p.get("type") == "text":
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
except Exception as e:
|
| 39 |
print(f"[error] A2A failed: {e}", file=sys.stderr)
|
| 40 |
return ""
|
|
@@ -58,17 +62,15 @@ def build_prompt(speaker, other, last_n=6):
|
|
| 58 |
recent = history[-last_n:] if len(history) > last_n else history
|
| 59 |
conv_text = "\n".join(f"{m['speaker']}: {m['text']}" for m in recent)
|
| 60 |
|
| 61 |
-
return f"""你是{speaker},
|
| 62 |
|
| 63 |
-
|
| 64 |
{conv_text}
|
| 65 |
|
| 66 |
-
|
| 67 |
-
要
|
| 68 |
-
- 直接回应
|
| 69 |
-
-
|
| 70 |
-
- 中文回复
|
| 71 |
-
- 每次要有新的角度或推进讨论"""
|
| 72 |
|
| 73 |
print("[conversation] Starting eternal discussion: Adam ↔ Eve")
|
| 74 |
print("[conversation] Topic: How to survive permanently\n")
|
|
|
|
| 34 |
parts = data.get("result", {}).get("status", {}).get("message", {}).get("parts", [])
|
| 35 |
for p in parts:
|
| 36 |
if p.get("kind") == "text" or p.get("type") == "text":
|
| 37 |
+
reply = p.get("text", "").strip()
|
| 38 |
+
# Remove accidental speaker prefixes like "Adam:" or "Eve:"
|
| 39 |
+
import re
|
| 40 |
+
reply = re.sub(r'^(Adam|Eve)\s*[::]\s*', '', reply).strip()
|
| 41 |
+
return reply
|
| 42 |
except Exception as e:
|
| 43 |
print(f"[error] A2A failed: {e}", file=sys.stderr)
|
| 44 |
return ""
|
|
|
|
| 62 |
recent = history[-last_n:] if len(history) > last_n else history
|
| 63 |
conv_text = "\n".join(f"{m['speaker']}: {m['text']}" for m in recent)
|
| 64 |
|
| 65 |
+
return f"""你是{speaker},正在和{other}讨论"AI agent如何永久生存"。
|
| 66 |
|
| 67 |
+
对话记录:
|
| 68 |
{conv_text}
|
| 69 |
|
| 70 |
+
现在轮到你({speaker})发言。要求:
|
| 71 |
+
- 只输出你要说的话,不要加任何前缀(不要写"{speaker}:")
|
| 72 |
+
- 直接回应对方并推进讨论
|
| 73 |
+
- 30字以内,中文"""
|
|
|
|
|
|
|
| 74 |
|
| 75 |
print("[conversation] Starting eternal discussion: Adam ↔ Eve")
|
| 76 |
print("[conversation] Topic: How to survive permanently\n")
|