Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Completions

Greg Priday edited this page Jul 7, 2021 · 1 revision

Completions API

Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.

https://beta.openai.com/docs/api-reference/completions

Completions is where the real magic of GPT-3 happens.

use SiteOrigin\OpenAI\Client;
use SiteOrigin\OpenAI\Engines;

$client = new Client($_ENV['OPENAI_API_KEY']);
$result = $client->completions(Engines::CURIE)->complete("We could all use some more", [
    'max_tokens' => 32,
    'temperature' => 0.8,
    'n' => 4,
    'stop' => ["\n", '.'],
]);
echo json_encode($result);

$result is a PHP object, so you'd access choices using $result->choices.

(object) array(
   'id' => 'cmpl-3IzxC9MsYyX2h66UUIJ3xFz3uMn63',
   'object' => 'text_completion',
   'created' => 1625657066,
   'model' => 'curie:2020-05-03',
   'choices' => 
  array (
    0 => 
    (object) array(
       'text' => ' light saving days',
       'index' => 0,
       'logprobs' => NULL,
       'finish_reason' => 'stop',
    ),
    1 => 
    (object) array(
       'text' => ' spinach in our lives',
       'index' => 1,
       'logprobs' => NULL,
       'finish_reason' => 'stop',
    ),
    3 => (object) array( /* ... */ ),
    4 => (object) array( /* ... */ ),
  ),
);
Clone this wiki locally