Skip to content

Commit be85dda

Browse files
committed
ref
1 parent 1963409 commit be85dda

File tree

7 files changed

+79
-14
lines changed

7 files changed

+79
-14
lines changed

src/platform/src/Bridge/ElevenLabs/ElevenLabsSpeechListener.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\AI\Platform\Capability;
1515
use Symfony\AI\Platform\Message\Content\Text;
1616
use Symfony\AI\Platform\Message\MessageBag;
17-
use Symfony\AI\Platform\Model;
1817
use Symfony\AI\Platform\PlatformInterface;
1918
use Symfony\AI\Platform\Speech\SpeechListenerInterface;
2019

@@ -39,8 +38,16 @@ public function listen(object|array|string $input, array $options): Text
3938
return new Text($result->asText());
4039
}
4140

42-
public function support(Model $model, object|array|string $input, array $options): bool
41+
public function support(object|array|string $input, array $options): bool
4342
{
43+
$speechConfiguration = $this->platform->getSpeechConfiguration();
44+
45+
if (null === $speechConfiguration) {
46+
return false;
47+
}
48+
49+
$model = $this->platform->getModelCatalog()->getModel($speechConfiguration->sttModel);
50+
4451
return \in_array(Capability::SPEECH_TO_TEXT, $model->getCapabilities(), true);
4552
}
4653
}

src/platform/src/Bridge/ElevenLabs/ElevenLabsSpeechProvider.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\AI\Platform\Bridge\ElevenLabs;
1313

1414
use Symfony\AI\Platform\Capability;
15-
use Symfony\AI\Platform\Model;
1615
use Symfony\AI\Platform\PlatformInterface;
1716
use Symfony\AI\Platform\Result\DeferredResult;
1817
use Symfony\AI\Platform\Speech\Speech;
@@ -43,8 +42,16 @@ public function generate(DeferredResult $result, array $options): Speech
4342
return new Speech($payload, $speechResult, 'eleven_labs');
4443
}
4544

46-
public function support(Model $model, DeferredResult $result, array $options): bool
45+
public function support(DeferredResult $result, array $options): bool
4746
{
47+
$speechConfiguration = $this->platform->getSpeechConfiguration();
48+
49+
if (null === $speechConfiguration) {
50+
return false;
51+
}
52+
53+
$model = $this->platform->getModelCatalog()->getModel($speechConfiguration->ttsModel);
54+
4855
return \in_array(Capability::TEXT_TO_SPEECH, $model->getCapabilities(), true);
4956
}
5057
}

src/platform/src/Speech/SpeechListenerInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\AI\Platform\Speech;
1313

1414
use Symfony\AI\Platform\Message\Content\Text;
15-
use Symfony\AI\Platform\Model;
1615

1716
/**
1817
* @author Guillaume Loulier <personal@guillaumeloulier.fr>
@@ -29,5 +28,5 @@ public function listen(array|string|object $input, array $options): Text;
2928
* @param array<mixed>|string|object $input
3029
* @param array<string, mixed> $options
3130
*/
32-
public function support(Model $model, array|string|object $input, array $options): bool;
31+
public function support(array|string|object $input, array $options): bool;
3332
}

src/platform/src/Speech/SpeechProviderInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\AI\Platform\Speech;
1313

14-
use Symfony\AI\Platform\Model;
1514
use Symfony\AI\Platform\Result\DeferredResult;
1615

1716
/**
@@ -27,5 +26,5 @@ public function generate(DeferredResult $result, array $options): Speech;
2726
/**
2827
* @param array<string, mixed> $options
2928
*/
30-
public function support(Model $model, DeferredResult $result, array $options): bool;
29+
public function support(DeferredResult $result, array $options): bool;
3130
}

src/platform/src/Speech/SpeechProviderListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function onInvocation(InvocationEvent $event): void
4646
$options = $event->getOptions();
4747

