Commit bfaf222
committed
fix(client): stream terminator echoes handler-supplied finish_reason
_handle_chat's two streaming paths (async-gen + sync-gen) hardcoded
finish_reason="stop" on the synthetic done=True chat-chunk terminator.
A handler that yielded a chunk with finish_reason="length" (max-tokens
truncation) had it silently rewritten to "stop" on the wire, so the
client couldn't distinguish a clean stop from a truncation.
The non-streaming accumulate paths already carry the handler's
finish_reason through _finalize_accumulated; the JS port was fixed for
the streaming paths in 7427ed4. Track the last finish_reason seen via
_chunk_fields and echo it on the terminator, falling back to "stop"
when the handler never sets one.1 parent c45fdca commit bfaf222
1 file changed
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
359 | 359 | | |
360 | 360 | | |
361 | 361 | | |
| 362 | + | |
362 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
363 | 367 | | |
364 | | - | |
| 368 | + | |
365 | 369 | | |
366 | 370 | | |
367 | 371 | | |
| |||
380 | 384 | | |
381 | 385 | | |
382 | 386 | | |
| 387 | + | |
383 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
384 | 392 | | |
385 | | - | |
| 393 | + | |
386 | 394 | | |
387 | 395 | | |
388 | 396 | | |
| |||
0 commit comments