PHP code example of gzdsx / openai

1. Go to this page and download the library: Download gzdsx/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/ */

    

gzdsx / openai example snippets


OpenAiClient.init('YOUR_OPEN_AI_KEY','YOUR_OPEN_AI_ORG_ID');

$config = new OpenAiRequestConfig();
$config->model = 'text-davinci-003';
$config->prompt = 'Hello Ai';
$config->temperature = 0;
$config->top_p = 1;
$config->n = 1;
$config->max_tokens = 1024;
$config->stream = false;
$config->stop = ["Human:", " AI:"];
$config->echo = true;

$client = new OpenAiClient();
$response = $client->completions($config);
if ($response->success()) {
    //成功调用,返回结果
    return $response->toArray();
}else{
    //返回错误信息
    return $response->error;
}