1. Go to this page and download the library: Download lingoda/langfuse-bundle 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/ */
use Lingoda\AiSdk\PlatformInterface;
class ContentService
{
public function __construct(
private PlatformInterface $platform
) {}
public function generateContent(string $prompt): string
{
// This call is automatically traced to Langfuse with proper generation and usage metrics
$result = $this->platform->ask($prompt, 'gpt-4');
return $result->getContent();
}
public function generateAudio(string $text): string
{
// TTS operations are also traced
$audio = $this->platform->textToSpeech($text);
return $audio->getContent();
}
}
use Lingoda\LangfuseBundle\Prompt\PromptRegistryInterface;
use Lingoda\AiSdk\Prompt\Conversation;
class EmailService
{
public function __construct(
private PromptRegistryInterface $prompts
) {}
public function generateWelcomeEmail(string $userName): Conversation
{
// Intelligent cascade: Cache → API → Storage
return $this->prompts->get('welcome_email');
}
public function generateCustomEmail(string $promptName, array $variables): Conversation
{
// Get specific version with variables
$prompt = $this->prompts->getCompiled($promptName, $variables);
return $prompt;
}
}
use Lingoda\AiSdk\Result\TextResult;
use Lingoda\LangfuseBundle\Tracing\TraceManagerInterface;
class SummaryService
{
public function __construct(
private TraceManagerInterface $traceManager
) {}
public function summarize(string $text): TextResult
{
return $this->traceManager->trace(
'custom-summary',
['model' => 'my-local-model'], // a model makes it a generation
$text,
fn () => $this->runSummary($text) // returns a ResultInterface
);
}
}
bash
php bin/console messenger:consume langfuse_traces --time-limit=3600
# or multiple workers for high throughput
php bin/console messenger:consume langfuse_traces --limit=100
php bin/console messenger:consume langfuse_traces --limit=100
...
bash
php bin/console langfuse:test-connection
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.