openai-php / client

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

Missing new line / line break on responses #135

Closed perryputtiapps closed 1 year ago

perryputtiapps commented 1 year ago

I have this snippet;

$promptRequest = [
            'model' => env('OPENAI_MODEL'),
            'messages' => [
                ['role' => 'system', 'content' => 'You are helpful assistant'],
                ['role' => 'user', 'content' => "Create 3 paragraph description about ChatGPT"]
            ]
        ];

$stream = $client->chat()->createStreamed($promptRequest);

  foreach ($stream as $response) {
      $content = data_get($response, 'choices.0.delta.content');       
  }

I'm getting the streamed content correctly but it's missing new line characters. Is there a way to show the line breaks / new line in the response content?

pb30 commented 1 year ago

I see newlines in my streamed responses on v0.5.2. How are you displaying the content? If it's HTML you'll need to convert to <br>.

You can verify they are there with: echo json_encode($response->choices[0]->delta->content)

jtomek commented 1 year ago

Thanks, this is very helpful. :)