papi-ai/symfony
最新稳定版本:v0.9.1
Composer 安装命令:
composer require papi-ai/symfony
包简介
Symfony bridge for PapiAI - Integrate AI agents into your Symfony application
README 文档
README
Symfony bridge for PapiAI -- integrate AI agents into your Symfony application with full dependency injection, configuration, and service wiring.
Installation
composer require papi-ai/symfony
Bundle Registration
If you are not using Symfony Flex, register the bundle manually in config/bundles.php:
return [ // ... PapiAI\Symfony\PapiBundle::class => ['all' => true], ];
Configuration
Create config/packages/papi.yaml:
papi: default_provider: openai providers: openai: driver: PapiAI\OpenAI\OpenAIProvider api_key: '%env(OPENAI_API_KEY)%' model: gpt-4o anthropic: driver: PapiAI\Anthropic\AnthropicProvider api_key: '%env(ANTHROPIC_API_KEY)%' model: claude-sonnet-4-20250514 middleware: - app.middleware.logging - app.middleware.rate_limit conversation: store: file path: '%kernel.project_dir%/var/papi/conversations'
Usage
Injecting a Provider
use PapiAI\Core\Contracts\ProviderInterface; class ChatController { public function __construct( private ProviderInterface $provider, ) {} public function chat(string $message): string { $response = $this->provider->chat([ ['role' => 'user', 'content' => $message], ]); return $response->getText(); } }
Using Conversation Storage
use PapiAI\Core\Contracts\ConversationStoreInterface; use PapiAI\Core\Conversation; class ConversationService { public function __construct( private ConversationStoreInterface $store, ) {} public function saveConversation(string $id, Conversation $conversation): void { $this->store->save($id, $conversation); } public function loadConversation(string $id): ?Conversation { return $this->store->load($id); } }
Using Doctrine Conversation Store
Install Doctrine DBAL and configure the store:
composer require doctrine/dbal
papi: conversation: store: doctrine
Create the conversations table in your database:
CREATE TABLE papi_conversations ( id VARCHAR(255) PRIMARY KEY, data JSON NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL );
Using Messenger Queue
Install Symfony Messenger:
composer require symfony/messenger
use PapiAI\Core\Contracts\QueueInterface; use PapiAI\Core\AgentJob; class AgentService { public function __construct( private QueueInterface $queue, ) {} public function dispatchJob(string $agentClass, string $prompt): string { $job = new AgentJob( agentClass: $agentClass, prompt: $prompt, ); return $this->queue->dispatch($job); } }
License
MIT License. See LICENSE for details.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-08