Skip to content

Commit b3e83d0

Browse files
authored
chore: lib v0.24 compatibility (#101)
1 parent 0adf120 commit b3e83d0

File tree

5 files changed

+44
-18
lines changed

5 files changed

+44
-18
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
],
1616
"require": {
1717
"php": ">=8.2",
18-
"php-llm/llm-chain": "^0.23",
18+
"php-llm/llm-chain": "^0.24",
1919
"symfony/config": "^6.4 || ^7.0",
2020
"symfony/dependency-injection": "^6.4 || ^7.0",
2121
"symfony/framework-bundle": "^6.4 || ^7.0",
2222
"symfony/string": "^6.4 || ^7.0"
2323
},
2424
"require-dev": {
25-
"php-cs-fixer/shim": "^3.69",
25+
"php-cs-fixer/shim": "^3.78",
2626
"phpstan/phpstan": "^2.1",
2727
"phpunit/phpunit": "^11.5",
2828
"rector/rector": "^2.0"

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function getConfigTreeBuilder(): TreeBuilder
182182
->end()
183183
->end()
184184
->end()
185-
->arrayNode('embedder')
185+
->arrayNode('indexer')
186186
->normalizeKeys(false)
187187
->useAttributeAsKey('name')
188188
->arrayPrototype()

src/DependencyInjection/LlmChainExtension.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
use PhpLlm\LlmChain\Store\Bridge\ChromaDB\Store as ChromaDBStore;
4040
use PhpLlm\LlmChain\Store\Bridge\MongoDB\Store as MongoDBStore;
4141
use PhpLlm\LlmChain\Store\Bridge\Pinecone\Store as PineconeStore;
42-
use PhpLlm\LlmChain\Store\Embedder;
42+
use PhpLlm\LlmChain\Store\Document\Vectorizer;
43+
use PhpLlm\LlmChain\Store\Indexer;
4344
use PhpLlm\LlmChain\Store\StoreInterface;
4445
use PhpLlm\LlmChain\Store\VectorStoreInterface;
4546
use PhpLlm\LlmChainBundle\Profiler\DataCollector;
@@ -98,11 +99,11 @@ public function load(array $configs, ContainerBuilder $container): void
9899
$container->setAlias(StoreInterface::class, reset($stores));
99100
}
100101

