PHP code example of fixik / openai-client

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

    

fixik / openai-client example snippets


use Fixik\OpenAI\OpenAIClient;

$apiKey = 'YOUR_OPENAI_API_KEY_HERE';

$openaiClient = new OpenAIClient($apiKey);

$message = "Write a haiku about modern PHP development.";

$openaiClient->chat()->send('gpt-3.5-turbo', $message);
$openaiClient->embeddings()->create('gpt-3.5-turbo', $message);
$openaiClient->fineTune()->create([
    'model' => 'gpt-3.5-turbo',
    'training_file' => 'file-id',
]);
$openaiClient->fineTune()->retrieve($jobId);
$openaiClient->images()->generate($message);

$message = "Write a haiku about modern PHP development.";

OpenAI::chat()->send('gpt-3.5-turbo', $message);
OpenAI::embeddings()->create('gpt-3.5-turbo', $message);
OpenAI::fineTune()->create([
    'model' => 'gpt-3.5-turbo',
    'training_file' => 'file-id',
]);
OpenAI::fineTune()->retrieve($jobId);
OpenAI::images()->generate($message);
bash
php artisan vendor:publish --provider="Fixik\OpenAI\Laravel\OpenAIServiceProvider"