PHP code example of ceytek-labs / openai

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

    

ceytek-labs / openai example snippets


use CeytekLabs\OpenAI\OpenAI;
use CeytekLabs\OpenAI\Enums\TTSModel;
use CeytekLabs\OpenAI\Enums\Voice;

try {
    $openai = OpenAI::make('<your-key-here>')
        ->audio()
        ->createSpeech()
        ->setModel(TTSModel::TTS_1)
        ->setInput('The quick brown fox jumped over the lazy dog.')
        ->setVoice(Voice::Shimmer)
        ->ask();

    print_r($openai->getResponse());
} catch (\Exception $exception) {
    echo $exception->getMessage();
}

use CeytekLabs\OpenAI\OpenAI;

try {
    $openai = OpenAI::make('<your-key-here>')
        ->audio()
        ->createTranscription()
        ->setFile(__DIR__.'/speeches/speech1.mp3')
        ->ask();

    print_r($openai->getResponse());
} catch (\Exception $exception) {
    echo $exception->getMessage();
}

use CeytekLabs\OpenAI\OpenAI;
use CeytekLabs\OpenAI\Enums\Model;

try {
    $openai = OpenAI::make('<your-key-here>')
        ->chat()
        ->createCompletion()
        ->setModel(Model::GPT_3_5_TURBO_0125)
        ->setPrompt('give your answer as json and keep it simple')
        ->ask('What is your name');

    print_r($openai->getResponse());
} catch (\Exception $exception) {
    echo $exception->getMessage();
}

use CeytekLabs\OpenAI\OpenAI;
use CeytekLabs\OpenAI\Enums\Model;

try {
    $openai = OpenAI::make('<your-key-here>')
        ->chat()
        ->createImageCompletion()
        ->setModel(Model::GPT_4_TURBO)
        ->ask('What is in this image', 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg');

    print_r($openai->getResponse());
} catch (\Exception $exception) {
    echo $exception->getMessage();
}

use CeytekLabs\OpenAI\OpenAI;

try {
    $openai = OpenAI::make('<your-key-here>')
        ->model()
        ->availableList()
        ->ask();

    print_r($openai->getResponse());
} catch (\Exception $exception) {
    echo $exception->getMessage();
}

use CeytekLabs\OpenAI\OpenAI;
use CeytekLabs\OpenAI\Enums\Model;

try {
    $openai = OpenAI::make('<your-key-here>')
        ->model()
        ->retrieve()
        ->ask(Model::GPT_4O_MINI);

    print_r($openai->getResponse());
} catch (\Exception $exception) {
    echo $exception->getMessage();
}