Streamed completion and function calls #177
-
Hey, I was wondering whether it is possible to combine streamed response and function calls ? I did a few tests but couldn't get the function call to work as the streamed response format is quite different from the "standard" completion response. Any idea how to do this ? is it even possible with the current API/Library ? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @sebrosse Yes that's possible. You can get the function call information from the streamed response. Here's an excerpt of some code I am using: foreach($response as $response) {
$delta = $response->choices[0]->delta->functionCall->arguments ?? '';
} Be aware, the arguments is returned as JSON and in a stream you receive the response part by part. So the JSON is only valid when the complete response is received. But if you want to wait for the response to complete you could do the call without streaming. Therefore I am using a regex to parse parts from the response before the JSON is complete. |
Beta Was this translation helpful? Give feedback.
Hi @sebrosse
Yes that's possible.
You can get the function call information from the streamed response. Here's an excerpt of some code I am using:
Be aware, the arguments is returned as JSON and in a stream you receive the response part by part. So the JSON is only valid when the complete response is received.
But if you want to wait for the response to complete you could do the call without streaming. Therefore I am using a regex to parse parts from the response before the JSON is complete.