Enha: drain chunkChan to avoid missing tokens

This commit is contained in:
Grail Finder
2025-12-28 11:37:52 +03:00
parent 9d91685e9a
commit 033d9bf78a

15
bot.go
View File

@@ -677,7 +677,6 @@ out:
tv.ScrollToEnd() tv.ScrollToEnd()
// Send chunk to audio stream handler // Send chunk to audio stream handler
if cfg.TTS_ENABLED { if cfg.TTS_ENABLED {
// audioStream.TextChan <- chunk
extra.TTSTextChan <- chunk extra.TTSTextChan <- chunk
} }
case toolChunk := <-openAIToolChan: case toolChunk := <-openAIToolChan:
@@ -685,11 +684,15 @@ out:
toolResp.WriteString(toolChunk) toolResp.WriteString(toolChunk)
tv.ScrollToEnd() tv.ScrollToEnd()
case <-streamDone: case <-streamDone:
botRespMode = false // rrain any remaining chunks from chunkChan before exiting
if cfg.TTS_ENABLED { for chunk := range chunkChan {
// audioStream.TextChan <- chunk fmt.Fprint(tv, chunk)
extra.TTSFlushChan <- true respText.WriteString(chunk)
logger.Debug("sending flushchan signal") tv.ScrollToEnd()
// Send chunk to audio stream handler
if cfg.TTS_ENABLED {
extra.TTSTextChan <- chunk
}
} }
break out break out
} }