Search by

proweb / yii2-ai

vyatka

AI/LLM access for Yii2: provider factory (Yandex, OpenAI, Claude, Gemini, DeepSeek, Grok, OpenAI-compatible) and a chat service on top of ai-access.

Package info

github.com/yii2-ext/yii2-ai

Documentation

Type:yii2-extension

pkg:composer/proweb/yii2-ai

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-11-08 20:28 UTC

This package is auto-updated.

Last update: 2026-11-09 09:38:15 UTC


README

< English | Русский >

Latest stable version PHP version Total downloads

AI/LLM access for Yii2: a provider factory and a chat service on top of ai-access.

One dependency, seven backends: Yandex AI Studio, OpenAI, Claude, Gemini, DeepSeek, Grok, and any OpenAI-compatible endpoint (Ollama, OpenRouter, vLLM, ...).

  • One-line provider setup with per-provider presets
  • One-shot generation, streaming, and multi-turn chat with your own history
  • Default generation options (temperature, max tokens, top-p) applied to every chat
  • Model listing straight from the backend
  • Console smoke-test commands (ai/chat, ai/list-models)
  • DI integration: component or container definition, your choice

[!NOTE] A Russian version of this guide is available in README_RU.md.

Requirements

  • PHP 8.3 or higher
  • Yii 2.0.54+ or the Yii 22 development branch
  • ext-curl (used by ai-access)

Installation

composer require proweb/yii2-ai

Quick start

use proweb\ai\ChatService;
use proweb\ai\ProviderFactory;

$service = new ChatService(
    ProviderFactory::yandex(
        apiKey: 'your-api-key',
        model: 'qwen3.6-35b-a3b',
        folder: 'your-folder-id',
        temperature: 0.3,
        maxTokens: 1024,
    ),
);

$response = $service->generate('Write a haiku about PHP.');
echo $response->getText();

Or wire it into the application once and pull it from the container:

// config/web.php (or console.php)
'bootstrap' => ['log', \proweb\ai\Bootstrap::class],
'components' => [
    'ai' => [
        'class' => \proweb\ai\AiComponent::class,
        'provider' => 'yandex',
        'apiKey' => env('YANDEX_CLOUD_API_KEY'),
        'model' => 'qwen3.6-35b-a3b',
        'folder' => env('YANDEX_CLOUD_FOLDER'),
    ],
],
$service = Yii::$container->get(\proweb\ai\ChatServiceInterface::class);

Documentation

The yii2-ai skill covers provider setup, the chat service, console commands, and testing conventions.

Console commands

php yii ai/list-models
php yii ai/chat "Hello" --model=gpt://<folder>/<model>

Register the controller in the console controllerMap and provide a ChatServiceInterface container definition (see Configuration).

Changelog

See CHANGELOG.md.

License

MIT. The extension wraps ai-access (BSD-3-Clause) by David Grudl.