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

Undefined array key "choices" {"exception":"[object] (ErrorException(code: 0): Undefined array key "choices" #147

Closed ondraasek closed 1 year ago

ondraasek commented 1 year ago

Hi I am using the newest version 0.6.1 and still having this:

[2023-06-17 09:09:12] production.ERROR: Undefined array key "choices" {"exception":"[object] (ErrorException(code: 0): Undefined array key "choices" at /home/forge/app.deeply.cz/vendor/openai-php/client/src/Responses/Chat/CreateStreamedResponse.php:44) [stacktrace]

any idea? thanks a lot

MantraMedia commented 1 year ago

I am getting the same but not on every call. I think this is related to the openai api having issues.

The $attributes array is actually then

[CreateStreamedResponse.php] Line 44:
array:1 [
  "error" => array:4 [
    "message" => "The server had an error while processing your request. Sorry about that!"
    "type" => "server_error"
    "param" => null
    "code" => null
  ]
]

instead of eg

[CreateStreamedResponse.php] Line 44:
array:5 [
  "id" => "..."
  "object" => "chat.completion.chunk"
  "created" => 1234567890
  "model" => "gpt-4-0613"
  "choices" => array:1 [
    0 => array:3 [
      "index" => 0
      "delta" => array:2 [
        "role" => "assistant"
        "content" => ""
      ]
      "finish_reason" => null
    ]
  ]
]
ondraasek commented 1 year ago

I know I fixed it by myself and use my software logic, but it seems its broken when openai doesnt work. I dont have it every request as well, just in a problem with OpenAI api

MantraMediaMike commented 1 year ago

I assume you were also calling gpt-4-0613 directly , or? gpt-4 seems to work fine. the new model seems to throw this error on every 2nd or 3rd request so for now we switched back to the base model.

ondraasek commented 1 year ago

exactly gpt-4-0613. ok good to know :)