Skip to content

Streamed completion and function calls #177

Answered by gehrisandro
sebrosse asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@sebrosse
Comment options

@gehrisandro
Comment options

@vesper8
Comment options

Answer selected by sebrosse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants