File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -734,6 +734,15 @@ async def chat_completion_stream_generator(
734
734
combined_reasoning = ""
735
735
tool_messages = []
736
736
737
+ # Calculate base_index once before the loop
738
+ base_index = 0
739
+ for msg in harmony_parser .messages :
740
+ if (msg .channel == "commentary"
741
+ and msg .recipient
742
+ and msg .recipient .startswith (
743
+ "functions." )):
744
+ base_index += 1
745
+
737
746
for group in groups :
738
747
group_channel = group ['channel' ]
739
748
group_recipient = group ['recipient' ]
@@ -747,14 +756,6 @@ async def chat_completion_stream_generator(
747
756
elif (group_channel == "commentary" and group_recipient
748
757
and group_recipient .startswith ("functions." )):
749
758
750
- base_index = 0
751
- for msg in harmony_parser .messages :
752
- if (msg .channel == "commentary"
753
- and msg .recipient
754
- and msg .recipient .startswith (
755
- "functions." )):
756
- base_index += 1
757
-
758
759
if prev_recipient != group_recipient :
759
760
tool_name = group_recipient .split (
760
761
"functions." , 1 )[1 ]
@@ -768,10 +769,12 @@ async def chat_completion_stream_generator(
768
769
index = base_index ,
769
770
))
770
771
prev_recipient = group_recipient
772
+ # Increment index for next tool call
773
+ base_index += 1
771
774
772
775
if group_text :
773
776
tool_messages .append (DeltaToolCall (
774
- index = base_index ,
777
+ index = base_index - 1 , # Use the index of the current tool call
775
778
function = DeltaFunctionCall (
776
779
arguments = group_text ),
777
780
))
You can’t perform that action at this time.
0 commit comments