openai-php / client

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

How to set the frequency_penalty? #360

Closed alanccw closed 1 month ago

alanccw commented 3 months ago

Hi,

I want to set the frequency_penalty when calling gpt-3.5-turbo model via your code. How to do so? Is there a sample showing how to do this?

Thank you

thomaspapanikolaou commented 2 months ago

Hi,

simply add the frequency_penalty parameter in your call as shown below


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

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

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