101-
foreach ($config['embedder'] as $embedderName => $embedder) {
102-
$this->processEmbedderConfig($embedderName, $embedder, $container);
102+
foreach ($config['indexer'] as $indexerName => $indexer) {
103+
$this->processIndexerConfig($indexerName, $indexer, $container);
103104
}
104-
if (1 === count($config['embedder']) && isset($embedderName)) {
105-
$container->setAlias(Embedder::class, 'llm_chain.embedder.'.$embedderName);
105+
if (1 === count($config['indexer']) && isset($indexerName)) {
106+
$container->setAlias(Indexer::class, 'llm_chain.indexer.'.$indexerName);
106107
}
107108

108109
$container->registerAttributeForAutoconfiguration(AsTool::class, static function (ChildDefinition $definition, AsTool $attribute): void {
@@ -455,7 +456,7 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
455456
/**
456457
* @param array<string, mixed> $config
457458
*/
458-
private function processEmbedderConfig(int|string $name, array $config, ContainerBuilder $container): void
459+
private function processIndexerConfig(int|string $name, array $config, ContainerBuilder $container): void
459460
{
460461
['name' => $modelName, 'version' => $version, 'options' => $options] = $config['model'];
461462

@@ -472,14 +473,19 @@ private function processEmbedderConfig(int|string $name, array $config, Containe
472473
$modelDefinition->setArgument('$options', $options);
473474
}
474475
$modelDefinition->addTag('llm_chain.model.embeddings_model');
475-
$container->setDefinition('llm_chain.embedder.'.$name.'.model', $modelDefinition);
476+
$container->setDefinition('llm_chain.indexer.'.$name.'.model', $modelDefinition);
476477

477-
$definition = new Definition(Embedder::class, [
478-
'$model' => new Reference('llm_chain.embedder.'.$name.'.model'),
478+
$vectorizerDefinition = new Definition(Vectorizer::class, [
479479
'$platform' => new Reference($config['platform']),
480+
'$model' => new Reference('llm_chain.indexer.'.$name.'.model'),
481+
]);
482+
$container->setDefinition('llm_chain.indexer.'.$name.'.vectorizer', $vectorizerDefinition);
483+
484+
$definition = new Definition(Indexer::class, [
485+
'$vectorizer' => new Reference('llm_chain.indexer.'.$name.'.vectorizer'),
480486
'$store' => new Reference($config['store']),
481487
]);
482488

483-
$container->setDefinition('llm_chain.embedder.'.$name, $definition);
489+
$container->setDefinition('llm_chain.indexer.'.$name, $definition);
484490
}
485491
}

src/Profiler/DataCollector.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpLlm\LlmChainBundle\Profiler;
66

77
use PhpLlm\LlmChain\Chain\Toolbox\ToolboxInterface;
8+
use PhpLlm\LlmChain\Platform\Model;
89
use PhpLlm\LlmChain\Platform\Tool\Tool;
910
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
1011
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
@@ -46,7 +47,7 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
4647
{
4748
$this->data = [
4849
'tools' => $this->defaultToolBox->getTools(),
49-
'platform_calls' => array_merge(...array_map(fn (TraceablePlatform $platform) => $platform->calls, $this->platforms)),
50+
'platform_calls' => array_merge(...array_map($this->awaitCallResults(...), $this->platforms)),
5051
'tool_calls' => array_merge(...array_map(fn (TraceableToolbox $toolbox) => $toolbox->calls, $this->toolboxes)),
5152
];
5253
}
@@ -79,4 +80,23 @@ public function getToolCalls(): array
7980
{
8081
return $this->data['tool_calls'] ?? [];
8182
}
83+
84+
/**
85+
* @return array{
86+
* model: Model,
87+
* input: array<mixed>|string|object,
88+
* options: array<string, mixed>,
89+
* response: string|iterable<mixed>|object|null
90+
* }[]
91+
*/
92+
private function awaitCallResults(TraceablePlatform $platform): array
93+
{
94+
$calls = $platform->calls;
95+
foreach ($calls as $key => $call) {
96+
$call['response'] = $call['response']->await()->getContent();
97+
$calls[$key] = $call;
98+
}
99+
100+
return $calls;
101+
}
82102
}

src/Profiler/TraceablePlatform.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
use PhpLlm\LlmChain\Platform\Message\Content\File;
88
use PhpLlm\LlmChain\Platform\Model;
99
use PhpLlm\LlmChain\Platform\PlatformInterface;
10-
use PhpLlm\LlmChain\Platform\Response\ResponseInterface;
10+
use PhpLlm\LlmChain\Platform\Response\ResponsePromise;
1111

1212
/**
1313
* @phpstan-type PlatformCallData array{
1414
* model: Model,
1515
* input: array<mixed>|string|object,
1616
* options: array<string, mixed>,
17-
* response: ResponseInterface,
17+
* response: ResponsePromise,
1818
* }
1919
*/
2020
final class TraceablePlatform implements PlatformInterface
@@ -29,7 +29,7 @@ public function __construct(
2929
) {
3030
}
3131

32-
public function request(Model $model, array|string|object $input, array $options = []): ResponseInterface
32+
public function request(Model $model, array|string|object $input, array $options = []): ResponsePromise
3333
{
3434
$response = $this->platform->request($model, $input, $options);
3535

@@ -41,7 +41,7 @@ public function request(Model $model, array|string|object $input, array $options
4141
'model' => $model,
4242
'input' => is_object($input) ? clone $input : $input,
4343
'options' => $options,
44-
'response' => $response->getContent(),
44+
'response' => $response,
4545
];
4646

4747
return $response;

0 commit comments

Comments
 (0)