fix: refactor DoubaoBot to use AsyncArk with proper async streaming - #613
Open
octo-patch wants to merge 1 commit into
Open
fix: refactor DoubaoBot to use AsyncArk with proper async streaming#613octo-patch wants to merge 1 commit into
octo-patch wants to merge 1 commit into
Conversation
- Replace sync `Ark` client with `AsyncArk` to avoid blocking the event loop during API calls - Use `async for` to iterate the streaming response instead of a sync `for` loop - Add `split_sentences` for cleaner TTS chunking, matching the pattern used by other bots (ppio, chatgptapi) - Add guard for empty `choices` to prevent IndexError on certain chunks - Return `""` (not `None`) from `ask` on error to satisfy the `BaseBot` return type contract - Update default model from the deprecated `skylark-chat` to `doubao-pro-32k` (the current Ark V3 model name) - Fix module docstring (was copy-pasted from glm_bot) Closes yihong0618#594 Co-Authored-By: Octopus <liyuan851277048@icloud.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #594
Problem
The
DoubaoBotimplementation has several issues introduced when it wasmigrated to the Volcengine Ark V3 SDK:
Blocks the event loop: Both
askandask_streamcall thesynchronous
Arkclient insideasync defmethods withoutawait,blocking asyncio while waiting for network I/O.
Streaming loop uses a sync iterator:
ask_streamusedfor chunk in …instead ofasync for chunk in …, which prevents asyncio fromyielding control between chunks.
Missing
split_sentences: Other bots (chatgptapi, ppio, jiekou)pass the raw LLM token stream through
split_sentencesbeforeyielding to the TTS layer, producing natural sentence-boundary
chunks. DoubaoBot was yielding raw tokens, resulting in choppy or
broken TTS output.
No guard for empty
choices: A chunk with an emptychoiceslist would raise
IndexError. chatgptapi_bot guards against thiswith
if not event.choices: continue.Deprecated default model:
skylark-chatis an old Ark V2 modelname. The current Ark V3 equivalent is
doubao-pro-32k(users canstill override via
gpt_options).askreturnedNoneon error instead of"", violating theBaseBotabstract method signature.Solution
Ark→AsyncArkand addawaittochat.completions.createasync forsplit_sentencesintoask_stream, matching ppio/chatgptapi patternif not chunk.choices: continueandif content is None: continueguardsdoubao-pro-32k""instead ofNonefromaskon errorTesting
Changes follow the exact patterns already used by
ppio_bot.pyandchatgptapi_bot.py, which are known to work correctly in production.