openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.92k stars 508 forks source link

use stream failed #127

Closed jinhuashijie closed 1 year ago

jinhuashijie commented 1 year ago

when i use stream , code like down $stream = $client->completions()->createStreamed([ 'model' => 'text-davinci-003', 'prompt' => $prompt, 'max_tokens' => 1000, ]); foreach($stream as $response){ // echo $response->choices[0]->text."
"; echo $response->choices[0]->text; // var_dump($response); // echo $response.id; } i have to wait atleats 12 s why this problem? where i did error?

pb30 commented 1 year ago

Streaming should use:

foreach($stream as $response){
   echo $response->choices[0]->delta->content;
}
kevinquillen commented 1 year ago

You need to ensure your php and webserver configuration allow for this.

See this thread for more information: https://github.com/openai-php/client/issues/100