fix: explicitly model streaming tokens vs sentences#374
Conversation
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughRefactors agent streaming: Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@ovos_plugin_manager/templates/agents.py`:
- Around line 254-278: The stream_sentences implementation and docstring are
incorrect: update the docstring in stream_sentences to say "sentence streaming"
(not "token streaming") and change the Returns description to "sentences";
replace the naive split("\n") with a proper sentence splitter by calling
AbstractSolver.sentence_split (from thirdparty/solvers.py which wraps
quebra_frases.sentence_tokenize) on the AgentMessage content returned by
continue_chat (use continue_chat(messages, session_id, lang, units).content and
then yield each sentence from AbstractSolver.sentence_split), ensuring
stream_sentences yields complete sentences suitable for TTS.
In `@ovos_plugin_manager/thirdparty/solvers.py`:
- Around line 108-110: In sentence_split, the exception fallback returns
text.split("\n") without applying the max_sentences limit; update the except
block (where LOG.exception(f"Error in sentence_split: {e}") is logged) to return
the split result truncated with [:max_sentences] (i.e., apply the same slicing
used in the normal path) so the fallback respects the max_sentences parameter.
🧹 Nitpick comments (1)
ovos_plugin_manager/templates/agents.py (1)
228-252: Clarify token semantics in documentation and consider naming.The method uses
.split()which yields whitespace-separated words, not LLM tokens (which are typically subword units). This is fine for a default fallback implementation, but the docstring should clarify that subclasses implementing real streaming would yield actual model tokens.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Summary by CodeRabbit
New Features
Breaking Changes
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.