cortexphp/model-info

A unified way to get AI model info from various providers

0.1.0 2025-05-14 07:52 UTC

This package is auto-updated.

Last update: 2025-05-15 07:28:06 UTC


README

Latest Version GitHub Actions Test Workflow Status GitHub License

Features

  • 🤖 Model Providers - Get detailed model information with type-safe responses from various model providers (OpenAI, Ollama, etc.)
  • 💾 Simple Cache - PSR-16 Simple Cache support for caching model information
  • 🔌 Extensibility - Easily add support for additional model providers

Requirements

  • PHP 8.3+

Installation

composer require cortexphp/model-info

Usage

use Cortex\ModelInfo\ModelInfoFactory;
use Cortex\ModelInfo\Enums\ModelProvider;

// Create a new factory instance
$factory = new ModelInfoFactory();

// Get all available models for a provider
$models = $factory->getModels(ModelProvider::Ollama);
// ['llama3.1', 'llama3.1:8b', 'llama3.1:70b']

// Get information about a specific model
$modelInfo = $factory->getModelInfo(ModelProvider::Ollama, 'llama3.1');

// Accessing model information properties
echo $modelInfo->name;            // 'llama3.1'
echo $modelInfo->provider;        // ModelProvider::Ollama
echo $modelInfo->type;            // ModelType::Chat
echo $modelInfo->maxInputTokens;  // 8000
echo $modelInfo->maxOutputTokens; // null
echo $modelInfo->inputCostPerToken;  // 0.0
echo $modelInfo->outputCostPerToken; // 0.0
echo $modelInfo->isDeprecated;    // false
echo $modelInfo->features;        // [ModelFeature::ToolCalling, ModelFeature::JsonOutput, etc]

// Check if model supports specific features
if ($modelInfo->supportsFeature(ModelFeature::ToolCalling)) {
    // Use tool calling feature
}
// Using with custom PSR-16 cache implementation
$factory = new ModelInfoFactory(
    cache: $yourPsr16CacheImplementation // `Psr\SimpleCache\CacheInterface`
);

// With exception handling
try {
    $modelInfo = $factory->getModelInfoOrFail(ModelProvider::OpenAI, 'gpt-4o');
} catch (ModelInfoException $e) {
    // Handle exception
}

// Clear the cache
$factory->flushCache();

Credits

License

The MIT License (MIT). Please see License File for more information.