4848
foreach ($this->speechListeners as $speechListener) {
49-
if (!$speechListener->support($event->getModel(), $input, $options)) {
49+
if (!$speechListener->support($input, $options)) {
5050
continue;
5151
}
5252

@@ -70,7 +70,7 @@ public function onResult(ResultEvent $event): void
7070
$options = $event->getOptions();
7171

7272
foreach ($this->speechProviders as $speechProvider) {
73-
if (!$speechProvider->support($event->getModel(), $deferredResult, $options)) {
73+
if (!$speechProvider->support($deferredResult, $options)) {
7474
continue;
7575
}
7676

src/platform/tests/Bridge/ElevenLabs/ElevenLabsSpeechListenerTest.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\AI\Platform\Message\Content\Text;
2020
use Symfony\AI\Platform\Message\Message;
2121
use Symfony\AI\Platform\Message\MessageBag;
22+
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
2223
use Symfony\AI\Platform\PlatformInterface;
2324
use Symfony\AI\Platform\Result\DeferredResult;
2425
use Symfony\AI\Platform\Result\RawResultInterface;
@@ -28,28 +29,52 @@
2829

2930
final class ElevenLabsSpeechListenerTest extends TestCase
3031
{
32+
public function testListenerCannotSupportOnMissingSpeechConfiguration()
33+
{
34+
$platform = $this->createMock(PlatformInterface::class);
35+
$platform->expects($this->once())->method('getSpeechConfiguration')->willReturn(null);
36+
37+
$speechListener = new ElevenLabsSpeechListener($platform);
38+
39+
$this->assertFalse($speechListener->support([], []));
40+
}
41+
3142
public function testListenerCannotSupportOnWrongModel()
3243
{
44+
$speechConfiguration = new SpeechConfiguration(sttModel: 'foo');
45+
3346
$model = new ElevenLabs('foo');
3447

48+
$modelCatalog = $this->createMock(ModelCatalogInterface::class);
49+
$modelCatalog->expects($this->once())->method('getModel')->willReturn($model);
50+
3551
$platform = $this->createMock(PlatformInterface::class);
52+
$platform->expects($this->once())->method('getSpeechConfiguration')->willReturn($speechConfiguration);
53+
$platform->expects($this->once())->method('getModelCatalog')->willReturn($modelCatalog);
3654

3755
$speechListener = new ElevenLabsSpeechListener($platform);
3856

39-
$this->assertFalse($speechListener->support($model, [], []));
57+
$this->assertFalse($speechListener->support([], []));
4058
}
4159

4260
public function testListenerCanSupportOnValidModel()
4361
{
62+
$speechConfiguration = new SpeechConfiguration(sttModel: 'foo');
63+
4464
$model = new ElevenLabs('foo', [
4565
Capability::SPEECH_TO_TEXT,
4666
]);
4767

68+
$modelCatalog = $this->createMock(ModelCatalogInterface::class);
69+
$modelCatalog->expects($this->once())->method('getModel')->willReturn($model);
70+
4871
$platform = $this->createMock(PlatformInterface::class);
72+
$platform->expects($this->once())->method('getSpeechConfiguration')->willReturn($speechConfiguration);
73+
$platform->expects($this->once())->method('getModelCatalog')->willReturn($modelCatalog);
4974

5075
$speechListener = new ElevenLabsSpeechListener($platform);
5176

52-
$this->assertTrue($speechListener->support($model, [], []));
77+
$this->assertTrue($speechListener->support([], []));
5378
}
5479

5580
public function testListenerCanListenOnArrayInput()

src/platform/tests/Bridge/ElevenLabs/ElevenLabsSpeechProviderTest.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\AI\Platform\Bridge\ElevenLabs\ElevenLabs;
1616
use Symfony\AI\Platform\Bridge\ElevenLabs\ElevenLabsSpeechProvider;
1717
use Symfony\AI\Platform\Capability;
18+
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
1819
use Symfony\AI\Platform\PlatformInterface;
1920
use Symfony\AI\Platform\Result\DeferredResult;
2021
use Symfony\AI\Platform\Result\RawResultInterface;
@@ -24,24 +25,46 @@
2425

2526
final class ElevenLabsSpeechProviderTest extends TestCase
2627
{
28+
public function testProviderCannotSupportOnMissingSpeechConfiguration()
29+
{
30+
$rawResult = $this->createMock(RawResultInterface::class);
31+
$resultConverter = $this->createMock(ResultConverterInterface::class);
32+
33+
$deferredResult = new DeferredResult($resultConverter, $rawResult);
34+
35+
$platform = $this->createMock(PlatformInterface::class);
36+
$platform->expects($this->once())->method('getSpeechConfiguration')->willReturn(null);
37+
38+
$speechListener = new ElevenLabsSpeechProvider($platform);
39+
40+
$this->assertFalse($speechListener->support($deferredResult, []));
41+
}
42+
2743
public function testProviderCannotSupportOnWrongModel()
2844
{
45+
$speechConfiguration = new SpeechConfiguration(ttsModel: 'foo');
2946
$model = new ElevenLabs('foo');
3047

3148
$rawResult = $this->createMock(RawResultInterface::class);
3249
$resultConverter = $this->createMock(ResultConverterInterface::class);
3350

3451
$deferredResult = new DeferredResult($resultConverter, $rawResult);
3552

53+
$modelCatalog = $this->createMock(ModelCatalogInterface::class);
54+
$modelCatalog->expects($this->once())->method('getModel')->willReturn($model);
55+
3656
$platform = $this->createMock(PlatformInterface::class);
57+
$platform->expects($this->once())->method('getSpeechConfiguration')->willReturn($speechConfiguration);
58+
$platform->expects($this->once())->method('getModelCatalog')->willReturn($modelCatalog);
3759

3860
$speechListener = new ElevenLabsSpeechProvider($platform);
3961

40-
$this->assertFalse($speechListener->support($model, $deferredResult, []));
62+
$this->assertFalse($speechListener->support($deferredResult, []));
4163
}
4264

4365
public function testProviderCanSupportOnValidModel()
4466
{
67+
$speechConfiguration = new SpeechConfiguration(ttsModel: 'foo');
4568
$model = new ElevenLabs('foo', [
4669
Capability::TEXT_TO_SPEECH,
4770
]);
@@ -51,11 +74,16 @@ public function testProviderCanSupportOnValidModel()
5174

5275
$deferredResult = new DeferredResult($resultConverter, $rawResult);
5376

77+
$modelCatalog = $this->createMock(ModelCatalogInterface::class);
78+
$modelCatalog->expects($this->once())->method('getModel')->willReturn($model);
79+
5480
$platform = $this->createMock(PlatformInterface::class);
81+
$platform->expects($this->once())->method('getSpeechConfiguration')->willReturn($speechConfiguration);
82+
$platform->expects($this->once())->method('getModelCatalog')->willReturn($modelCatalog);
5583

5684
$speechListener = new ElevenLabsSpeechProvider($platform);
5785

58-
$this->assertTrue($speechListener->support($model, $deferredResult, []));
86+
$this->assertTrue($speechListener->support($deferredResult, []));
5987
}
6088

6189
public function testProviderCanGenerate()

0 commit comments

Comments
 (0)