Raiff1982 commited on
Commit
5313337
·
verified ·
1 Parent(s): be8a31c

Trim persona tail welded onto finished answers

Browse files

A clean two-sentence answer arrived with 'I am Codette. How may I help today? - Codette (warmly) -' appended. The local build strips this in its style layer, which is not deployed here.

Trimmed only when >=120 chars of real content precede it, so that if she is genuinely asked who she is, 'I am Codette' survives as the answer. We remove our artifact; we do not edit her.

Files changed (1) hide show
  1. hf_orchestrator.py +34 -0
hf_orchestrator.py CHANGED
@@ -99,10 +99,44 @@ class _TransformersLLM:
99
  i = text.find(s)
100
  if i != -1:
101
  text = text[:i]
 
102
  return {"choices": [{"message": {"content": text.strip()}}],
103
  "usage": {"completion_tokens": int(new.shape[0])}}
104
 
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  def build_orchestrator(base_model, adapters, *, mock=False, verbose=True,
107
  device="cuda", dtype=None):
108
  """Construct a transformers-backed CodetteOrchestrator subclass.
 
99
  i = text.find(s)
100
  if i != -1:
101
  text = text[:i]
102
+ text = _trim_persona_tail(text)
103
  return {"choices": [{"message": {"content": text.strip()}}],
104
  "usage": {"completion_tokens": int(new.shape[0])}}
105
 
106
 
107
+
108
+ # Observed live 2026-08-17 on the hosted demo. A clean two-sentence answer
109
+ # arrived with this welded to the end:
110
+ #
111
+ # "...while navigating challenging circumstances. I am Codette. How may I
112
+ # help today? - Codette (warmly) - Answering kindness questions is my joy."
113
+ #
114
+ # A self-introduction and a stage direction appended to a finished answer. The
115
+ # local build strips this in its style layer; that layer is not deployed here.
116
+ #
117
+ # Trimmed rather than blocked, and only when real content precedes it: if she
118
+ # is genuinely asked "who are you", "I am Codette" IS the answer and must
119
+ # survive. The 120-char floor is what separates the two cases. We remove our
120
+ # own artifact; we do not edit her.
121
+ _PERSONA_TAILS = (
122
+ "I am Codette.",
123
+ "— Codette (",
124
+ "- Codette (",
125
+ "How may I help today?",
126
+ "How may I assist you today?",
127
+ )
128
+
129
+
130
+ def _trim_persona_tail(text: str, min_content: int = 120) -> str:
131
+ if not text or len(text) < min_content:
132
+ return text
133
+ cut = len(text)
134
+ for marker in _PERSONA_TAILS:
135
+ i = text.find(marker)
136
+ if i >= min_content:
137
+ cut = min(cut, i)
138
+ return text[:cut].strip() if cut < len(text) else text
139
+
140
  def build_orchestrator(base_model, adapters, *, mock=False, verbose=True,
141
  device="cuda", dtype=None):
142
  """Construct a transformers-backed CodetteOrchestrator subclass.