PHP code example of luminovang / php-ai-models-enum
1. Go to this page and download the library: Download luminovang/php-ai-models-enum 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-enum example snippets
composer install luminovang/php-ai-models-enum
use Luminova\AI\Model;
// Correct — pass ->value to the client
$ai->message('Hello!', ['model' => Model::GPT_4_1_MINI->value]);
// Also correct when your method accepts Model directly and extracts ->value internally
function chat(Model $model, string $prompt): array {
return $ai->message($prompt, ['model' => $model->value]);
}
use Luminova\AI\Model;
use Luminova\AI\AI;
// Chat with OpenAI
$reply = AI::Openai($key)->message('Hello!', [
'model' => Model::GPT_4_1_MINI->value,
]);
// Chat with Claude
$reply = AI::Anthropic($key)->message('Summarise this.', [
'model' => Model::CLAUDE_SONNET_4_6->value,
]);
// Local inference with Ollama
$reply = AI::Ollama()->message('Explain closures.', [
'model' => Model::LLAMA_3_2->value,
]);
// Embeddings
$vector = AI::Openai($key)->embed('Hello world', [
'model' => Model::TEXT_EMBEDDING_3_SMALL->value,
]);
// Ollama vision
$reply = AI::Ollama()->vision('What is in this image?', '/tmp/photo.jpg', [
'model' => Model::LLAVA->value,
]);
use Luminova\AI\Model;
function chat(string $prompt, Model $model = Model::GPT_4_1_MINI): array
{
return AI::getInstance()->message($prompt, ['model' => $model->value]);
}
// Valid calls
chat('Hello!');
chat('Hello!', Model::O3);
chat('Hello!', Model::CLAUDE_OPUS_4_6);
chat('Hello!', Model::LLAMA_3_3);
// Invalid — PHP type error at call time, not a runtime client error
chat('Hello!', 'gpt-4.1-mini'); // TypeError: Argument 2 must be of type Model
// From a config file
$configured = $config->get('ai.model', 'gpt-4.1-mini');
$model = Model::resolve($configured) ?? Model::GPT_4_1_MINI;
echo "Using: {$model->value} ({$model->client()})";
// From a web request — reject unknown values
$userModel = $_POST['model'] ?? '';
$model = Model::tryFrom($userModel);
if ($model === null) {
http_response_code(400);
exit("Unknown model: {$userModel}");
}
$reply = $ai->message($prompt, ['model' => $model->value]);
use Luminova\AI\AI;
use Luminova\AI\Model;
function chat(string $prompt, Model $model): array
{
return match ($model->client()) {
'openai' => AI::Openai($_ENV['OPENAI_KEY'])->message($prompt, ['model' => $model->value]),
'anthropic' => AI::Anthropic($_ENV['ANTHROPIC_KEY'])->message($prompt, ['model' => $model->value]),
'ollama' => AI::Ollama()->message($prompt, ['model' => $model->value]),
};
}
chat('Tell me a joke.', Model::GPT_4_1_MINI); // OpenAI
chat('Tell me a joke.', Model::CLAUDE_SONNET_4_6); // Anthropic
chat('Tell me a joke.', Model::LLAMA_3_2); // Ollama
use Luminova\AI\Model;
function analyzeImage(string $prompt, string $imagePath, Model $model): array
{
if (!$model->isVision()) {
throw new RuntimeException(
"Model '{$model->value}' does not support vision. " .
'Try Model::GPT_4_1, Model::LLAVA, or Model::LLAMA_3_2_VISION.'
);
}
return AI::getInstance()->vision($prompt, $imagePath, ['model' => $model->value]);
}
analyzeImage('What breed is this?', '/tmp/dog.jpg', Model::GPT_4_1); // OK
analyzeImage('What breed is this?', '/tmp/dog.jpg', Model::WHISPER_1); // throws
function embed(string $text, Model $model = Model::TEXT_EMBEDDING_3_SMALL): array
{
if (!$model->isEmbedding()) {
throw new RuntimeException("'{$model->value}' is not an embedding model.");
}
return AI::getInstance()->embed($text, ['model' => $model->value]);
}
// All available models grouped by client for a settings page
$grouped = [];
foreach (Model::cases() as $model) {
$grouped[$model->client()][] = [
'value' => $model->value,
'label' => str_replace('_', ' ', ucfirst(strtolower($model->name))),
'tags' => $model->capabilities(),
];
}
// Only offer vision-capable models in a vision task dropdown
$visionOptions = array_map(
fn(Model $m): array => ['value' => $m->value, 'label' => $m->name],
Model::forCapability('vision')
);
// Always-latest alias — may quietly change behavior when Anthropic updates it
$model = Model::CLAUDE_OPUS_4_5; // 'claude-opus-4-5'
// Pinned snapshot — behavior is frozen to the exact release
$model = Model::CLAUDE_OPUS_4_5_SNAP; // 'claude-opus-4-5-20251101'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.