PHP code example of mliviu79 / laravel-langfuse-prism

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

    

mliviu79 / laravel-langfuse-prism example snippets


// config/langfuse.php
'prism' => [
    'auto_trace' => true,
    'trace_model_params' => true,
    'trace_usage' => true,
    'trace_cost' => true,
],

use Prism\Prism\Facades\Prism;

// This operation will be automatically traced in Langfuse
$response = Prism::text()
    ->using('anthropic', 'claude-3-opus')
    ->withPrompt('Explain quantum computing like I am 5')
    ->generate();

use Langfuse\Integration\Laravel\Facades\Langfuse;

$span = Langfuse::startSpan('my-custom-operation');

try {
    // ... your code ...
    $span->end();
} catch (\Exception $e) {
    $span->update(level: 'ERROR', statusMessage: $e->getMessage());
    $span->end();
    throw $e;
}
bash
php artisan vendor:publish --tag=langfuse-config