1. Go to this page and download the library: Download luminovang/php-ai-models 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/ */
luminovang / php-ai-models example snippets
composer install luminovang/php-ai-models
use Luminova\AI\Model;
// Anywhere a model string is expected — pass the constant value.
$ai->message('Hello!', ['model' => Model::GPT_4_1_MINI]);
$ai->embed('Hello world', ['model' => Model::TEXT_EMBEDDING_3_SMALL]);
$ai->vision('Describe this.', '/tmp/img.png', ['model' => Model::LLAVA]);
use Luminova\AI\Model;
use Luminova\AI\AI;
// Chat
$reply = AI::Openai($key)->message('Hello!', [
'model' => Model::GPT_4_1_MINI,
]);
// Chat with Claude
$reply = AI::Anthropic($key)->message('Summarise this.', [
'model' => Model::CLAUDE_SONNET_4_6,
]);
// Local inference with Ollama
$reply = AI::Ollama()->message('Explain recursion.', [
'model' => Model::LLAMA_3_2,
]);
// Embeddings
$vector = AI::Openai($key)->embed('Hello world', [
'model' => Model::TEXT_EMBEDDING_3_SMALL,
]);
// Vision
$output = AI::Openai($key)->vision('What is in this image?', '/tmp/photo.jpg', [
'model' => Model::GPT_4_1,
]);
$userModel = $request->get('model', Model::GPT_4_1_MINI);
if (!Model::exists($userModel)) {
throw new InvalidArgumentException("Unknown model: {$userModel}");
}
$reply = $ai->message('Hello!', ['model' => $userModel]);
// Build a select list for a UI
$options = [];
foreach (Model::forClient('openai') as $name => $id) {
$options[$id] = str_replace('_', ' ', ucfirst(strtolower($name)));
}
// ['gpt-4.1-mini' => 'Gpt 4 1 mini', ...]
// Only offer vision-capable models in the UI
$visionModels = Model::forCapability('vision');
// Only offer embedding models for the vector store config
$embeddingModels = Model::forCapability('embedding');
// Show reasoning models separately
$reasoningModels = Model::forCapability('reasoning');
function analyzeImage(string $prompt, string $imagePath, string $model): array
{
if (!Model::isVision($model)) {
throw new RuntimeException(
"Model '{$model}' does not support vision. " .
"Try: " . Model::GPT_4_1 . " or " . Model::LLAVA
);
}
return AI::getInstance()->vision($prompt, $imagePath, ['model' => $model]);
}
analyzeImage('Describe this chart.', '/tmp/q4.png', Model::GPT_4_1); // OK
analyzeImage('Describe this chart.', '/tmp/q4.png', Model::WHISPER_1); // throws
use Luminova\AI\AI;
use Luminova\AI\Model;
function chat(string $prompt, string $model): array
{
$client = Model::client($model);
return match ($client) {
'openai' => AI::Openai($_ENV['OPENAI_KEY'])->message($prompt, ['model' => $model]),
'anthropic' => AI::Anthropic($_ENV['ANTHROPIC_KEY'])->message($prompt, ['model' => $model]),
'ollama' => AI::Ollama()->message($prompt, ['model' => $model]),
default => throw new RuntimeException("Unsupported client: {$client}"),
};
}
chat('Tell me a joke.', Model::GPT_4_1_MINI); // routed to OpenAI
chat('Tell me a joke.', Model::CLAUDE_SONNET_4_6); // routed to Anthropic
chat('Tell me a joke.', Model::LLAMA_3_2); // routed to Ollama
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.