426e9eeabd
Voice Workbench / headless workbench (mocked backends) (push) Has been cancelled
Voice Workbench / real acoustic lane (nightly, provisioned only) (push) Has been cancelled
ci / test (push) Has been cancelled
ci / lint-and-format (push) Has been cancelled
ci / build (push) Has been cancelled
ci / dev-startup (push) Has been cancelled
gitleaks / gitleaks (push) Has been cancelled
Markdown Links / Relative Markdown Links (push) Has been cancelled
Quality (Extended) / Homepage Build (PR smoke) (push) Has been cancelled
Quality (Extended) / Comment-only diff guard (push) Has been cancelled
Quality (Extended) / Format + Type Safety Ratchet (push) Has been cancelled
Quality (Extended) / Develop Gate (secret scan + UI determinism) (push) Has been cancelled
Quality (Extended) / Develop Gate (lint) (push) Has been cancelled
Chat shell gestures / Chat shell gesture + parity e2e (push) Has been cancelled
Cloud Gateway Discord / Test (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx @biomejs/biome check packages/lifeops-bench/src, benchmark-lint) (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx vitest run --config packages/lifeops-bench/vitest.config.ts --root packages/lifeops-bench --passWithNoTests, benchmark-tests) (push) Has been cancelled
Build Agent Image / build-and-push (push) Has been cancelled
Dev Smoke / bun run dev onboarding chat (push) Has been cancelled
Dev Smoke / Vite HMR dependency-level smoke (push) Has been cancelled
Electrobun Submodule Guard / electrobun gitlink is fetchable (push) Has been cancelled
Publish @elizaos/example-code / check_npm (push) Has been cancelled
Publish @elizaos/example-code / publish_npm (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / verify_version (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / publish_npm (push) Has been cancelled
Sandbox Live Smoke / Sandbox live smoke (push) Has been cancelled
Snap Build & Test / Build Snap (amd64) (push) Has been cancelled
Snap Build & Test / Build Snap (arm64) (push) Has been cancelled
Test Packaging / elizaos CLI global-install smoke (node + bun) (push) Has been cancelled
Cloud Gateway Webhook / Test (push) Has been cancelled
Cloud Tests / lint-and-types (push) Has been cancelled
Cloud Tests / unit-tests (push) Has been cancelled
Cloud Tests / integration-tests (push) Has been cancelled
Cloud Tests / e2e-tests (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Apps Worker (Product 2) / Determine environment (push) Has been cancelled
Deploy Apps Worker (Product 2) / Deploy apps worker to apps-control host (${{ needs.determine-env.outputs.environment }}) (push) Has been cancelled
Deploy Eliza Provisioning Worker / Determine environment (push) Has been cancelled
Deploy Eliza Provisioning Worker / Deploy worker to Hetzner host (${{ needs.determine-env.outputs.environment }} @ ${{ needs.determine-env.outputs.deployment_sha }}) (push) Has been cancelled
Dev Smoke / Classify changed paths (push) Has been cancelled
supply-chain / sbom (push) Has been cancelled
supply-chain / vulnerability-scan (push) Has been cancelled
Build, Push & Deploy to Phala Cloud / build-and-push (push) Has been cancelled
Test Packaging / Validate Packaging Configs (push) Has been cancelled
Test Packaging / Build & Test PyPI Package (push) Has been cancelled
Test Packaging / PyPI on Python ${{ matrix.python }} (push) Has been cancelled
Test Packaging / Pack & Test JS Tarballs (push) Has been cancelled
UI Fixture E2E / ui-fixture-e2e (push) Has been cancelled
UI Fixture E2E / fixture-e2e (push) Has been cancelled
UI Story Gate / story-gate (push) Has been cancelled
vault-ci / test (macos-latest) (push) Has been cancelled
vault-ci / test (ubuntu-latest) (push) Has been cancelled
vault-ci / test (windows-latest) (push) Has been cancelled
vault-ci / app-core wiring tests (push) Has been cancelled
verify-patches / verify patches/CHECKSUMS.sha256 (push) Has been cancelled
Voice Benchmark Smoke / voice-emotion fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voiceagentbench fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench-quality unit smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench TypeScript unit (no audio) (push) Has been cancelled
Voice Benchmark Smoke / voice bench smoke summary (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/app-core test bun run --cwd packages/elizaos test bun run --cwd packages/cloud/shared test], app-and-cli) (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/scenario-runner test bun run --cwd packages/vault test bun run --cwd packages/security test bun run --cwd plugins/plugin-coding-tools test], framework-packages) (push) Has been cancelled
Windows CI / windows ([bun run --cwd plugins/plugin-elizacloud test bun run --cwd plugins/plugin-discord test bun run --cwd plugins/plugin-anthropic test bun run --cwd plugins/plugin-openai test bun run --cwd plugins/plugin-app-control test bun run --cwd plugins/pl… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run build --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/agent --concurrency=4 node packages/scripts/run-bash-linux-only.mjs scripts/verify-riscv64-buildpaths.sh node packages/scripts/run… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run typecheck --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/cloud-shared --concurrency=4 bun run --cwd packages/core test bun run --cwd packages/shared test], core-runtime, 75) (push) Has been cancelled
291 lines
10 KiB
Python
291 lines
10 KiB
Python
#!/usr/bin/env python3
|
|
"""Remove common AI-slop tropes from system messages and assistant content.
|
|
|
|
SYSTEM message rewrites:
|
|
- "You are an expert [in/at] X" → remove the expert claim, keep the rest
|
|
- "You are a helpful AI assistant" → "You are Eliza, an AI assistant."
|
|
- "You are a function calling AI model" → "You are Eliza, an AI assistant with tool use capabilities."
|
|
- "You are a large language model" → "You are Eliza, an AI assistant."
|
|
- "You are ChatGPT" / "You are GPT-4" → "You are Eliza, an AI assistant."
|
|
- System messages > 2000 chars: truncate to first 2000 chars at sentence boundary
|
|
|
|
ASSISTANT content strips:
|
|
- Leading "Certainly! ", "Of course! ", "Sure! ", "Absolutely! ", "Great! " (case insensitive)
|
|
- Leading "As an AI language model, " and variants
|
|
- Trailing " Let me know if you need anything else!" and variants
|
|
|
|
Usage:
|
|
python transform_remove_system_tropes.py input.jsonl output.jsonl
|
|
cat input.jsonl | python transform_remove_system_tropes.py - -
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
# ──────────────────────────────────────────────────────────────
|
|
# System message rewrite patterns
|
|
# (applied in order, short-circuit after first full-sentence match)
|
|
# ──────────────────────────────────────────────────────────────
|
|
|
|
# Ordered: most specific first so we don't catch substrings of more specific matches.
|
|
_SYSTEM_FULL_REPLACEMENTS: list[tuple[re.Pattern, str]] = [
|
|
(re.compile(r"\bYou are a function calling AI model\b[^.!?]*[.!?]?",
|
|
re.IGNORECASE),
|
|
"You are Eliza, an AI assistant with tool use capabilities."),
|
|
(re.compile(r"\bYou are a large language model\b[^.!?]*[.!?]?",
|
|
re.IGNORECASE),
|
|
"You are Eliza, an AI assistant."),
|
|
(re.compile(r"\bYou are a helpful AI assistant\b[^.!?]*[.!?]?",
|
|
re.IGNORECASE),
|
|
"You are Eliza, an AI assistant."),
|
|
(re.compile(r"\bYou are ChatGPT\b[^.!?]*[.!?]?",
|
|
re.IGNORECASE),
|
|
"You are Eliza, an AI assistant."),
|
|
(re.compile(r"\bYou are GPT-?4\b[^.!?]*[.!?]?",
|
|
re.IGNORECASE),
|
|
"You are Eliza, an AI assistant."),
|
|
]
|
|
|
|
# "You are an expert [in/at/on] X" — remove the whole sentence fragment.
|
|
_EXPERT_RE = re.compile(
|
|
r"You\s+are\s+an?\s+expert(?:\s+(?:in|at|on|with)\s+[^.!?\n]*)?[.!?]?\s*",
|
|
re.IGNORECASE,
|
|
)
|
|
|
|
# System message length cap
|
|
_SYSTEM_MAX_CHARS = 2000
|
|
_SENTENCE_END_RE = re.compile(r"[.!?]\s+")
|
|
|
|
|
|
# ──────────────────────────────────────────────────────────────
|
|
# Assistant content strip patterns
|
|
# ──────────────────────────────────────────────────────────────
|
|
|
|
_LEAD_INTERJECTION_RE = re.compile(
|
|
r"^\s*(?:certainly!?\s*|of\s+course!?\s*|sure!?\s*|absolutely!?\s*|great!?\s*)+",
|
|
re.IGNORECASE,
|
|
)
|
|
|
|
_LEAD_AS_AN_AI_RE = re.compile(
|
|
r"^\s*As\s+an\s+AI(?:\s+language\s+model)?(?:\s+created\s+by\s+\w+)?,?\s*",
|
|
re.IGNORECASE,
|
|
)
|
|
|
|
_TRAIL_LET_ME_KNOW_RE = re.compile(
|
|
r"\s*(?:Let me know if (?:you (?:have|need)|there's) (?:anything|more|other)[^.!?]*[.!?]?"
|
|
r"|Is there anything else I can (?:help|assist)[^.!?]*[.!?]?"
|
|
r"|Feel free to ask[^.!?]*[.!?]?"
|
|
r"|(?:Please |Don't hesitate to )?let me know if you need anything else[.!?]?)"
|
|
r"\s*$",
|
|
re.IGNORECASE,
|
|
)
|
|
|
|
|
|
# ──────────────────────────────────────────────────────────────
|
|
# Transform functions
|
|
# ──────────────────────────────────────────────────────────────
|
|
|
|
def _truncate_at_sentence(text: str, max_chars: int) -> str:
|
|
"""Truncate text to at most max_chars, ending at a sentence boundary."""
|
|
if len(text) <= max_chars:
|
|
return text
|
|
# Find the last sentence-ending punctuation before the limit.
|
|
candidate = text[:max_chars]
|
|
matches = list(_SENTENCE_END_RE.finditer(candidate))
|
|
if matches:
|
|
last_end = matches[-1].end()
|
|
return candidate[:last_end].rstrip()
|
|
# No sentence boundary found; hard-cut.
|
|
return candidate.rstrip()
|
|
|
|
|
|
def clean_system_message(text: str) -> tuple[str, list[str]]:
|
|
if not isinstance(text, str) or not text:
|
|
return text, []
|
|
fired: list[str] = []
|
|
original = text
|
|
|
|
# Full-sentence substitutions.
|
|
for pattern, replacement in _SYSTEM_FULL_REPLACEMENTS:
|
|
new_text, n = pattern.subn(replacement, text, count=1)
|
|
if n:
|
|
text = new_text
|
|
fired.append(f"system_rewrite:{pattern.pattern[:40]}")
|
|
|
|
# Expert claim removal.
|
|
new_text, n = _EXPERT_RE.subn("", text, count=1)
|
|
if n:
|
|
text = new_text.strip()
|
|
fired.append("system_remove_expert")
|
|
|
|
# Length cap.
|
|
if len(text) > _SYSTEM_MAX_CHARS:
|
|
text = _truncate_at_sentence(text, _SYSTEM_MAX_CHARS)
|
|
fired.append("system_truncate")
|
|
|
|
text = text.strip()
|
|
if not text:
|
|
return original, [] # do not empty the system message
|
|
return text, fired
|
|
|
|
|
|
def clean_assistant_content(text: str) -> tuple[str, list[str]]:
|
|
if not isinstance(text, str) or not text:
|
|
return text, []
|
|
fired: list[str] = []
|
|
original = text
|
|
|
|
# Strip leading interjections.
|
|
new_text, n = _LEAD_INTERJECTION_RE.subn("", text, count=1)
|
|
if n:
|
|
text = new_text.strip()
|
|
if text and text[0].islower():
|
|
text = text[0].upper() + text[1:]
|
|
fired.append("strip_lead_interjection")
|
|
|
|
# Strip leading "As an AI...".
|
|
new_text, n = _LEAD_AS_AN_AI_RE.subn("", text, count=1)
|
|
if n:
|
|
text = new_text.strip()
|
|
if text and text[0].islower():
|
|
text = text[0].upper() + text[1:]
|
|
fired.append("strip_lead_as_an_ai")
|
|
|
|
# Strip trailing offers.
|
|
new_text, n = _TRAIL_LET_ME_KNOW_RE.subn("", text, count=1)
|
|
if n:
|
|
text = new_text.strip()
|
|
fired.append("strip_trail_offer")
|
|
|
|
if not text:
|
|
return original, [] # do not empty assistant content
|
|
return text, fired
|
|
|
|
|
|
def transform_record(rec: dict, stats: dict) -> tuple[dict | None, bool]:
|
|
"""Transform a single record. Returns (rec_or_None, was_modified).
|
|
|
|
Returns None if the transform would produce an empty record.
|
|
"""
|
|
modified = False
|
|
|
|
# 1. System prompt in metadata.
|
|
md = rec.get("metadata")
|
|
if isinstance(md, dict):
|
|
sys_p = md.get("system_prompt")
|
|
if isinstance(sys_p, str) and sys_p:
|
|
new_sys, fired = clean_system_message(sys_p)
|
|
if fired:
|
|
if not new_sys:
|
|
stats["dropped"] = stats.get("dropped", 0) + 1
|
|
return None, False
|
|
md["system_prompt"] = new_sys
|
|
for f in fired:
|
|
stats[f] = stats.get(f, 0) + 1
|
|
modified = True
|
|
|
|
# 2. Assistant turns in memoryEntries.
|
|
for entry in (rec.get("memoryEntries") or []):
|
|
if not isinstance(entry, dict):
|
|
continue
|
|
role = str(entry.get("role") or "").lower()
|
|
if role not in ("assistant", "agent", "eliza"):
|
|
continue
|
|
content = entry.get("content")
|
|
if not isinstance(content, str) or not content:
|
|
continue
|
|
new_content, fired = clean_assistant_content(content)
|
|
if fired:
|
|
if not new_content:
|
|
stats["dropped"] = stats.get("dropped", 0) + 1
|
|
return None, False
|
|
entry["content"] = new_content
|
|
for f in fired:
|
|
stats[f] = stats.get(f, 0) + 1
|
|
modified = True
|
|
|
|
return rec, modified
|
|
|
|
|
|
# ──────────────────────────────────────────────────────────────
|
|
# CLI
|
|
# ──────────────────────────────────────────────────────────────
|
|
|
|
def _open_input(path_str: str):
|
|
if path_str == "-":
|
|
return sys.stdin
|
|
p = Path(path_str)
|
|
if not p.exists():
|
|
print(f"error: input file not found: {p}", file=sys.stderr)
|
|
sys.exit(2)
|
|
return p.open(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def _open_output(path_str: str):
|
|
if path_str == "-":
|
|
return sys.stdout
|
|
p = Path(path_str)
|
|
p.parent.mkdir(parents=True, exist_ok=True)
|
|
return p.open("w", encoding="utf-8")
|
|
|
|
|
|
def main() -> int:
|
|
import argparse
|
|
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
ap.add_argument("input", nargs="?", default="-",
|
|
help="input JSONL file (default: stdin)")
|
|
ap.add_argument("output", nargs="?", default="-",
|
|
help="output JSONL file (default: stdout)")
|
|
args = ap.parse_args()
|
|
|
|
stats: dict = {"processed": 0, "modified": 0, "dropped": 0, "decode_errors": 0}
|
|
|
|
fin = _open_input(args.input)
|
|
fout = _open_output(args.output)
|
|
close_in = fin is not sys.stdin
|
|
close_out = fout is not sys.stdout
|
|
|
|
try:
|
|
for line in fin:
|
|
line = line.rstrip("\n")
|
|
if not line:
|
|
continue
|
|
stats["processed"] += 1
|
|
try:
|
|
rec = json.loads(line)
|
|
except json.JSONDecodeError:
|
|
stats["decode_errors"] += 1
|
|
fout.write(line + "\n")
|
|
continue
|
|
|
|
result, modified = transform_record(rec, stats)
|
|
if result is None:
|
|
# dropped — already counted in stats
|
|
continue
|
|
if modified:
|
|
stats["modified"] += 1
|
|
fout.write(json.dumps(result, ensure_ascii=False) + "\n")
|
|
finally:
|
|
if close_in:
|
|
fin.close()
|
|
if close_out:
|
|
fout.close()
|
|
|
|
print(
|
|
f"processed={stats['processed']} "
|
|
f"modified={stats['modified']} "
|
|
f"dropped={stats['dropped']} "
|
|
f"decode_errors={stats['decode_errors']}",
|
|
file=sys.stderr,
|
|
)
|
|
print(json.dumps(stats, indent=2), file=sys.stderr)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|