openai-php / client

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

Request Headers Meta information for 'x-request-id' #298

Closed rodrigoisabelo closed 6 months ago

rodrigoisabelo commented 6 months ago

Overview: We have created an API Service indentical with OpenAI API deployed on a server from a third-party company. The payload and response is at most identical to OpenAI but I think it differs on the headers.

Steps

  1. On creating the OpenAI Client, we replaced the base uri with our custom API endpoint
  2. Tried sending a chat completion streaming request to it
  3. I got an exception around this line #L31C58-L31C58

Exception

image

Initial Investigation:

  1. MetaInformation class first parameter is optional, this means there should be no problem
  2. Upon receiving the response, meta information is instantiated through the array form of OpenAI Response https://github.com/openai-php/client/blob/1287f569199de3bb7f64bb368b334a77077d348c/src/ValueObjects/Transporter/Response.php#L35-L41
  3. Line #L31C58-L31C58 should handle of whether the array headers have key x-request-id or not in addition to null check. https://github.com/openai-php/client/blob/1287f569199de3bb7f64bb368b334a77077d348c/src/Responses/Meta/MetaInformation.php#L31
Herz3h commented 5 months ago

I'm trying to use this with https://github.com/h2oai/h2ogpt and getting the same error. How did you solve this ?

murnieza commented 5 months ago

It's resolved with https://github.com/openai-php/client/releases/tag/v0.8.1