-
-
Notifications
You must be signed in to change notification settings - Fork 102
Open
Labels
Hackathon 2025This issue or pull request was part of the Symfony AI Hackathon 2025This issue or pull request was part of the Symfony AI Hackathon 2025RFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)
Description
Problem
Currently, AI platform configuration requires multiple parameters (API key, endpoint, version, etc.) to be set separately. Symfony already uses DSN patterns successfully for mailers and notifiers, providing a clean and standardized way to configure external services.
Proposed Solution
Implement a DSN (Data Source Name) format for AI platform configuration, following Symfony's established patterns:
scheme://API_KEY@HOST[:PORT][/PATH]?option1=value1&option2=value2
Examples
Basic Usage
// Anthropic
'anthropic://[email protected]?version=2025-01-01'
// OpenAI
'openai://[email protected]/v1?model=gpt-4'
// Azure OpenAI
'azure://[email protected]?api-version=2024-02-01&deployment=gpt-4'
// Custom/Self-hosted
'ollama://localhost:11434?model=llama2'
Environment Variables
# .env file
AI_PLATFORM_DSN=anthropic://[email protected]?version=2025-01-01
Configuration
# config/packages/ai.yaml
ai:
platform:
dsn: '%env(AI_PLATFORM_DSN)%'
Bundle Configuration Example
# config/packages/ai.yaml
ai:
agents:
my_assistant:
platform: 'anthropic://[email protected]?version=2025-01-01&model=claude-3-opus'
code_reviewer:
platform: 'openai://[email protected]/v1?model=gpt-4&temperature=0.2'
local_agent:
platform: 'ollama://localhost:11434?model=llama2'
Platform Configuration Simplification
Current platform configuration:
ai:
platform:
openai:
api_key: '%env(OPENAI_API_KEY)%'
azure:
default:
base_url: '%env(AZURE_OPENAI_BASEURL)%'
deployment: '%env(AZURE_OPENAI_GPT)%'
api_key: '%env(AZURE_OPENAI_API_KEY)%'
api_version: '%env(AZURE_OPENAI_VERSION)%'
embeddings:
base_url: '%env(AZURE_OPENAI_EMBEDDINGS_BASEURL)%'
deployment: '%env(AZURE_OPENAI_EMBEDDINGS)%'
api_key: '%env(AZURE_OPENAI_EMBEDDINGS_API_KEY)%'
api_version: '%env(AZURE_OPENAI_VERSION)%'
With DSN:
ai:
platform:
openai: '%env(OPENAI_DSN)%' # openai://[email protected]/v1
azure:
default: '%env(AZURE_DSN)%' # azure://[email protected]?deployment=gpt-4&api-version=2024-02-01
embeddings: '%env(AZURE_EMBEDDINGS_DSN)%' # azure://[email protected]?deployment=embeddings&api-version=2024-02-01
DSN Components
- Scheme: Provider name (
anthropic
,openai
,azure
,ollama
, etc.) - User: API key or authentication token
- Host: API endpoint URL
- Port: Optional port number (default varies by provider)
- Path: Optional API path
- Query Parameters:
version
: API versionmodel
: Default modeltimeout
: Request timeoutmax_retries
: Retry configuration- Provider-specific options
Benefits
- Consistency: Follows Symfony's established DSN patterns (mailer, notifier)
- Simplicity: Single configuration string contains all connection details
- Security: Easy to use environment variables for sensitive data
- Flexibility: Query parameters allow provider-specific configurations
- Familiarity: Developers already know this pattern from other Symfony components
Implementation Notes
- Parse DSN using Symfony's existing DSN parsing utilities (across different components)
- Support only full DSN and no individual parameters in configuration anymore (NO backward compatibility)
- Validate scheme against supported providers
- Handle provider-specific requirements in dedicated factories
References
welcoMattic, lochmueller and Pixman
Metadata
Metadata
Assignees
Labels
Hackathon 2025This issue or pull request was part of the Symfony AI Hackathon 2025This issue or pull request was part of the Symfony AI Hackathon 2025RFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)