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 @@ -809,6 +809,15 @@ async def chat_completion_stream_generator(
809
809
combined_reasoning = ""
810
810
tool_messages = []
811
811
812
+ # Calculate base_index once before the loop
813
+ base_index = 0
814
+ for msg in harmony_parser .messages :
815
+ if (msg .channel == "commentary"
816
+ and msg .recipient
817
+ and msg .recipient .startswith (
818
+ "functions." )):
819
+ base_index += 1
820
+
812
821
for group in groups :
813
822
group_channel = group ['channel' ]
814
823
group_recipient = group ['recipient' ]
@@ -822,14 +831,6 @@ async def chat_completion_stream_generator(
822
831
elif (group_channel == "commentary" and group_recipient
823
832
and group_recipient .startswith ("functions." )):
824
833
825
- base_index = 0
826
- for msg in harmony_parser .messages :
827
- if (msg .channel == "commentary"
828
- and msg .recipient
829
- and msg .recipient .startswith (
830
- "functions." )):
831
- base_index += 1
832
-
833
834
if prev_recipient != group_recipient :
834
835
tool_name = group_recipient .split (
835
836
"functions." , 1 )[1 ]
@@ -843,10 +844,12 @@ async def chat_completion_stream_generator(
843
844
index = base_index ,
844
845
))
845
846
prev_recipient = group_recipient
847
+ # Increment index for next tool call
848
+ base_index += 1
846
849
847
850
if group_text :
848
851
tool_messages .append (DeltaToolCall (
849
- index = base_index ,
852
+ index = base_index - 1 , # Use the index of the current tool call
850
853
function = DeltaFunctionCall (
851
854
arguments = group_text ),
852
855
))
You can’t perform that action at this time.
0 commit comments