fix: remove hardcoded chinese title heuristics (#887)

* fix: remove hardcoded chinese title heuristics

* fix: use english placeholder for non-latin fallback titles
This commit is contained in:
Pavol Biely
2026-04-23 20:45:34 +04:00
committed by GitHub
parent ae7be6deba
commit 96c97c5e0e
3 changed files with 74 additions and 43 deletions

View File

@@ -137,16 +137,21 @@ class TestIssue495TitleStreaming(unittest.TestCase):
)
def test_streaming_rejects_generic_completion_titles(self):
self.assertIn(
"测试完成",
STREAMING_PY,
"streaming.py should reject generic completion phrases as session titles",
)
self.assertIn(
"all set",
STREAMING_PY,
"streaming.py should reject generic English completion phrases as session titles",
)
self.assertIn(
"completed",
STREAMING_PY,
"streaming.py should reject completion-status titles as session titles",
)
self.assertNotIn(
"测试完成",
STREAMING_PY,
"streaming.py title generation should stay English-only",
)
def test_streaming_uses_reasoning_split_for_minimax_titles(self):
self.assertIn(

View File

@@ -1,6 +1,11 @@
import unittest
from pathlib import Path
from api.streaming import _first_exchange_snippets, _sanitize_generated_title
from api.streaming import (
_fallback_title_from_exchange,
_first_exchange_snippets,
_sanitize_generated_title,
)
class TestGeneratedTitleSanitization(unittest.TestCase):
@@ -33,3 +38,31 @@ class TestGeneratedTitleSanitization(unittest.TestCase):
_first_exchange_snippets(messages),
("What time is it in San Francisco?", "It is 6:16 PM in San Francisco."),
)
def test_fallback_title_uses_english_discussion_suffix(self):
self.assertEqual(
_fallback_title_from_exchange('Please review "random cancel"', ""),
"random cancel discussion",
)
def test_fallback_title_summary_label_is_english(self):
self.assertEqual(
_fallback_title_from_exchange("Generate a short title summary test", ""),
"Session title auto-summary test",
)
def test_fallback_title_non_latin_input_uses_english_placeholder(self):
self.assertEqual(
_fallback_title_from_exchange("讨论一下这个问题", ""),
"Conversation topic",
)
def test_fallback_title_non_latin_quoted_topic_uses_english_placeholder(self):
self.assertEqual(
_fallback_title_from_exchange('Please review "讨论主题"', ""),
"Conversation topic",
)
def test_title_generation_source_has_no_cjk_literals(self):
src = Path("api/streaming.py").read_text(encoding="utf-8")
self.assertNotRegex(src, r"[\u4e00-\u9fff]", "title generation code should stay English-only")