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

Add Chat completion #293

Closed arturhayne closed 6 months ago

arturhayne commented 6 months ago

Description

Completion API was deprecated with final last update in July 2023 as stated in open api documentation.

A new API endpoint was created to support GPT-4 model, chat completions.

I believe we have to create a new class, ChatCompletions to support this endpoint following same structured we have in Completions class.

Steps To Reproduce

If we try to use gpt-4 as:

$result = $client->completions()->create([
    'model' => 'gpt-4',
    'prompt' => 'Peas are ',
]);

An error will surface:

Fatal error: Uncaught OpenAI\Exceptions\ErrorException: This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions? in /var/www/html/vendor/openai-php/client/src/Transporters/HttpTransporter.php on line 131

OpenAI\Exceptions\ErrorException: This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions? in /var/www/html/vendor/openai-php/client/src/Transporters/HttpTransporter.php on line 131

OpenAI PHP Client Version

v0.8.0

PHP Version

8.1.2

Notes

No response

pb30 commented 6 months ago

See README. You need to use the Chat resource

arturhayne commented 6 months ago

You are right. thanks!