PHP code example of iserter / laravel-uniformed-ai
1. Go to this page and download the library: Download iserter/laravel-uniformed-ai 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/ */
iserter / laravel-uniformed-ai example snippets
use Iserter\UniformedAI\Facades\AI;
use Iserter\UniformedAI\Services\Chat\DTOs\{ChatMessage, ChatRequest};
use Iserter\UniformedAI\Services\Audio\DTOs\{AudioRequest, AudioTranscriptionRequest};
//...
// Chat
$response = AI::chat()->send(new ChatRequest([
new ChatMessage('system', 'You are a helpful assistant.'),
new ChatMessage('user', 'Write a haiku about Laravel.'),
]));
// Image
$img = AI::image()->create(new ImageRequest(prompt: 'A low-poly fox, 3D, studio light', size: '1024x1024'));
file_put_contents(storage_path('app/fox.png'), base64_decode($img->images[0]['b64']));
// On-the-fly provider override (bypasses configured default):
// Chat default may be openai, but call OpenRouter just for this request (streaming supported)
$or = AI::chat('openrouter')->send(new ChatRequest([
new ChatMessage('user', 'Respond via OpenRouter only once.')
]));
// Image with named argument provider (works nicely with PHP named params)
$img2 = AI::image(provider: 'openai')->create(new ImageRequest(prompt: 'A serene lake at dawn'));
// Audio - Text-to-Speech (TTS)
$tts = AI::audio()->speak(new AudioRequest(text: 'Hello world from Laravel.', voice: 'Rachel', format: 'mp3'));
file_put_contents(storage_path('app/hello.mp3'), base64_decode($tts->b64Audio));
// Audio - Speech-to-Text (STT / Transcription)
$transcript = AI::audio()->transcribe(new AudioTranscriptionRequest(
audioFile: storage_path('app/recording.mp3'),
language: 'en'
));
echo $transcript->text; // "This is the transcribed text..."
// Audio transcription with base64 encoded audio
$transcript = AI::audio()->transcribe(new AudioTranscriptionRequest(
audioFile: $base64AudioContent,
isBase64: true,
language: 'es'
));
// Search
$results = AI::search()->query(new SearchQuery('Latest on PHP 8.3 features', maxResults: 5));
// Video (e.g. AI_VIDEO_PROVIDER=google for Gemini Veo; replicate, kie, elevenlabs also available)
try {
$video = AI::video()->driver('google')->generate(new VideoRequest(prompt: 'A serene flyover of a futuristic Laravel city', durationSeconds: 8));
if ($video->hasUrl()) {
// With Google driver, the returned URL may
app(\Iserter\UniformedAI\Services\Chat\ChatManager::class)->extend('myprovider', function($app) {
return new \App\AI\Drivers\MyProviderChatDriver(config('services.myprovider'));
});
use Iserter\UniformedAI\Facades\AI;
// Full catalog (service => provider => models[])
$catalog = AI::catalog();
// e.g. $catalog['chat']['openai'] contains: ['gpt-4.1-mini','gpt-4.1','gpt-4o-mini','o3-mini']
// List available chat providers
$providers = AI::chat()->getProviders(); // ['openai','openrouter','google','kie','piapi']
// List curated models for a provider
$models = AI::chat()->getModels('openai');
// Unknown provider returns an empty array (no exception)
$none = AI::chat()->getModels('does-not-exist'); // []
// Iterate to render a UI select
foreach (AI::catalog()['chat'] as $provider => $models) {
// render option group for $provider with $models
}
// Video catalog enumeration (new)
foreach (AI::catalog()['video'] as $provider => $models) {
// render video model options
}