Stage 6 of the realism migration. User-class file bodies (note, todo, draft, script) optionally get LLM-authored content; system classes (cron / daemon logs, /tmp caches) stay template-only because formulaic *is* the right look for them. New surface: - realism.llm.circuit.LLMCircuitBreaker — process-local sliding-window breaker. 3 consecutive failures trip open; 60s cooldown to half-open; half-open success closes, failure re-opens. Protects the orchestrator tick from sustained Ollama wedges (per-call timeout already covers one-shot hangs). - realism.prompts._style — em-dash suppression lifted from the email prompt. Persona.uses_llms_heavily opts out per the feedback_em_dash_llm_tell.md memory. Includes strip_em_dashes belt-and-braces sub for output that slipped past the prompt rule. - realism.prompts.filebody — class-conditioned prompts (note / todo / draft / script) with persona context, language pinning, output shape rule. - realism.bodies.make_body_with_llm — async wrapper around make_body that calls the LLM when one is provided AND the breaker allows. Falls back to template on timeout / error / empty / system-class. Wiring: - scheduler.pick_file accepts optional llm + llm_breaker + llm_timeout. When the planner picks a create action and the content_class is a user-class, the body_hint is replaced with the LLM-authored body (or falls back to the deterministic body_hint). - orchestrator.worker constructs get_llm() at startup gated by DECNET_REALISM_LLM env var (any non-empty value enables; empty / "off" / "none" / "0" disables). Passes llm + breaker through every tick. - decnet orchestrate gains --llm/--no-llm flag overriding the env var.
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
"""Shared stylometric guards for LLM-bound prompts.
|
||
|
||
Lifted from the original ``orchestrator.emailgen.prompt`` em-dash
|
||
block so file-class prompts (note / todo / draft / script bodies)
|
||
pick up the same suppression. Per the
|
||
``feedback_em_dash_llm_tell.md`` memory: em-dashes (—) are a strong
|
||
LLM-authorship tell, suppress by default; allow only for personas
|
||
explicitly opted in via ``EmailPersona.uses_llms_heavily``.
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
from decnet.realism.personas import EmailPersona
|
||
|
||
|
||
_SUPPRESS_RULE = (
|
||
"Do NOT use em-dashes (—). Use commas, periods, or "
|
||
"parentheses instead. Em-dashes are a tell."
|
||
)
|
||
_ALLOW_RULE = (
|
||
"Em-dashes are fine — this persona uses them naturally. "
|
||
"Write in your usual style."
|
||
)
|
||
|
||
|
||
def em_dash_rule(persona: EmailPersona) -> str:
|
||
"""Return the em-dash instruction line for *persona*'s prompt."""
|
||
if persona.uses_llms_heavily:
|
||
return _ALLOW_RULE
|
||
return _SUPPRESS_RULE
|
||
|
||
|
||
def strip_em_dashes(text: str, persona: EmailPersona) -> str:
|
||
"""Belt-and-braces: even with the prompt rule, small models leak
|
||
em-dashes occasionally. Substitute with comma+space so the
|
||
output reads naturally; opt-in personas pass through unchanged.
|
||
"""
|
||
if persona.uses_llms_heavily:
|
||
return text
|
||
return text.replace("—", ", ").replace("–", ", ")
|