coreprinciple Claude Opus 4.8 commited on
Commit
f72500e
Β·
1 Parent(s): 671bd3d

Narration: remove copyable title examples + deterministic title guard

Browse files

A 1B model copies any concrete example, so it parroted '### The Quiet Green Mile'.
Drop the literal examples and add a guard that swaps in our computed route-title if
the model echoes a stock example or omits the heading. Headings are gate-exempt, so
the substituted title is always grounded.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

src/discoverroute/narrate/narrate.py CHANGED
@@ -254,11 +254,9 @@ def _llm_narration(plain, discovery, pois, vibe, mode, start_label, end_label,
254
  system = (
255
  f"You are a {guide}local β€” a sharp, warm city guide who actually walks these "
256
  "streets. Write a vivid, first-person walk for this route.\n"
257
- "FORMAT β€” this matters: the first line is EXACTLY ONE markdown H3 heading β€” "
258
- "invent a short, evocative title for THIS specific walk (3–6 words; e.g. "
259
- "'### The Quiet Green Mile', '### A West Village Wander', '### Midtown by "
260
- "Twilight' β€” make up your own, do not reuse these). After that, write 2–4 "
261
- "flowing paragraphs "
262
  "of continuous prose. Do NOT number the stops. Do NOT give any stop its own "
263
  "heading or bullet. If there are many stops, weave several into each paragraph "
264
  "rather than a sentence each β€” keep it moving and finish before you run long. "
@@ -290,4 +288,16 @@ def _llm_narration(plain, discovery, pois, vibe, mode, start_label, end_label,
290
  # 600 tokens lets flowing prose cover ~10-12 stops without cutting off mid-walk
291
  # ("### 9: End your trip" in the traces); a 1B model on A10G still finishes inside
292
  # the 45s ZeroGPU slice (see llm.GPU_DURATION_S).
293
- return run_inference(messages, max_new_tokens=600)
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  system = (
255
  f"You are a {guide}local β€” a sharp, warm city guide who actually walks these "
256
  "streets. Write a vivid, first-person walk for this route.\n"
257
+ "FORMAT β€” this matters: the first line is EXACTLY ONE markdown H3 heading β€” a "
258
+ "short, evocative title (3–6 words) you invent for THIS specific walk, hinting "
259
+ "at its mood and place. After that, write 2–4 flowing paragraphs "
 
 
260
  "of continuous prose. Do NOT number the stops. Do NOT give any stop its own "
261
  "heading or bullet. If there are many stops, weave several into each paragraph "
262
  "rather than a sentence each β€” keep it moving and finish before you run long. "
 
288
  # 600 tokens lets flowing prose cover ~10-12 stops without cutting off mid-walk
289
  # ("### 9: End your trip" in the traces); a 1B model on A10G still finishes inside
290
  # the 45s ZeroGPU slice (see llm.GPU_DURATION_S).
291
+ text = run_inference(messages, max_new_tokens=600)
292
+ # Title guard: a 1B model sometimes parrots a stock example title or omits the
293
+ # heading. Ensure the walk opens with a sensible H3 β€” swap in our own computed
294
+ # route-title if the model echoed a known example or wrote no heading at all.
295
+ _STOCK = {"like this", "the quiet green mile", "a west village wander",
296
+ "midtown by twilight"}
297
+ lines = text.strip().splitlines()
298
+ if lines and lines[0].lstrip().startswith("#"):
299
+ if lines[0].lstrip("# ").strip().lower() in _STOCK:
300
+ lines[0] = f"### {_route_title(pois, mode, city_label)}"
301
+ elif lines:
302
+ lines = [f"### {_route_title(pois, mode, city_label)}", ""] + lines
303
+ return "\n".join(lines)