fix(title): strip markdown labels and skip empty placeholders in auto-title (#611)
Squash-merges PR #611 (@franksong2702). Fixes two edge cases in auto-generated session titles. 1. Strip Markdown labels (`**Session Title:**`, `Title:`) from sanitizer output — these were being persisted verbatim when the LLM emitted them. 2. Skip empty assistant tool-call placeholder messages when extracting the first exchange for title generation — previously the empty row could be latched onto instead of the first real answer. Also tightens the title prompt to explicitly forbid Markdown, bullets, and label prefixes. 1371 tests passing, QA harness green. Co-authored-by: Frank Song <franksong2702@gmail.com>
This commit is contained in:
35
tests/test_title_sanitization.py
Normal file
35
tests/test_title_sanitization.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import unittest
|
||||
|
||||
from api.streaming import _first_exchange_snippets, _sanitize_generated_title
|
||||
|
||||
|
||||
class TestGeneratedTitleSanitization(unittest.TestCase):
|
||||
def test_strips_session_title_markdown_prefix(self):
|
||||
self.assertEqual(
|
||||
_sanitize_generated_title("**Session Title:** Clarifying Topic for Discussion"),
|
||||
"Clarifying Topic for Discussion",
|
||||
)
|
||||
|
||||
def test_strips_plain_title_prefix(self):
|
||||
self.assertEqual(
|
||||
_sanitize_generated_title("Title: Clarifying Topic for Discussion"),
|
||||
"Clarifying Topic for Discussion",
|
||||
)
|
||||
|
||||
def test_strips_wrapping_markdown_emphasis(self):
|
||||
self.assertEqual(
|
||||
_sanitize_generated_title("**Clarifying Topic for Discussion**"),
|
||||
"Clarifying Topic for Discussion",
|
||||
)
|
||||
|
||||
def test_first_exchange_skips_empty_assistant_tool_call_placeholder(self):
|
||||
messages = [
|
||||
{"role": "user", "content": "What time is it in San Francisco?"},
|
||||
{"role": "assistant", "content": "", "tool_calls": [{"id": "call_1"}]},
|
||||
{"role": "tool", "content": "tool output", "tool_call_id": "call_1"},
|
||||
{"role": "assistant", "content": "It is 6:16 PM in San Francisco."},
|
||||
]
|
||||
self.assertEqual(
|
||||
_first_exchange_snippets(messages),
|
||||
("What time is it in San Francisco?", "It is 6:16 PM in San Francisco."),
|
||||
)
|
||||
Reference in New Issue
Block a user