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-14 07:57:51 UTC


README

Latest Version GitHub Actions Test Workflow Status GitHub License

Features

  • Get model information from various AI providers (Ollama, LiteLLM)
  • PSR-16 Simple Cache support for caching model information
  • Retrieve available models for supported providers
  • Get detailed model information for specific models
  • Extensible provider system

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);

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

// Using with custom cache implementation
$factory = new ModelInfoFactory(
    cache: $yourPsr16CacheImplementation
);

// Force fetch (bypass cache) with exception handling
try {
    $models = $factory->getModelsOrFail(ModelProvider::LiteLLM);
    $modelInfo = $factory->getModelInfoOrFail(ModelProvider::LiteLLM, 'gpt-4');
} catch (ModelInfoException $e) {
    // Handle exception
}

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

Credits

License

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