Skip to content

Commit 3a04966

Browse files
committed
chore: lib v0.24 compatibility (#101)
1 parent 7e8b3b4 commit 3a04966

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/ai-bundle/src/DependencyInjection/AIExtension.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
use Symfony\AI\Store\Bridge\ChromaDB\Store as ChromaDBStore;
5050
use Symfony\AI\Store\Bridge\MongoDB\Store as MongoDBStore;
5151
use Symfony\AI\Store\Bridge\Pinecone\Store as PineconeStore;
52+
use Symfony\AI\Store\Document\Vectorizer;
5253
use Symfony\AI\Store\Indexer;
5354
use Symfony\AI\Store\StoreInterface;
5455
use Symfony\AI\Store\VectorStoreInterface;
@@ -484,9 +485,14 @@ private function processIndexerConfig(int|string $name, array $config, Container
484485
$modelDefinition->addTag('symfony_ai.model.embeddings_model');
485486
$container->setDefinition('symfony_ai.indexer.'.$name.'.model', $modelDefinition);
486487

487-
$definition = new Definition(Indexer::class, [
488-
'$model' => new Reference('symfony_ai.indexer.'.$name.'.model'),
488+
$vectorizerDefinition = new Definition(Vectorizer::class, [
489489
'$platform' => new Reference($config['platform']),
490+
'$model' => new Reference('symfony_ai.indexer.'.$name.'.model'),
491+
]);
492+
$container->setDefinition('symfony_ai.indexer.'.$name.'.vectorizer', $vectorizerDefinition);
493+
494+
$definition = new Definition(Indexer::class, [
495+
'$vectorizer' => new Reference('symfony_ai.indexer.'.$name.'.vectorizer'),
490496
'$store' => new Reference($config['store']),
491497
]);
492498

src/ai-bundle/src/Profiler/DataCollector.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\AI\AIBundle\Profiler;
1313

1414
use Symfony\AI\Agent\Toolbox\ToolboxInterface;
15+
use Symfony\AI\Platform\Model;
1516
use Symfony\AI\Platform\Tool\Tool;
1617
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
1718
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
@@ -55,7 +56,7 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
5556
{
5657
$this->data = [
5758
'tools' => $this->defaultToolBox->getTools(),
58-
'platform_calls' => array_merge(...array_map(fn (TraceablePlatform $platform) => $platform->calls, $this->platforms)),
59+
'platform_calls' => array_merge(...array_map($this->awaitCallResults(...), $this->platforms)),
5960
'tool_calls' => array_merge(...array_map(fn (TraceableToolbox $toolbox) => $toolbox->calls, $this->toolboxes)),
6061
];
6162
}
@@ -88,4 +89,23 @@ public function getToolCalls(): array
8889
{
8990
return $this->data['tool_calls'] ?? [];
9091
}
92+
93+
/**
94+
* @return array{
95+
* model: Model,
96+
* input: array<mixed>|string|object,
97+
* options: array<string, mixed>,
98+
* response: string|iterable<mixed>|object|null
99+
* }[]
100+
*/
101+
private function awaitCallResults(TraceablePlatform $platform): array
102+
{
103+
$calls = $platform->calls;
104+
foreach ($calls as $key => $call) {
105+
$call['response'] = $call['response']->await()->getContent();
106+
$calls[$key] = $call;
107+
}
108+
109+
return $calls;
110+
}
91111
}

src/ai-bundle/src/Profiler/TraceablePlatform.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\AI\Platform\Message\Content\File;
1515
use Symfony\AI\Platform\Model;
1616
use Symfony\AI\Platform\PlatformInterface;
17-
use Symfony\AI\Platform\Response\ResponseInterface;
17+
use Symfony\AI\Platform\Response\ResponsePromise;
1818

1919
/**
2020
* @author Christopher Hertel <mail@christopher-hertel.de>
@@ -23,7 +23,7 @@
2323
* model: Model,
2424
* input: array<mixed>|string|object,
2525
* options: array<string, mixed>,
26-
* response: ResponseInterface,
26+
* response: ResponsePromise,
2727
* }
2828
*/
2929
final class TraceablePlatform implements PlatformInterface
@@ -38,7 +38,7 @@ public function __construct(
3838
) {
3939
}
4040

41-
public function request(Model $model, array|string|object $input, array $options = []): ResponseInterface
41+
public function request(Model $model, array|string|object $input, array $options = []): ResponsePromise
4242
{
4343
$response = $this->platform->request($model, $input, $options);
4444

@@ -50,7 +50,7 @@ public function request(Model $model, array|string|object $input, array $options
5050
'model' => $model,
5151
'input' => \is_object($input) ? clone $input : $input,
5252
'options' => $options,
53-
'response' => $response->getContent(),
53+
'response' => $response,
5454
];
5555

5656
return $response;

0 commit comments

Comments
 (0)