symfony/ai-open-ai-platform
OpenAI platform integration for Symfony AI Platform, adding GPT chat completions, embeddings, DALL-E image generation, Whisper audio transcription, and text-to-speech support.
ChatCompletionClientInterface, EmbeddingClientInterface, etc.). It aligns with Symfony’s DI, configuration-driven architecture, and event-driven patterns. Ideal for:
config/packages/ system, enabling environment-specific configurations.parameter_bag for secure credential management.HttpClientMock to simulate OpenAI API responses.symfony/ai (v1.0+).ChatMessage, BatchJob entities).guzzlehttp/guzzle); batch and realtime features may require custom wrappers./chat endpoint) using the package.config/test/ to validate configuration.// src/Controller/ChatController.php
use Symfony\AI\OpenAI\Client\ChatCompletionClientInterface;
class ChatController {
public function __construct(private ChatCompletionClientInterface $client) {}
public function __invoke(Request $request): Response {
$response = $this->client->createChatCompletion([
'model' => 'gpt-4',
'messages' => [['role' => 'user', 'content' => $request->request->get('prompt')]],
]);
return new Response($response->getChoices()[0]->getMessage()->getContent());
}
}
BatchClient (if available) and processes results via Messenger.ChatCompletionClientInterface).config/packages/ai_open_ai.yaml:
ai_open_ai:
client:
api_key: '%env(AI_OPEN_AI_KEY)%'
base_uri: 'https://api.openai.com/v1'
timeout: 30
retries: 3
models:
default: gpt-4
fallback: gpt-3.5-turbo
symfony/ai (≥v0.14.0), symfony/http-client, symfony/flex.^ or ~).Embedding, AudioTranscription, BatchJob).#[ORM\Entity]
class ChatMessage {
#[ORM\Id, ORM\GeneratedValue]
private ?int $id = null;
// ...
}
How can I help you explore Laravel packages today?