Skip to content

Commit 1b4e225

Browse files
committed
ref
1 parent 0823bf4 commit 1b4e225

File tree

3 files changed

+57
-40
lines changed

3 files changed

+57
-40
lines changed

src/ai-bundle/config/options.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,18 +1077,18 @@
10771077
->end()
10781078
->end()
10791079
->arrayNode('speech')
1080-
->children()
1081-
->arrayNode('elevenlabs')
1082-
->children()
1083-
->stringNode('tts_model')->end()
1084-
->stringNode('tts_voice')->end()
1085-
->arrayNode('tts_extra_options')
1086-
->scalarPrototype()->end()
1087-
->end()
1088-
->stringNode('stt_model')->end()
1089-
->arrayNode('stt_extra_options')
1090-
->scalarPrototype()->end()
1091-
->end()
1080+
->useAttributeAsKey('name')
1081+
->arrayPrototype()
1082+
->children()
1083+
->stringNode('platform')->isRequired()->end()
1084+
->stringNode('tts_model')->end()
1085+
->stringNode('tts_voice')->end()
1086+
->arrayNode('tts_extra_options')
1087+
->scalarPrototype()->end()
1088+
->end()
1089+
->stringNode('stt_model')->end()
1090+
->arrayNode('stt_extra_options')
1091+
->scalarPrototype()->end()
10921092
->end()
10931093
->end()
10941094
->end()

