Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 6c48c4f

Browse files
authored
chore: support LLM Chain 0.22 (#85)
1 parent e8f7809 commit 6c48c4f

File tree

9 files changed

+62
-75
lines changed

9 files changed

+62
-75
lines changed

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,3 @@ ci-lowest: deps-low rector cs phpstan tests
3535

3636
ci-dev: deps-dev rector cs phpstan tests
3737
git restore composer.json
38-
39-
coverage:
40-
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html=coverage

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"require": {
1717
"php": ">=8.2",
18-
"php-llm/llm-chain": "^0.21",
18+
"php-llm/llm-chain": "^0.22",
1919
"symfony/config": "^6.4 || ^7.0",
2020
"symfony/dependency-injection": "^6.4 || ^7.0",
2121
"symfony/framework-bundle": "^6.4 || ^7.0",

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PhpLlm\LlmChainBundle\DependencyInjection;
66

7-
use PhpLlm\LlmChain\PlatformInterface;
7+
use PhpLlm\LlmChain\Platform\PlatformInterface;
88
use PhpLlm\LlmChain\Store\StoreInterface;
99
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1010
use Symfony\Component\Config\Definition\ConfigurationInterface;

src/DependencyInjection/LlmChainExtension.php

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,38 @@
44

55
namespace PhpLlm\LlmChainBundle\DependencyInjection;
66

7-
use PhpLlm\LlmChain\Bridge\Anthropic\Claude;
8-
use PhpLlm\LlmChain\Bridge\Anthropic\PlatformFactory as AnthropicPlatformFactory;
9-
use PhpLlm\LlmChain\Bridge\Azure\OpenAI\PlatformFactory as AzureOpenAIPlatformFactory;
10-
use PhpLlm\LlmChain\Bridge\Azure\Store\SearchStore as AzureSearchStore;
11-
use PhpLlm\LlmChain\Bridge\ChromaDB\Store as ChromaDBStore;
12-
use PhpLlm\LlmChain\Bridge\Google\Gemini;
13-
use PhpLlm\LlmChain\Bridge\Google\PlatformFactory as GooglePlatformFactory;
14-
use PhpLlm\LlmChain\Bridge\Meta\Llama;
15-
use PhpLlm\LlmChain\Bridge\MongoDB\Store as MongoDBStore;
16-
use PhpLlm\LlmChain\Bridge\OpenAI\Embeddings;
17-
use PhpLlm\LlmChain\Bridge\OpenAI\GPT;
18-
use PhpLlm\LlmChain\Bridge\OpenAI\PlatformFactory as OpenAIPlatformFactory;
19-
use PhpLlm\LlmChain\Bridge\Pinecone\Store as PineconeStore;
20-
use PhpLlm\LlmChain\Bridge\Voyage\Voyage;
21-
use PhpLlm\LlmChain\Chain;
22-
use PhpLlm\LlmChain\Chain\InputProcessor;
7+
use PhpLlm\LlmChain\Chain\Chain;
8+
use PhpLlm\LlmChain\Chain\ChainInterface;
239
use PhpLlm\LlmChain\Chain\InputProcessor\SystemPromptInputProcessor;
24-
use PhpLlm\LlmChain\Chain\OutputProcessor;
10+
use PhpLlm\LlmChain\Chain\InputProcessorInterface;
11+
use PhpLlm\LlmChain\Chain\OutputProcessorInterface;
2512
use PhpLlm\LlmChain\Chain\StructuredOutput\ChainProcessor as StructureOutputProcessor;
2613
use PhpLlm\LlmChain\Chain\Toolbox\Attribute\AsTool;
2714
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor as ToolProcessor;
2815
use PhpLlm\LlmChain\Chain\Toolbox\FaultTolerantToolbox;
29-
use PhpLlm\LlmChain\Chain\Toolbox\MetadataFactory\ChainFactory;
30-
use PhpLlm\LlmChain\Chain\Toolbox\MetadataFactory\MemoryFactory;
31-
use PhpLlm\LlmChain\Chain\Toolbox\MetadataFactory\ReflectionFactory;
3216
use PhpLlm\LlmChain\Chain\Toolbox\Tool\Chain as ChainTool;
33-
use PhpLlm\LlmChain\ChainInterface;
34-
use PhpLlm\LlmChain\Embedder;
35-
use PhpLlm\LlmChain\Model\EmbeddingsModel;
36-
use PhpLlm\LlmChain\Model\LanguageModel;
37-
use PhpLlm\LlmChain\Platform;
38-
use PhpLlm\LlmChain\Platform\ModelClient;
39-
use PhpLlm\LlmChain\Platform\ResponseConverter;
40-
use PhpLlm\LlmChain\PlatformInterface;
17+
use PhpLlm\LlmChain\Chain\Toolbox\ToolFactory\ChainFactory;
18+
use PhpLlm\LlmChain\Chain\Toolbox\ToolFactory\MemoryToolFactory;
19+
use PhpLlm\LlmChain\Chain\Toolbox\ToolFactory\ReflectionToolFactory;
20+
use PhpLlm\LlmChain\Platform\Bridge\Anthropic\Claude;
21+
use PhpLlm\LlmChain\Platform\Bridge\Anthropic\PlatformFactory as AnthropicPlatformFactory;
22+
use PhpLlm\LlmChain\Platform\Bridge\Azure\OpenAI\PlatformFactory as AzureOpenAIPlatformFactory;
23+
use PhpLlm\LlmChain\Platform\Bridge\Google\Gemini;
24+
use PhpLlm\LlmChain\Platform\Bridge\Google\PlatformFactory as GooglePlatformFactory;
25+
use PhpLlm\LlmChain\Platform\Bridge\Meta\Llama;
26+
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\Embeddings;
27+
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\GPT;
28+
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\PlatformFactory as OpenAIPlatformFactory;
29+
use PhpLlm\LlmChain\Platform\Bridge\Voyage\Voyage;
30+
use PhpLlm\LlmChain\Platform\ModelClientInterface;
31+
use PhpLlm\LlmChain\Platform\Platform;
32+
use PhpLlm\LlmChain\Platform\PlatformInterface;
33+
use PhpLlm\LlmChain\Platform\ResponseConverterInterface;
34+
use PhpLlm\LlmChain\Store\Bridge\Azure\SearchStore as AzureSearchStore;
35+
use PhpLlm\LlmChain\Store\Bridge\ChromaDB\Store as ChromaDBStore;
36+
use PhpLlm\LlmChain\Store\Bridge\MongoDB\Store as MongoDBStore;
37+
use PhpLlm\LlmChain\Store\Bridge\Pinecone\Store as PineconeStore;
38+
use PhpLlm\LlmChain\Store\Embedder;
4139
use PhpLlm\LlmChain\Store\StoreInterface;
4240
use PhpLlm\LlmChain\Store\VectorStoreInterface;
4341
use PhpLlm\LlmChainBundle\Profiler\DataCollector;
@@ -86,10 +84,6 @@ public function load(array $configs, ContainerBuilder $container): void
8684
if (1 === count($config['chain']) && isset($chainName)) {
8785
$container->setAlias(ChainInterface::class, 'llm_chain.chain.'.$chainName);
8886
}
89-
$llms = array_keys($container->findTaggedServiceIds('llm_chain.model.language_model'));
90-
if (1 === count($llms)) {
91-
$container->setAlias(LanguageModel::class, reset($llms));
92-
}
9387

9488
foreach ($config['store'] ?? [] as $type => $store) {
9589
$this->processStoreConfig($type, $store, $container);
@@ -106,10 +100,6 @@ public function load(array $configs, ContainerBuilder $container): void
106100
if (1 === count($config['embedder']) && isset($embedderName)) {
107101
$container->setAlias(Embedder::class, 'llm_chain.embedder.'.$embedderName);
108102
}
109-
$embeddings = array_keys($container->findTaggedServiceIds('llm_chain.model.embeddings_model'));
110-
if (1 === count($embeddings)) {
111-
$container->setAlias(EmbeddingsModel::class, reset($embeddings));
112-
}
113103

114104
$container->registerAttributeForAutoconfiguration(AsTool::class, static function (ChildDefinition $definition, AsTool $attribute): void {
115105
$definition->addTag('llm_chain.tool', [
@@ -119,13 +109,13 @@ public function load(array $configs, ContainerBuilder $container): void
119109
]);
120110
});
121111

122-
$container->registerForAutoconfiguration(InputProcessor::class)
112+
$container->registerForAutoconfiguration(InputProcessorInterface::class)
123113
->addTag('llm_chain.chain.input_processor');
124-
$container->registerForAutoconfiguration(OutputProcessor::class)
114+
$container->registerForAutoconfiguration(OutputProcessorInterface::class)
125115
->addTag('llm_chain.chain.output_processor');
126-
$container->registerForAutoconfiguration(ModelClient::class)
116+
$container->registerForAutoconfiguration(ModelClientInterface::class)
127117
->addTag('llm_chain.platform.model_client');
128-
$container->registerForAutoconfiguration(ResponseConverter::class)
118+
$container->registerForAutoconfiguration(ResponseConverterInterface::class)
129119
->addTag('llm_chain.platform.response_converter');
130120

131121
if (false === $container->getParameter('kernel.debug')) {
@@ -253,10 +243,10 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
253243
if ($config['tools']['enabled']) {
254244
// Create specific toolbox and process if tools are explicitly defined
255245
if (0 !== count($config['tools']['services'])) {
256-
$memoryFactoryDefinition = new Definition(MemoryFactory::class);
246+
$memoryFactoryDefinition = new Definition(MemoryToolFactory::class);
257247
$container->setDefinition('llm_chain.toolbox.'.$name.'.memory_factory', $memoryFactoryDefinition);
258248
$chainFactoryDefinition = new Definition(ChainFactory::class, [
259-
'$factories' => [new Reference('llm_chain.toolbox.'.$name.'.memory_factory'), new Reference(ReflectionFactory::class)],
249+
'$factories' => [new Reference('llm_chain.toolbox.'.$name.'.memory_factory'), new Reference(ReflectionToolFactory::class)],
260250
]);
261251
$container->setDefinition('llm_chain.toolbox.'.$name.'.chain_factory', $chainFactoryDefinition);
262252

src/Profiler/DataCollector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace PhpLlm\LlmChainBundle\Profiler;
66

7-
use PhpLlm\LlmChain\Chain\Toolbox\Metadata;
87
use PhpLlm\LlmChain\Chain\Toolbox\ToolboxInterface;
8+
use PhpLlm\LlmChain\Platform\Tool\Tool;
99
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
1010
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
1111
use Symfony\Component\HttpFoundation\Request;
@@ -45,7 +45,7 @@ public function __construct(
4545
public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
4646
{
4747
$this->data = [
48-
'tools' => $this->defaultToolBox->getMap(),
48+
'tools' => $this->defaultToolBox->getTools(),
4949
'platform_calls' => array_merge(...array_map(fn (TraceablePlatform $platform) => $platform->calls, $this->platforms)),
5050
'tool_calls' => array_merge(...array_map(fn (TraceableToolbox $toolbox) => $toolbox->calls, $this->toolboxes)),
5151
];
@@ -65,7 +65,7 @@ public function getPlatformCalls(): array
6565
}
6666

6767
/**
68-
* @return Metadata[]
68+
* @return Tool[]
6969
*/
7070
public function getTools(): array
7171
{

src/Profiler/TraceablePlatform.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace PhpLlm\LlmChainBundle\Profiler;
66

7-
use PhpLlm\LlmChain\Model\Message\Content\File;
8-
use PhpLlm\LlmChain\Model\Model;
9-
use PhpLlm\LlmChain\Model\Response\AsyncResponse;
10-
use PhpLlm\LlmChain\Model\Response\ResponseInterface;
11-
use PhpLlm\LlmChain\PlatformInterface;
7+
use PhpLlm\LlmChain\Platform\Message\Content\File;
8+
use PhpLlm\LlmChain\Platform\Model;
9+
use PhpLlm\LlmChain\Platform\PlatformInterface;
10+
use PhpLlm\LlmChain\Platform\Response\AsyncResponse;
11+
use PhpLlm\LlmChain\Platform\Response\ResponseInterface;
1212

1313
/**
1414
* @phpstan-type PlatformCallData array{

src/Profiler/TraceableToolbox.php

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

77
use PhpLlm\LlmChain\Chain\Toolbox\ToolboxInterface;
8-
use PhpLlm\LlmChain\Model\Response\ToolCall;
8+
use PhpLlm\LlmChain\Platform\Response\ToolCall;
99

1010
/**
1111
* @phpstan-type ToolCallData array{
@@ -25,9 +25,9 @@ public function __construct(
2525
) {
2626
}
2727

28-
public function getMap(): array
28+
public function getTools(): array
2929
{
30-
return $this->toolbox->getMap();
30+
return $this->toolbox->getTools();
3131
}
3232

3333
public function execute(ToolCall $toolCall): mixed

src/Resources/config/services.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
use PhpLlm\LlmChain\Chain\StructuredOutput\ResponseFormatFactory;
99
use PhpLlm\LlmChain\Chain\StructuredOutput\ResponseFormatFactoryInterface;
1010
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor as ToolProcessor;
11-
use PhpLlm\LlmChain\Chain\Toolbox\MetadataFactory;
12-
use PhpLlm\LlmChain\Chain\Toolbox\MetadataFactory\ReflectionFactory;
1311
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
1412
use PhpLlm\LlmChain\Chain\Toolbox\ToolboxInterface;
13+
use PhpLlm\LlmChain\Chain\Toolbox\ToolFactory\ReflectionToolFactory;
14+
use PhpLlm\LlmChain\Chain\Toolbox\ToolFactoryInterface;
1515
use PhpLlm\LlmChainBundle\Profiler\DataCollector;
1616
use PhpLlm\LlmChainBundle\Profiler\TraceableToolbox;
1717

@@ -33,7 +33,7 @@
3333
->autowire()
3434
->abstract()
3535
->args([
36-
'$metadataFactory' => service(MetadataFactory::class),
36+
'$metadataFactory' => service(ToolFactoryInterface::class),
3737
'$tools' => abstract_arg('Collection of tools'),
3838
])
3939
->set(Toolbox::class)
@@ -42,8 +42,8 @@
4242
'$tools' => tagged_iterator('llm_chain.tool'),
4343
])
4444
->alias(ToolboxInterface::class, Toolbox::class)
45-
->set(ReflectionFactory::class)
46-
->alias(MetadataFactory::class, ReflectionFactory::class)
45+
->set(ReflectionToolFactory::class)
46+
->alias(ToolFactoryInterface::class, ReflectionToolFactory::class)
4747
->set('llm_chain.tool.chain_processor.abstract')
4848
->class(ToolProcessor::class)
4949
->abstract()

tests/Profiler/TraceableToolboxTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace PhpLlm\LlmChainBundle\Tests\Profiler;
66

7-
use PhpLlm\LlmChain\Chain\Toolbox\ExecutionReference;
8-
use PhpLlm\LlmChain\Chain\Toolbox\Metadata;
97
use PhpLlm\LlmChain\Chain\Toolbox\ToolboxInterface;
10-
use PhpLlm\LlmChain\Model\Response\ToolCall;
8+
use PhpLlm\LlmChain\Platform\Response\ToolCall;
9+
use PhpLlm\LlmChain\Platform\Tool\ExecutionReference;
10+
use PhpLlm\LlmChain\Platform\Tool\Tool;
1111
use PhpLlm\LlmChainBundle\Profiler\TraceableToolbox;
1212
use PHPUnit\Framework\Attributes\CoversClass;
1313
use PHPUnit\Framework\Attributes\Small;
@@ -21,19 +21,19 @@ final class TraceableToolboxTest extends TestCase
2121
#[Test]
2222
public function getMap(): void
2323
{
24-
$metadata = new Metadata(new ExecutionReference('Foo\Bar'), 'bar', 'description', null);
24+
$metadata = new Tool(new ExecutionReference('Foo\Bar'), 'bar', 'description', null);
2525
$toolbox = $this->createToolbox(['tool' => $metadata]);
2626
$traceableToolbox = new TraceableToolbox($toolbox);
2727

28-
$map = $traceableToolbox->getMap();
28+
$map = $traceableToolbox->getTools();
2929

3030
self::assertSame(['tool' => $metadata], $map);
3131
}
3232

3333
#[Test]
3434
public function execute(): void
3535
{
36-
$metadata = new Metadata(new ExecutionReference('Foo\Bar'), 'bar', 'description', null);
36+
$metadata = new Tool(new ExecutionReference('Foo\Bar'), 'bar', 'description', null);
3737
$toolbox = $this->createToolbox(['tool' => $metadata]);
3838
$traceableToolbox = new TraceableToolbox($toolbox);
3939
$toolCall = new ToolCall('foo', '__invoke');
@@ -47,19 +47,19 @@ public function execute(): void
4747
}
4848

4949
/**
50-
* @param Metadata[] $metadata
50+
* @param Tool[] $tools
5151
*/
52-
private function createToolbox(array $metadata): ToolboxInterface
52+
private function createToolbox(array $tools): ToolboxInterface
5353
{
54-
return new class($metadata) implements ToolboxInterface {
54+
return new class($tools) implements ToolboxInterface {
5555
public function __construct(
56-
private readonly array $metadata,
56+
private readonly array $tools,
5757
) {
5858
}
5959

60-
public function getMap(): array
60+
public function getTools(): array
6161
{
62-
return $this->metadata;
62+
return $this->tools;
6363
}
6464

6565
public function execute(ToolCall $toolCall): string

0 commit comments

Comments
 (0)