PHP code example of omeratagunn / openai

1. Go to this page and download the library: Download omeratagunn/openai library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

omeratagunn / openai example snippets

`
$test = new OpenAI('your-key');  

// default davinci, to see other engines please visit openAI documentation//
$test->setEngineId('davinci');

try {
    $a = $test->postCompletions([
        'prompt' => "I wish i had a flying fish",
        'max_tokens' => 5,
        'temperature' => 1,
        'top_p' => 1,
        'n' => 1,
        'stream' => false,
        'logprobs' => null,
        'stop' => "\n"
    ]);

    $response = $a->getBody()->getContents();

} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    $e->getMessage();
}

try {
    $b = $test->search([
        'documents' => [
            'white house',
            'hospital',
            'school'
        ],
        'query' => "the president"
    ]);

    $response = $b->getBody()->getContents();

} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    $e->getMessage();
}