src/ai-bundle/src/AiBundle.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ private function processChatConfig(string $name, array $configuration, Container
18481848
private function processSpeechConfig(string $name, array $provider, ContainerBuilder $container): void
18491849
{
18501850
if ('elevenlabs' === $name) {
1851-
if (!$container->hasDefinition('ai.platform.'.$name)) {
1851+
if (!$container->hasDefinition($provider['platform'])) {
18521852
throw new RuntimeException(\sprintf('The "%s" platform cannot be found.', $name));
18531853
}
18541854

@@ -1861,8 +1861,7 @@ private function processSpeechConfig(string $name, array $provider, ContainerBui
18611861
$provider['stt_model'],
18621862
$provider['stt_extra_options'] ?? [],
18631863
])
1864-
->addTag('name', $name)
1865-
->addTag('ai.speech_configuration')
1864+
->addTag('ai.speech_configuration', ['name' => $name])
18661865
;
18671866

18681867
$container->setDefinition('ai.speech.'.$name.'.configuration', $configurationDefinition);
@@ -1877,7 +1876,7 @@ private function processSpeechConfig(string $name, array $provider, ContainerBui
18771876
])
18781877
->addTag('proxy', ['interface' => PlatformInterface::class])
18791878
->addTag('proxy', ['interface' => SpeechAwarePlatformInterface::class])
1880-
->addTag('ai.speech_aware_platform'.$name)
1879+
->addTag('ai.speech_aware_platform', ['name' => $name])
18811880
;
18821881

18831882
$container->setDefinition('ai.speech.'.$name.'.platform', $decoratedPlatform);

src/ai-bundle/tests/DependencyInjection/AiBundleTest.php

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use Symfony\AI\Platform\PlatformInterface;
3636
use Symfony\AI\Platform\Speech\SpeechListenerInterface;
3737
use Symfony\AI\Platform\Speech\SpeechProviderInterface;
38+
use Symfony\AI\Platform\SpeechAwarePlatformInterface;
3839
use Symfony\AI\Store\Bridge\AzureSearch\SearchStore as AzureStore;
3940
use Symfony\AI\Store\Bridge\Cache\Store as CacheStore;
4041
use Symfony\AI\Store\Bridge\ChromaDb\Store as ChromaDbStore;
@@ -3599,17 +3600,16 @@ public function testOllamaCanBeCreatedWithCatalogFromApi()
35993600
$ollamaDefinition = $container->getDefinition('ai.platform.ollama');
36003601

36013602
$this->assertTrue($ollamaDefinition->isLazy());
3602-
$this->assertCount(6, $ollamaDefinition->getArguments());
3603+
$this->assertCount(5, $ollamaDefinition->getArguments());
36033604
$this->assertSame('http://127.0.0.1:11434', $ollamaDefinition->getArgument(0));
36043605
$this->assertInstanceOf(Reference::class, $ollamaDefinition->getArgument(1));
36053606
$this->assertSame('http_client', (string) $ollamaDefinition->getArgument(1));
36063607
$this->assertInstanceOf(Reference::class, $ollamaDefinition->getArgument(2));
36073608
$this->assertSame('ai.platform.model_catalog.ollama', (string) $ollamaDefinition->getArgument(2));
36083609
$this->assertInstanceOf(Reference::class, $ollamaDefinition->getArgument(3));
36093610
$this->assertSame('ai.platform.contract.ollama', (string) $ollamaDefinition->getArgument(3));
3610-
$this->assertNull($ollamaDefinition->getArgument(4));
3611-
$this->assertInstanceOf(Reference::class, $ollamaDefinition->getArgument(5));
3612-
$this->assertSame('event_dispatcher', (string) $ollamaDefinition->getArgument(5));
3611+
$this->assertInstanceOf(Reference::class, $ollamaDefinition->getArgument(4));
3612+
$this->assertSame('event_dispatcher', (string) $ollamaDefinition->getArgument(4));
36133613

36143614
$ollamaCatalogDefinition = $container->getDefinition('ai.platform.model_catalog.ollama');
36153615

@@ -3774,17 +3774,16 @@ public function testElevenLabsPlatformCanBeRegistered()
37743774
$this->assertTrue($definition->isLazy());
37753775
$this->assertSame([PlatformFactory::class, 'create'], $definition->getFactory());
37763776

3777-
$this->assertCount(7, $definition->getArguments());
3777+
$this->assertCount(6, $definition->getArguments());
37783778
$this->assertSame('foo', $definition->getArgument(0));
37793779
$this->assertSame('https://api.elevenlabs.io/v1', $definition->getArgument(1));
37803780
$this->assertInstanceOf(Reference::class, $definition->getArgument(2));
37813781
$this->assertSame('http_client', (string) $definition->getArgument(2));
37823782
$this->assertInstanceOf(Reference::class, $definition->getArgument(3));
37833783
$this->assertSame('ai.platform.model_catalog.elevenlabs', (string) $definition->getArgument(3));
37843784
$this->assertNull($definition->getArgument(4));
3785-
$this->assertNull($definition->getArgument(5));
3786-
$this->assertInstanceOf(Reference::class, $definition->getArgument(6));
3787-
$this->assertSame('event_dispatcher', (string) $definition->getArgument(6));
3785+
$this->assertInstanceOf(Reference::class, $definition->getArgument(5));
3786+
$this->assertSame('event_dispatcher', (string) $definition->getArgument(5));
37883787

37893788
$this->assertTrue($definition->hasTag('proxy'));
37903789
$this->assertSame([['interface' => PlatformInterface::class]], $definition->getTag('proxy'));
@@ -3815,17 +3814,16 @@ public function testElevenLabsPlatformWithCustomEndpointCanBeRegistered()
38153814
$this->assertTrue($definition->isLazy());
38163815
$this->assertSame([PlatformFactory::class, 'create'], $definition->getFactory());
38173816

3818-
$this->assertCount(7, $definition->getArguments());
3817+
$this->assertCount(6, $definition->getArguments());
38193818
$this->assertSame('foo', $definition->getArgument(0));
38203819
$this->assertSame('https://api.elevenlabs.io/v2', $definition->getArgument(1));
38213820
$this->assertInstanceOf(Reference::class, $definition->getArgument(2));
38223821
$this->assertSame('http_client', (string) $definition->getArgument(2));
38233822
$this->assertInstanceOf(Reference::class, $definition->getArgument(3));
38243823
$this->assertSame('ai.platform.model_catalog.elevenlabs', (string) $definition->getArgument(3));
38253824
$this->assertNull($definition->getArgument(4));
3826-
$this->assertNull($definition->getArgument(5));
3827-
$this->assertInstanceOf(Reference::class, $definition->getArgument(6));
3828-
$this->assertSame('event_dispatcher', (string) $definition->getArgument(6));
3825+
$this->assertInstanceOf(Reference::class, $definition->getArgument(5));
3826+
$this->assertSame('event_dispatcher', (string) $definition->getArgument(5));
38293827

38303828
$this->assertTrue($definition->hasTag('proxy'));
38313829
$this->assertSame([['interface' => PlatformInterface::class]], $definition->getTag('proxy'));
@@ -3856,17 +3854,16 @@ public function testElevenLabsPlatformWithCustomHttpClientCanBeRegistered()
38563854
$this->assertTrue($definition->isLazy());
38573855
$this->assertSame([PlatformFactory::class, 'create'], $definition->getFactory());
38583856

3859-
$this->assertCount(7, $definition->getArguments());
3857+
$this->assertCount(6, $definition->getArguments());
38603858
$this->assertSame('foo', $definition->getArgument(0));
38613859
$this->assertSame('https://api.elevenlabs.io/v1', $definition->getArgument(1));
38623860
$this->assertInstanceOf(Reference::class, $definition->getArgument(2));
38633861
$this->assertSame('foo', (string) $definition->getArgument(2));
38643862
$this->assertInstanceOf(Reference::class, $definition->getArgument(3));
38653863
$this->assertSame('ai.platform.model_catalog.elevenlabs', (string) $definition->getArgument(3));
38663864
$this->assertNull($definition->getArgument(4));
3867-
$this->assertNull($definition->getArgument(5));
3868-
$this->assertInstanceOf(Reference::class, $definition->getArgument(6));
3869-
$this->assertSame('event_dispatcher', (string) $definition->getArgument(6));
3865+
$this->assertInstanceOf(Reference::class, $definition->getArgument(5));
3866+
$this->assertSame('event_dispatcher', (string) $definition->getArgument(5));
38703867

38713868
$this->assertTrue($definition->hasTag('proxy'));
38723869
$this->assertSame([['interface' => PlatformInterface::class]], $definition->getTag('proxy'));
@@ -3931,7 +3928,7 @@ public function testOpenAiPlatformWithDefaultRegion()
39313928
$definition = $container->getDefinition('ai.platform.openai');
39323929
$arguments = $definition->getArguments();
39333930

3934-
$this->assertCount(7, $arguments);
3931+
$this->assertCount(6, $arguments);
39353932
$this->assertSame('sk-test-key', $arguments[0]);
39363933
$this->assertNull($arguments[4]); // region should be null by default
39373934
}
@@ -3957,7 +3954,7 @@ public function testOpenAiPlatformWithRegion(?string $region)
39573954
$definition = $container->getDefinition('ai.platform.openai');
39583955
$arguments = $definition->getArguments();
39593956

3960-
$this->assertCount(7, $arguments);
3957+
$this->assertCount(6, $arguments);
39613958
$this->assertSame('sk-test-key', $arguments[0]);
39623959
$this->assertSame($region, $arguments[4]);
39633960
}
@@ -3996,7 +3993,7 @@ public function testPerplexityPlatformConfiguration()
39963993
$definition = $container->getDefinition('ai.platform.perplexity');
39973994
$arguments = $definition->getArguments();
39983995

