Search code examples
phplaravelopenai-apichatgpt-api

Laravel OpenAI client doesn't work with List result


When i try request throw OpenAI laravel library to model gpt-3.5-turbo and result must be list, library throw Exception

WARNING  Undefined array key "choices" in 

vendor/openaiphp/client/src/Responses/Completions/CreateResponse.php on line 45.

TypeError  array_map(): Argument #2 ($array) must be of type array, null given.

I tried this request for test

use OpenAI\Laravel\Facades\OpenAI;

OpenAI::completions()->create([
                'model' => 'gpt-3.5-turbo',
                'prompt' => 'Top 3 reachest peaople',
            ]);


Solution

  • The problem was related to the openai model. I changed the model to text-davinci-003 and it worked.