Commit 7ac1df0
committed
fix: Ensure stop_reason is captured by yielding on RawMessageDeltaEvent
The previous implementation had a timing issue where stop_reason arrived
after the last chunk was yielded. This fix ensures that when we receive
RawMessageDeltaEvent (which contains the stop_reason), we yield an
additional chunk with the updated metadata.
This addresses the test failure identified by @AstraBert where:
- Content chunks were yielded before stop_reason arrived
- stop_reason was None in the last chunk
- RawMessageDeltaEvent came after ContentBlockStopEvent
Now the flow is:
1. ContentBlockDeltaEvent -> yield chunks with content
2. ContentBlockStopEvent -> yield final content chunk
3. RawMessageDeltaEvent -> yield metadata update with stop_reason
4. Tests now pass with stop_reason correctly captured1 parent 88555d1 commit 7ac1df0
File tree
1 file changed
+30
-0
lines changed- llama-index-integrations/llms/llama-index-llms-anthropic/llama_index/llms/anthropic
1 file changed
+30
-0
lines changedLines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
619 | 619 | | |
620 | 620 | | |
621 | 621 | | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
622 | 637 | | |
623 | 638 | | |
624 | 639 | | |
| |||
851 | 866 | | |
852 | 867 | | |
853 | 868 | | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
854 | 884 | | |
855 | 885 | | |
856 | 886 | | |
| |||
0 commit comments