File tree 1 file changed +11
-0
lines changed
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ public static function formatResponse($buffer)
96
96
$ promptFilterResults = null ;
97
97
$ contentFilterResults = null ;
98
98
$ contentFilterOffsets = null ;
99
+ $ toolCalls = [];
99
100
foreach ($ chunks as $ chunk ) {
100
101
if ($ chunk === "" ) {
101
102
continue ;
@@ -117,6 +118,13 @@ public static function formatResponse($buffer)
117
118
} else {
118
119
foreach ($ data ['choices ' ] ?? [] as $ item ) {
119
120
$ content .= $ item ['delta ' ]['content ' ] ?? "" ;
121
+ foreach ($ item ['delta ' ]['tool_calls ' ] ?? [] as $ function ) {
122
+ if (isset ($ function ['function ' ]['name ' ])) {
123
+ $ toolCalls [$ function ['index ' ]] = $ function ;
124
+ } elseif (isset ($ function ['function ' ]['arguments ' ])) {
125
+ $ toolCalls [$ function ['index ' ]]['function ' ]['arguments ' ] .= $ function ['function ' ]['arguments ' ];
126
+ }
127
+ }
120
128
if (isset ($ item ['finish_reason ' ])) {
121
129
$ finishReason = $ item ['finish_reason ' ];
122
130
}
@@ -154,6 +162,9 @@ public static function formatResponse($buffer)
154
162
if ($ contentFilterOffsets ) {
155
163
$ result ['choices ' ][0 ]['content_filter_offsets ' ] = $ contentFilterOffsets ;
156
164
}
165
+ if ($ toolCalls ) {
166
+ $ result ['choices ' ][0 ]['message ' ]['tool_calls ' ] = array_values ($ toolCalls );
167
+ }
157
168
return $ result ;
158
169
}
159
170
You can’t perform that action at this time.
0 commit comments