Remove mid-stream flush on newlines: prevents split multi-turn responses
This commit is contained in:
@@ -245,11 +245,8 @@ def handler(event, context):
|
|||||||
token = delta.get('text', '')
|
token = delta.get('text', '')
|
||||||
if token:
|
if token:
|
||||||
text_buffer += token
|
text_buffer += token
|
||||||
flush = (
|
# Only flush if buffer is very large — prevents splitting multi-turn responses
|
||||||
text_buffer.rstrip().endswith(('\n\n', '.\n', '!\n', '?\n'))
|
if len(text_buffer) > 1200:
|
||||||
or len(text_buffer) > 800
|
|
||||||
)
|
|
||||||
if flush and text_buffer.strip():
|
|
||||||
print(f'[agent-runner] send chunk {len(text_buffer)}c to {chat_id}')
|
print(f'[agent-runner] send chunk {len(text_buffer)}c to {chat_id}')
|
||||||
send_telegram_direct(str(chat_id), bot_token, text_buffer.strip())
|
send_telegram_direct(str(chat_id), bot_token, text_buffer.strip())
|
||||||
text_buffer = ''
|
text_buffer = ''
|
||||||
|
|||||||
Reference in New Issue
Block a user