PHP code example of tuzlu07x / openai

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

    

tuzlu07x / openai example snippets




use Ftuzlu\OpenAI\BaseFunction;
use Ftuzlu\OpenAI\Client;
use Ftuzlu\OpenAI\OpenAI;

class Example extends BaseFunction
{
    public function __construct(
        private $location = 'Londra',
        private $unit = 'farhenheit',
    ) {
    }

    public function properties(): array
    {
        return $this->parameters();
    }
    public static function ic function type(): string
    {
        return 'object';
    }

    public function parameters(): array
    {
        $parameters = [
            static::parameter('location', 'string', 'The city and state, e.g. San Francisco, CA')->nction()
];
$client = new Client($yourApiKey, $yourOrganization);
$openAI = new OpenAI($example, $client);
$chat = $openAI->chat($functions, $messages, 'handle'); //handle is functionName on example
var_dump($chat->say('How is weather in London?'));




    use Ftuzlu\OpenAI\Client;

    $yourAPIKey=XXXXXX;
    $yourOrganization=XXXXX;
    $baseUrl = 'https://api.openai.com/';
    $client = new Client($yourApiKey, $yourOrganization, $baseUrl);


    use Ftuzlu\OpenAI\OpenAI;

   $example = new Example(); //Example is your Class
   $openAI = new OpenAI($example, $client);
   $chat = $openAI->chat($functions, $messages, 'handle'); //handle is also your class's functionName.