Commit e0cbd6d
fix: set index of tool calls in stream mode (#1468)
**Description**
There is an `index` field
(https://github.com/openai/openai-python/blob/4e8856576211064b09c0cc4a1ed35b82b169abe2/src/openai/types/chat/chat_completion_chunk.py#L48)
in the tool calls definition in stream mode: and it's not optional.
Third party libs like
opentelemetry(https://github.com/open-telemetry/opentelemetry-python-contrib/blob/447aac2b0fbe88998e970941c1160147f355ec73/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py#L285)
is implemented based on this assumption. The index field should be set
according the number of tool calls in the streaming events which can be
tracked by checking message start/stop event types.
- aws bedrock: track the tool index by contentBlockStart/Stop events
- gcp anthropic: track the tool index by content_block_start/stop events
**Discuss/suggestion**:
- `ChatCompletionMessageToolCallParam` should not be reused in the
response type.
- For both converse api and anthropic api, the stream chunks have strong
dependencies. We should use complete responses to write unit tests.
---------
Signed-off-by: yxia216 <[email protected]>
Signed-off-by: secustor <[email protected]>
Signed-off-by: ydu208 <[email protected]>
Signed-off-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Dan Sun <[email protected]>
Co-authored-by: Sebastian Poxhofer <[email protected]>
Co-authored-by: yuhongd <[email protected]>
Co-authored-by: ydu208 <[email protected]>
Co-authored-by: Dan Sun <[email protected]>
Co-authored-by: Takeshi Yoneda <[email protected]>1 parent c87e367 commit e0cbd6d
File tree
12 files changed
+737
-169
lines changed- internal
- apischema
- awsbedrock
- openai
- extproc/translator
- tests
- extproc
- internal/testupstreamlib/testupstream
12 files changed
+737
-169
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
406 | 440 | | |
407 | 441 | | |
408 | 442 | | |
| 443 | + | |
409 | 444 | | |
410 | 445 | | |
411 | 446 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
546 | 546 | | |
547 | 547 | | |
548 | 548 | | |
549 | | - | |
550 | | - | |
551 | 549 | | |
552 | 550 | | |
553 | 551 | | |
| |||
1350 | 1348 | | |
1351 | 1349 | | |
1352 | 1350 | | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
1353 | 1361 | | |
1354 | 1362 | | |
1355 | 1363 | | |
1356 | | - | |
1357 | | - | |
1358 | | - | |
1359 | | - | |
1360 | | - | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
1361 | 1369 | | |
1362 | 1370 | | |
1363 | 1371 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1288 | 1288 | | |
1289 | 1289 | | |
1290 | 1290 | | |
1291 | | - | |
| 1291 | + | |
1292 | 1292 | | |
1293 | 1293 | | |
1294 | 1294 | | |
1295 | 1295 | | |
1296 | 1296 | | |
1297 | 1297 | | |
1298 | 1298 | | |
| 1299 | + | |
1299 | 1300 | | |
1300 | 1301 | | |
1301 | 1302 | | |
1302 | 1303 | | |
1303 | | - | |
| 1304 | + | |
1304 | 1305 | | |
1305 | 1306 | | |
1306 | 1307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
647 | 647 | | |
648 | 648 | | |
649 | 649 | | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
650 | 692 | | |
651 | 693 | | |
652 | 694 | | |
| |||
746 | 788 | | |
747 | 789 | | |
748 | 790 | | |
749 | | - | |
| 791 | + | |
750 | 792 | | |
751 | 793 | | |
752 | 794 | | |
| |||
0 commit comments