LLPhant
LLPhant copied to clipboard
Tool calls in streamed responses
Hi !
I tried to use the OpenAIChat::createStreamedResponse with a function.
The finishReason is not function_call but tool_calls
It is not the only issue I faced.
Since it is a stream, when hitting the finishReason="tool_class", the array $toolsCalled is empty.
Here is the cinematic of $partialResponse->choices[0]->delta->toolCalls (note that $toolsCalled = []; for each piece of stream)
array:1 [
0 => OpenAI\Responses\Chat\CreateStreamedResponseToolCall^ {#202
+id: "call_lzS2i19jrpRSCKftKDLoRa2G"
+type: "function"
+function: OpenAI\Responses\Chat\CreateStreamedResponseToolCallFunction^ {#178
+name: "sendMail"
+arguments: ""
}
}
]
array:1 [
0 => OpenAI\Responses\Chat\CreateStreamedResponseToolCall^ {#86
+id: null
+type: null
+function: OpenAI\Responses\Chat\CreateStreamedResponseToolCallFunction^ {#400
+name: null
+arguments: "{\n"
}
}
]
...
array:1 [
0 => OpenAI\Responses\Chat\CreateStreamedResponseToolCall^ {#414
+id: null
+type: null
+function: OpenAI\Responses\Chat\CreateStreamedResponseToolCallFunction^ {#413
+name: null
+arguments: "}"
}
}
]
[]
Note the empty array
I honnestly don't know how to "merge" the buidling $toolsCalled for each piece of stream.
Hey @arnaudgoulpeau, thanks for having spotted this. I'll have a look at it when I have a bit of time.
Can you write me the code you used to get this so I can use it as a test?