proweb / yii2-ai
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
Type:yii2-extension
pkg:composer/proweb/yii2-ai
Requires
- php: >=8.3
- ai-access/ai-access: ^1.1
- yiisoft/yii2: ^2.0.54 || ^22.0@dev
Requires (Dev)
- infection/infection: ^0.35
- maglnet/composer-require-checker: ^4.1
- php-forge/coding-standard: ^0.3
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0.3
- phpunit/phpunit: ^12.5
- rector/rector: ^2.0
- yii2-extensions/phpstan: ^0.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-09 09:38:15 UTC
README
< English | Русский >
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
- Installation guide
- Configuration
- Providers
- Usage
- Testing
- AI agents: skill installation, client setup, and verification.
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.