sbh / ai-integration-bundle
A Symfony bundle to integrate AI models (ChatGPT, DeepSeek, Gemini...) with a unified interface.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/sbh/ai-integration-bundle
Requires
- php: >=8.1
- symfony/config: ^6.0 || ^7.0
- symfony/http-client: ^6.0 || ^7.0
This package is auto-updated.
Last update: 2025-12-17 12:14:38 UTC
README
A powerful Symfony bundle that provides unified access to multiple AI providers (ChatGPT, Gemini, DeepSeek) with a simple, consistent interface.
✨ Features
- Multi-provider support: Switch between ChatGPT, Gemini, DeepSeek and more
- Simple configuration: YAML-based setup with environment variables
- Extensible architecture: Easily add new AI providers
- Smart defaults: Pre-configured with recommended models for each provider
- Production-ready: Built on Symfony's HttpClient for reliability
- Caching support: Optional caching of API responses
📦 Installation
Requirements
- PHP 8.1 or higher
- Symfony 5.4+ or 6.0+
1. Install with Composer
composer require sbh/ai-integration-bundle
⚙️ Configuration
config/packages/ai_integration.yaml
ai_integration:
default_provider: chatgpt
providers:
chatgpt:
api_key: '%env(CHATGPT_API_KEY)%'
model: 'gpt-4o'
gemini:
api_key: '%env(GEMINI_API_KEY)%'
model: 'gemini-1.5-pro'
deepseek:
api_key: '%env(DEEPSEEK_API_KEY)%'
model: 'deepseek-chat'
Add to your API keys in .env
CHATGPT_API_KEY=sk-xxxx GEMINI_API_KEY=xxxx DEEPSEEK_API_KEY=xxxx
🛠 Usage
Inject the AIClientFactory into your service or controller.
use Sbh\AiIntegrationBundle\Service\AIClientFactory; public function __construct(private AIClientFactory $factory) {} public function askAI(): void { $client = $this->factory->getClient('gemini'); // or chatgpt, deepseek... $answer = $client->chat('What is Symfony?'); dump($answer); }
Or via a route:
#[Route('/ask/{provider}', name: 'ask_ai')] public function ask(AIClientFactory $factory, string $provider = 'chatgpt'): JsonResponse { $client = $factory->getClient($provider); $answer = $client->chat('Explain Symfony Bundles'); return $this->json(['provider' => $provider, 'answer' => $answer]); }
➕ Adding a New AI Provider
- Create a new Client class in src/Service implementing AIClientInterface.
namespace Sbh\AiIntegrationBundle\Service; use Symfony\Contracts\HttpClient\HttpClientInterface; class ClaudeClient implements AIClientInterface { public function __construct( private string $apiKey, private ?string $model, private HttpClientInterface $httpClient ) {} public function chat(string $prompt, array $options = []): string { // Call the Claude API here } }
- Add its configuration in ai_integration.yaml:
providers:
claude:
api_key: '%env(CLAUDE_API_KEY)%'
model: 'claude-3-opus'
Update the AIClientFactory to add a case 'claude' in the match() statement.
📜 Requirements
-
PHP >=8.1
-
Symfony ^6.0 || ^7.0
-
symfony/http-client
🗺 Roadmap
-
✅ Add support for service tags & auto-discovery (no factory changes for new tools).
-
✅ Streaming support for long responses.
-
✅ Embeddings & vector search integration (pgvector, Pinecone).
👤 Author
- Said Ben Hmed
- MIT License.