'gpt-4-turbo', //gpt-4-turbo, gpt-4o-mini 'messages' => [ [ 'role' => 'user', 'content' => $userPrompt ] ] ]; $response = Http::withHeaders([ 'Authorization' => 'Bearer ' . config('openai.api_key') ])->post(config('openai.base_url') . '/v1/chat/completions', $data); if ($response->successful()) { $data = $response->json(); return $data; } else { Log::info('CreatesChatGPTResponse: ' . $response); return null; } } catch (\Illuminate\Http\Client\ConnectionException $exception) { $error = 'Failed to connect to ChatGPT API'; throw new ConnectionErrorException($error, $exception->getMessage(), $userPrompt, $exception->getTraceAsString()); } catch (\Exception $exception) { throw new MalformedRequestException('Unable to get correct response from ChatGPT API: ' . $exception->getMessage()); } } }