openai-php / client

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

gpt-3.5-turbo-instruct is not a chat model (Get Started code snippet in README) #252

Closed vesper8 closed 8 months ago

vesper8 commented 8 months ago

Minor thing but your code snippet at the top of the README

$yourApiKey = getenv('YOUR_API_KEY');
$client = OpenAI::client($yourApiKey);

$result = $client->chat()->create([
    'model' => 'gpt-3.5-turbo-instruct',
    'messages' => [
        ['role' => 'user', 'content' => 'Hello!'],
    ],
]);

echo $result->choices[0]->message->content; // Hello! How can I assist you today?

returns an error because gpt-3.5-turbo-instruct is not a chat model, instead you can substitute it by gpt-3.5-turbo

rodrigonsh commented 8 months ago

I might be wrong on this but you should set your OPENAI_ORGANIZATION ... and trust me on this one: Its not "Personal' you can find it in Settings > Organization

vesper8 commented 8 months ago

I am setting it, although if you only belong to a single org, then it doesn't really matter. But I do belong to two so it's best to set it in such a case. I agree the usage example should show how to set it.

$this->client = OpenAI::client(config('services.openai.key'), config('services.openai.organization'));

I also got this to work by connecting to a locally running server (that is running via LM Studio for me, but it could be just a python server too. Like this:

        $baseUri = 'http://localhost:1234/v1';

        $this->client = OpenAI::factory()
        ->withApiKey(config('services.openai.key'))
        ->withOrganization(config('services.openai.organization'))
        ->withBaseUri($baseUri)
        ->make();

I think adding this in the README.md would also be welcome.

gehrisandro commented 8 months ago

Thanks @vesper8

Has been fixed now.