Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/ai-bundle/config/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
->children()
->scalarNode('api_key')->isRequired()->end()
->scalarNode('version')->defaultNull()->end()
->scalarNode('http_client')
->defaultValue('http_client')
->info('Service ID of the HTTP client to use')
->end()
->end()
->end()
->arrayNode('azure')
Expand All @@ -39,18 +43,30 @@
->scalarNode('base_url')->isRequired()->end()
->scalarNode('deployment')->isRequired()->end()
->scalarNode('api_version')->info('The used API version')->end()
->scalarNode('http_client')
->defaultValue('http_client')
->info('Service ID of the HTTP client to use')
->end()
->end()
->end()
->end()
->arrayNode('eleven_labs')
->children()
->scalarNode('host')->end()
->scalarNode('api_key')->isRequired()->end()
->scalarNode('http_client')
->defaultValue('http_client')
->info('Service ID of the HTTP client to use')
->end()
->end()
->end()
->arrayNode('gemini')
->children()
->scalarNode('api_key')->isRequired()->end()
->scalarNode('http_client')
->defaultValue('http_client')
->info('Service ID of the HTTP client to use')
->end()
->end()
->end()
->arrayNode('vertexai')
Expand All @@ -70,41 +86,73 @@
->end()
->info('The region for OpenAI API (EU, US, or null for default)')
->end()
->scalarNode('http_client')
->defaultValue('http_client')
->info('Service ID of the HTTP client to use')
->end()
->end()
->end()
->arrayNode('mistral')
->children()
->scalarNode('api_key')->isRequired()->end()
->scalarNode('http_client')
->defaultValue('http_client')
->info('Service ID of the HTTP client to use')
->end()
->end()
->end()
->arrayNode('openrouter')
->children()
->scalarNode('api_key')->isRequired()->end()
->scalarNode('http_client')
->defaultValue('http_client')
->info('Service ID of the HTTP client to use')
->end()
->end()
->end()
->arrayNode('lmstudio')
->children()
->scalarNode('host_url')->defaultValue('http://127.0.0.1:1234')->end()
->scalarNode('http_client')
->defaultValue('http_client')
->info('Service ID of the HTTP client to use')
->end()
->end()
->end()
->arrayNode('ollama')
->children()
->scalarNode('host_url')->defaultValue('http://127.0.0.1:11434')->end()
->scalarNode('http_client')
->defaultValue('http_client')
->info('Service ID of the HTTP client to use')
->end()
->end()
->end()
->arrayNode('cerebras')
->children()
->scalarNode('api_key')->isRequired()->end()
->scalarNode('http_client')
->defaultValue('http_client')
->info('Service ID of the HTTP client to use')
->end()
->end()
->end()
->arrayNode('voyage')
->children()
->scalarNode('api_key')->isRequired()->end()
->scalarNode('http_client')
->defaultValue('http_client')
->info('Service ID of the HTTP client to use')
->end()
->end()
->end()
->arrayNode('perplexity')
->children()
->scalarNode('api_key')->isRequired()->end()
->scalarNode('http_client')
->defaultValue('http_client')
->info('Service ID of the HTTP client to use')
->end()
->end()
->end()
->end()
Expand Down
26 changes: 26 additions & 0 deletions src/ai-bundle/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,32 @@ Configuration
vectorizer: 'ai.vectorizer.mistral_embeddings'
store: 'ai.store.memory.research'

HTTP Client Configuration
-------------------------

Each platform can be configured with a custom HTTP client service to handle API requests.
This allows you to customize timeouts, proxy settings, SSL configurations, and other HTTP-specific options.

By default, all platforms use the standard Symfony HTTP client service (``http_client``):

.. code-block:: yaml

ai:
platform:
openai:
api_key: '%env(OPENAI_API_KEY)%'
# http_client: 'http_client' # This is the default

You can specify a custom HTTP client service for any platform:

.. code-block:: yaml

ai:
platform:
openai:
api_key: '%env(OPENAI_API_KEY)%'
http_client: 'app.custom_http_client'

System Prompt Configuration
---------------------------

Expand Down
24 changes: 12 additions & 12 deletions src/ai-bundle/src/AiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->addTag('proxy', ['interface' => PlatformInterface::class])
->setArguments([
$platform['api_key'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.anthropic'),
])
->addTag('ai.platform');
Expand All @@ -243,7 +243,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
$config['deployment'],
$config['api_version'],
$config['api_key'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference($config['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.openai'),
])
->addTag('ai.platform');
Expand All @@ -263,7 +263,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->setArguments([
$platform['api_key'],
$platform['host'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.default'),
])
->addTag('ai.platform');
Expand All @@ -281,7 +281,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->addTag('proxy', ['interface' => PlatformInterface::class])
->setArguments([
$platform['api_key'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.google'),
])
->addTag('ai.platform');
Expand Down Expand Up @@ -338,7 +338,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->addTag('proxy', ['interface' => PlatformInterface::class])
->setArguments([
$platform['api_key'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.openai'),
$platform['region'] ?? null,
])
Expand All @@ -357,7 +357,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->addTag('proxy', ['interface' => PlatformInterface::class])
->setArguments([
$platform['api_key'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.default'),
])
->addTag('ai.platform');
Expand All @@ -375,7 +375,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->addTag('proxy', ['interface' => PlatformInterface::class])
->setArguments([
$platform['api_key'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.default'),
])
->addTag('ai.platform');
Expand All @@ -393,7 +393,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->addTag('proxy', ['interface' => PlatformInterface::class])
->setArguments([
$platform['host_url'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.default'),
])
->addTag('ai.platform');
Expand All @@ -412,7 +412,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->addTag('proxy', ['interface' => PlatformInterface::class])
->setArguments([
$platform['host_url'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.ollama'),
])
->addTag('ai.platform');
Expand All @@ -430,7 +430,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->addTag('proxy', ['interface' => PlatformInterface::class])
->setArguments([
$platform['api_key'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
])
->addTag('ai.platform');

Expand All @@ -447,7 +447,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->addTag('proxy', ['interface' => PlatformInterface::class])
->setArguments([
$platform['api_key'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
])
->addTag('ai.platform');

Expand All @@ -464,7 +464,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
->addTag('proxy', ['interface' => PlatformInterface::class])
->setArguments([
$platform['api_key'],
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference($platform['http_client'], ContainerInterface::NULL_ON_INVALID_REFERENCE),
new Reference('ai.platform.contract.perplexity'),
])
->addTag('ai.platform');
Expand Down