Skip to content

fix(openai-live): chunk Chinese and Japanese context appends at sentence endings - #6413

Merged
aconchillo merged 4 commits into
pipecat-ai:mainfrom
ninglinLiu:fix/openai-live-cjk-sentence-chunks
Nov 3, 2026
Merged

aconchillo merged 4 commits into
pipecat-ai:mainfrom
ninglinLiu:fix/openai-live-cjk-sentence-chunks

Conversation

@ninglinLiu

@ninglinLiu ninglinLiu commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6412

Summary

_chunk_text() (used by OpenAILiveLLMService._send_context_append() to split long delegation output into session.commentary.append / session.thinking.append events) only treated ASCII .!? followed by whitespace as a sentence boundary. Chinese and Japanese end sentences with 。!? and no space, so a CJK result became one long "sentence" that _split_at_token_limit() cut wherever the budget ran out, i.e. mid-sentence:

  • before: _chunk_text(cjk_text, 100) chunks ended with 测试句, 一个测, 这是一, か?这, …
  • before: _chunk_text("First sentence. 第二句话。Third sentence.", 6) → ['First sentence.', '第二句话。Thir', 'd sentence.']
  • after: every chunk ends at 。/!/?, and the mixed example gives ['First sentence.', '第二句话。', 'Third sentence.']

Changes:

  • _SENTENCE_BOUNDARY also splits after full-width 。!?, with no whitespace required.
  • When rejoining pieces into a chunk, no space is inserted after a CJK sentence ending (Latin sentences are rejoined with a single space exactly as before), so "".join(chunks) reproduces CJK text unchanged.

Latin-script behaviour is unchanged; the existing chunking tests pass as-is.

Tests

  • Added test_chunk_text_breaks_cjk_at_full_width_sentence_endings and test_chunk_text_keeps_spaces_between_latin_sentences_next_to_cjk to tests/test_openai_live_service.py; both fail on main and pass with the fix.
  • Changelog: changelog/6413.fixed.md.
  • uv run pytest tests/test_openai_live_service.py → 50 passed (also verified with the change applied on current main); ruff check / ruff format --check clean.

@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/pipecat/services/openai/live/llm.py 88.92% <100.00%> (+0.17%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aconchillo

Copy link
Copy Markdown
Contributor

LGTM! Thank you!

@aconchillo
aconchillo merged commit 9ee840d into pipecat-ai:main Nov 3, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAILiveLLMService: long Chinese/Japanese context appends are chunked mid-sentence (_chunk_text ignores 。!?)

2 participants