3999-
$this->assertCount(6, $arguments);
3996+
$this->assertCount(5, $arguments);
40003997
$this->assertSame('pplx-test-key', $arguments[0]);
40013998
$this->assertInstanceOf(Reference::class, $arguments[1]);
40023999
$this->assertSame('http_client', (string) $arguments[1]);
@@ -6858,12 +6855,13 @@ public function testSpeechProviderListenerCannotBeRegisteredWithoutSpeechProvide
68586855
public function testElevenLabsSpeechProviderListenerCannotBeRegisteredWithoutPlaform()
68596856
{
68606857
$this->expectException(PlatformRuntimeException::class);
6861-
$this->expectExceptionMessage('The ElevenLabs platform cannot be found.');
6858+
$this->expectExceptionMessage('The "elevenlabs" platform cannot be found.');
68626859
$this->expectExceptionCode(0);
68636860
$this->buildContainer([
68646861
'ai' => [
68656862
'speech' => [
68666863
'elevenlabs' => [
6864+
'platform' => 'ai.platform.elevenlabs',
68676865
'tts_model' => 'foo',
68686866
'tts_voice' => 'bar',
68696867
'tts_extra_options' => [
@@ -6890,6 +6888,7 @@ public function testElevenLabsSpeechProviderListenerIsRegisteredWithSpeechProvid
68906888
],
68916889
'speech' => [
68926890
'elevenlabs' => [
6891+
'platform' => 'ai.platform.elevenlabs',
68936892
'tts_model' => 'foo',
68946893
'tts_voice' => 'bar',
68956894
'tts_extra_options' => [
@@ -6908,22 +6907,40 @@ public function testElevenLabsSpeechProviderListenerIsRegisteredWithSpeechProvid
69086907
$this->assertTrue($container->hasDefinition('ai.speech.elevenlabs.configuration'));
69096908

69106909
$platformDefinition = $container->getDefinition('ai.platform.elevenlabs');
6911-
$this->assertCount(7, $platformDefinition->getArguments());
6910+
$this->assertCount(6, $platformDefinition->getArguments());
69126911
$this->assertInstanceOf(Reference::class, $platformDefinition->getArgument(5));
6913-
$this->assertSame('ai.speech.elevenlabs.configuration', (string) $platformDefinition->getArgument(5));
6912+
$this->assertSame('event_dispatcher', (string) $platformDefinition->getArgument(5));
6913+
6914+
$speechAwarePlatformDefinition = $container->getDefinition('ai.speech.elevenlabs.platform');
6915+
$this->assertTrue($speechAwarePlatformDefinition->isLazy());
6916+
$this->assertCount(2, $speechAwarePlatformDefinition->getArguments());
6917+
$this->assertInstanceOf(Reference::class, $speechAwarePlatformDefinition->getArgument(0));
6918+
$this->assertSame('.inner', (string) $speechAwarePlatformDefinition->getArgument(0));
6919+
$this->assertInstanceOf(Reference::class, $speechAwarePlatformDefinition->getArgument(1));
6920+
$this->assertSame('ai.speech.elevenlabs.configuration', (string) $speechAwarePlatformDefinition->getArgument(1));
6921+
6922+
$this->assertTrue($speechAwarePlatformDefinition->hasTag('proxy'));
6923+
$this->assertSame([
6924+
['interface' => PlatformInterface::class],
6925+
['interface' => SpeechAwarePlatformInterface::class],
6926+
], $speechAwarePlatformDefinition->getTag('proxy'));
6927+
$this->assertTrue($speechAwarePlatformDefinition->hasTag('ai.speech_aware_platform'));
6928+
$this->assertSame([
6929+
['name' => 'elevenlabs'],
6930+
], $speechAwarePlatformDefinition->getTag('ai.speech_aware_platform'));
69146931

69156932
$providerDefinition = $container->getDefinition('ai.speech_provider.elevenlabs');
69166933
$this->assertTrue($providerDefinition->isLazy());
69176934
$this->assertCount(1, $providerDefinition->getArguments());
6918-
$this->assertSame('ai.platform.elevenlabs', (string) $providerDefinition->getArgument(0));
6935+
$this->assertSame('ai.speech.elevenlabs.platform', (string) $providerDefinition->getArgument(0));
69196936

69206937
$this->assertSame([['interface' => SpeechProviderInterface::class]], $providerDefinition->getTag('proxy'));
69216938
$this->assertTrue($providerDefinition->hasTag('ai.speech_provider'));
69226939

69236940
$listenerDefinition = $container->getDefinition('ai.speech_listener.elevenlabs');
69246941
$this->assertTrue($listenerDefinition->isLazy());
69256942
$this->assertCount(1, $listenerDefinition->getArguments());
6926-
$this->assertSame('ai.platform.elevenlabs', (string) $listenerDefinition->getArgument(0));
6943+
$this->assertSame('ai.speech.elevenlabs.platform', (string) $listenerDefinition->getArgument(0));
69276944

69286945
$this->assertSame([['interface' => SpeechListenerInterface::class]], $listenerDefinition->getTag('proxy'));
69296946
$this->assertTrue($listenerDefinition->hasTag('ai.speech_listener'));
@@ -7475,6 +7492,7 @@ private function getFullConfig(): array
74757492
],
74767493
'speech' => [
74777494
'elevenlabs' => [
7495+
'platform' => 'ai.platform.elevenlabs',
74787496
'tts_model' => 'foo',
74797497
'tts_voice' => 'bar',
74807498
'tts_extra_options' => [

0 commit comments

Comments
 (0)