Skip to content

Commit bd588cf

Browse files
committed
feat(agent): voice provider
1 parent 8fc14a0 commit bd588cf

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

src/agent/src/Agent.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,28 @@
3333
*/
3434
private array $outputProcessors;
3535

36+
/**
37+
* @var VoiceProviderInterface[]
38+
*/
39+
private array $voiceProviders;
40+
3641
/**
3742
* @param InputProcessorInterface[] $inputProcessors
3843
* @param OutputProcessorInterface[] $outputProcessors
44+
* @param VoiceProviderInterface[] $voiceProviders
3945
* @param non-empty-string $model
4046
*/
4147
public function __construct(
4248
private PlatformInterface $platform,
4349
private string $model,
4450
iterable $inputProcessors = [],
4551
iterable $outputProcessors = [],
52+
iterable $voiceProviders = [],
4653
private string $name = 'agent',
4754
) {
4855
$this->inputProcessors = $this->initializeProcessors($inputProcessors, InputProcessorInterface::class);
4956
$this->outputProcessors = $this->initializeProcessors($outputProcessors, OutputProcessorInterface::class);
57+
$this->voiceProviders = $this->initializeVoiceProviders($voiceProviders);
5058
}
5159

5260
public function getModel(): string
@@ -79,6 +87,7 @@ public function call(MessageBag $messages, array $options = []): ResultInterface
7987

8088
$output = new Output($model, $result, $messages, $options);
8189
array_map(fn (OutputProcessorInterface $processor) => $processor->processOutput($output), $this->outputProcessors);
90+
array_map(static fn (VoiceProviderInterface $provider) => $provider->addVoice($output), $this->voiceProviders);
8291

8392
return $output->getResult();
8493
}
@@ -103,4 +112,20 @@ private function initializeProcessors(iterable $processors, string $interface):
103112

104113
return $processors instanceof \Traversable ? iterator_to_array($processors) : $processors;
105114
}
115+
116+
/**
117+
* @param VoiceProviderInterface[] $providers
118+
*
119+
* @return InputProcessorInterface[]|OutputProcessorInterface[]
120+
*/
121+
private function initializeVoiceProviders(iterable $providers): array
122+
{
123+
foreach ($providers as $provider) {
124+
if (!$provider instanceof VoiceProviderInterface) {
125+
throw new InvalidArgumentException(\sprintf('Voice provider "%s" must implement "%s".', $provider::class, VoiceProviderInterface::class));
126+
}
127+
}
128+
129+
return $providers instanceof \Traversable ? iterator_to_array($providers) : $providers;
130+
}
106131
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\AI\Agent;
13+
14+
/**
15+
* @author Guillaume Loulier <[email protected]>
16+
*/
17+
interface VoiceProviderInterface
18+
{
19+
public function addVoice(Output $output): void;
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\AI\Platform\Result;
13+
14+
/**
15+
* @author Guillaume Loulier <[email protected]>
16+
*/
17+
trait VoiceAwareTrait
18+
{
19+
20+
}

0 commit comments

Comments
 (0)