openai-php / client

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

Fix Content retrieval in HttpTransport with custom HttpClient #343

Open martinhoch42 opened 4 months ago

martinhoch42 commented 4 months ago

getContent does not return the content of the body but the remaining content of the stream.

If you were to use OpenAI::factory with withHttpClient and, for example, a logging middleware, getContent would return an empty string since the stream was already read by the log middleware.

See:

https://www.php-fig.org/psr/psr-7/ https://stackoverflow.com/questions/30549226/guzzlehttp-how-get-the-body-of-a-response-from-guzzle-6