Closed hakimio closed 1 year ago
Using the following code to stream chat responses:
$stream = OpenAI::chat()->createStreamed([ 'model' => 'gpt-3.5-turbo', 'messages' => [ ['role' => 'user', 'content' => 'Say "Hello World"'] ], 'max_tokens' => 500, 'temperature' => 0.5, 'top_p' => 0.5, 'frequency_penalty' => 0, 'presence_penalty' => 0, 'user' => '<some user id>' ]); /* @var CreateStreamedResponse $response */ foreach ($stream as $response) { if (connection_aborted()) { return; } /* @var CreateStreamedResponseChoice $choice */ $choice = $response->choices[0]; $answer = $choice->delta->content; $this->sendUpdate($answer); $finishReason = $choice->finishReason; if (isset($finishReason)) { $this->sendUpdate("<$finishReason>"); return; } }
In response I get the following from the API (ids are sanitized but they are different):
{ "id": "<sanitized>", "object": "chat.completion.chunk", "created": 1691674231, "model": "gpt-3.5-turbo-0613", "choices": [ { "index": 0, "delta": { "content": "Hello" }, "finish_reason": null } ] } { "id": "<sanitized>", "object": "chat.completion.chunk", "created": 1691674235, "model": "gpt-3.5-turbo-0613", "choices": [ { "index": 0, "delta": { "content": "Hello" }, "finish_reason": null } ] } { "id": "<sanitized>", "object": "chat.completion.chunk", "created": 1691674238, "model": "gpt-3.5-turbo-0613", "choices": [ { "index": 0, "delta": { "content": "Hello" }, "finish_reason": null } ] } // Ad Infinitum...
Any idea what's happening?
Not a client library issue.
Using the following code to stream chat responses:
In response I get the following from the API (ids are sanitized but they are different):
Any idea what's happening?