PHP code example of cybernerdie / glint

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

    

cybernerdie / glint example snippets


// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->append(\Cybernerdie\Glint\Middleware\GlintMiddleware::class);
})

use Cybernerdie\Glint\Facades\Glint;

$trace = Glint::trace('chat.pipeline', [
    'user_id' => (string) auth()->id(),
]);

try {
    $generation = Glint::generation('summarise', 'openai', 'gpt-4o');
    $generation
        ->prompt($prompt)
        ->options(temperature: 0.7, maxTokens: 1024, topP: 0.9);

    $response = $client->chat($prompt);

    $generation->finish(
        completion: $response->text,
        promptTokens: $response->promptTokens,
        completionTokens: $response->completionTokens,
    );
} catch (\Throwable $e) {
    isset($generation) && $generation->fail($e);

    throw $e;
} finally {
    $trace->end();
}
bash
php artisan queue:work --queue=glint