Skip to content

Commit d47c6f6

Browse files
committed
chore: 0.19 compatibility
1 parent 53fdc4e commit d47c6f6

File tree

9 files changed

+133
-133
lines changed

9 files changed

+133
-133
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ llm_chain:
5050
system_prompt: 'You are a helpful assistant that can answer questions.' # The default system prompt of the chain
5151
include_tools: true # Include tool definitions at the end of the system prompt
5252
tools:
53-
- 'PhpLlm\LlmChain\Chain\ToolBox\Tool\SimilaritySearch'
53+
- 'PhpLlm\LlmChain\Chain\ToolBox\Tool\SimilaritySearch'
5454
research:
5555
platform: 'llm_chain.platform.anthropic'
5656
model:
5757
name: 'Claude'
5858
tools: # If undefined, all tools are injected into the chain, use "tools: false" to disable tools.
59-
- 'PhpLlm\LlmChain\Chain\ToolBox\Tool\Wikipedia'
59+
- 'PhpLlm\LlmChain\Chain\Toolbox\Tool\Wikipedia'
6060
fault_tolerant_toolbox: false # Disables fault tolerant toolbox, default is true
6161
store:
6262
# also azure_search, mongodb and pinecone are supported as store type
@@ -111,20 +111,21 @@ services:
111111
autowire: true
112112
autoconfigure: true
113113
114-
PhpLlm\LlmChain\Chain\ToolBox\Tool\Clock: ~
115-
PhpLlm\LlmChain\Chain\ToolBox\Tool\OpenMeteo: ~
116-
PhpLlm\LlmChain\Chain\ToolBox\Tool\SerpApi:
114+
PhpLlm\LlmChain\Chain\Toolbox\Tool\Clock: ~
115+
PhpLlm\LlmChain\Chain\Toolbox\Tool\OpenMeteo: ~
116+
PhpLlm\LlmChain\Chain\Toolbox\Tool\SerpApi:
117117
$apiKey: '%env(SERP_API_KEY)%'
118-
PhpLlm\LlmChain\Chain\ToolBox\Tool\SimilaritySearch: ~
119-
PhpLlm\LlmChain\Chain\ToolBox\Tool\Tavily:
118+
PhpLlm\LlmChain\Chain\Toolbox\Tool\SimilaritySearch: ~
119+
PhpLlm\LlmChain\Chain\Toolbox\Tool\Tavily:
120120
$apiKey: '%env(TAVILY_API_KEY)%'
121-
PhpLlm\LlmChain\Chain\ToolBox\Tool\Wikipedia: ~
122-
PhpLlm\LlmChain\Chain\ToolBox\Tool\YouTubeTranscriber: ~
121+
PhpLlm\LlmChain\Chain\Toolbox\Tool\Wikipedia: ~
122+
PhpLlm\LlmChain\Chain\Toolbox\Tool\YouTubeTranscriber: ~
123123
```
124124

125125
Custom tools can be registered by using the `#[AsTool]` attribute:
126+
126127
```php
127-
use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool;
128+
use PhpLlm\LlmChain\Chain\Toolbox\Attribute\AsTool;
128129
129130
#[AsTool('company_name', 'Provides the name of your company')]
130131
final class CompanyName
@@ -152,7 +153,7 @@ llm_chain:
152153
chain:
153154
my_chain:
154155
tools:
155-
- 'PhpLlm\LlmChain\Chain\ToolBox\Tool\SimilaritySearch'
156+
- 'PhpLlm\LlmChain\Chain\Toolbox\Tool\SimilaritySearch'
156157
```
157158

158159
### Profiler

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.18",
18+
"php-llm/llm-chain": "^0.19",
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/LlmChainExtension.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@
2323
use PhpLlm\LlmChain\Chain\InputProcessor\SystemPromptInputProcessor;
2424
use PhpLlm\LlmChain\Chain\OutputProcessor;
2525
use PhpLlm\LlmChain\Chain\StructuredOutput\ChainProcessor as StructureOutputProcessor;
26-
use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool;
27-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor as ToolProcessor;
28-
use PhpLlm\LlmChain\Chain\ToolBox\FaultTolerantToolBox;
26+
use PhpLlm\LlmChain\Chain\Toolbox\Attribute\AsTool;
27+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor as ToolProcessor;
28+
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;
32+
use PhpLlm\LlmChain\Chain\Toolbox\Tool\Chain as ChainTool;
2933
use PhpLlm\LlmChain\ChainInterface;
3034
use PhpLlm\LlmChain\Embedder;
3135
use PhpLlm\LlmChain\Model\EmbeddingsModel;
@@ -38,7 +42,7 @@
3842
use PhpLlm\LlmChain\Store\VectorStoreInterface;
3943
use PhpLlm\LlmChainBundle\Profiler\DataCollector;
4044
use PhpLlm\LlmChainBundle\Profiler\TraceablePlatform;
41-
use PhpLlm\LlmChainBundle\Profiler\TraceableToolBox;
45+
use PhpLlm\LlmChainBundle\Profiler\TraceableToolbox;
4246
use Symfony\Component\Config\FileLocator;
4347
use Symfony\Component\DependencyInjection\ChildDefinition;
4448
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -126,7 +130,7 @@ public function load(array $configs, ContainerBuilder $container): void
126130

127131
if (false === $container->getParameter('kernel.debug')) {
128132
$container->removeDefinition(DataCollector::class);
129-
$container->removeDefinition(TraceableToolBox::class);
133+
$container->removeDefinition(TraceableToolbox::class);
130134
}
131135
}
132136

@@ -247,32 +251,33 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
247251

248252
// TOOL & PROCESSOR
249253
if ($config['tools']['enabled']) {
250-
// Create specific tool box and process if tools are explicitly defined
254+
// Create specific toolbox and process if tools are explicitly defined
251255
if (0 !== count($config['tools']['services'])) {
252256
$tools = array_map(static fn (string $tool) => new Reference($tool), $config['tools']['services']);
257+
253258
$toolboxDefinition = (new ChildDefinition('llm_chain.toolbox.abstract'))
254259
->replaceArgument('$tools', $tools);
255260
$container->setDefinition('llm_chain.toolbox.'.$name, $toolboxDefinition);
256261

257262
if ($config['fault_tolerant_toolbox']) {
258263
$faultTolerantToolboxDefinition = (new Definition('llm_chain.fault_tolerant_toolbox.'.$name))
259-
->setClass(FaultTolerantToolBox::class)
264+
->setClass(FaultTolerantToolbox::class)
260265
->setAutowired(true)
261266
->setDecoratedService('llm_chain.toolbox.'.$name);
262267
$container->setDefinition('llm_chain.fault_tolerant_toolbox.'.$name, $faultTolerantToolboxDefinition);
263268
}
264269

265270
if ($container->getParameter('kernel.debug')) {
266271
$traceableToolboxDefinition = (new Definition('llm_chain.traceable_toolbox.'.$name))
267-
->setClass(TraceableToolBox::class)
272+
->setClass(TraceableToolbox::class)
268273
->setAutowired(true)
269274
->setDecoratedService('llm_chain.toolbox.'.$name)
270275
->addTag('llm_chain.traceable_toolbox');
271276
$container->setDefinition('llm_chain.traceable_toolbox.'.$name, $traceableToolboxDefinition);
272277
}
273278

274279
$toolProcessorDefinition = (new ChildDefinition('llm_chain.tool.chain_processor.abstract'))
275-
->replaceArgument('$toolBox', new Reference('llm_chain.toolbox.'.$name));
280+
->replaceArgument('$toolbox', new Reference('llm_chain.toolbox.'.$name));
276281
$container->setDefinition('llm_chain.tool.chain_processor.'.$name, $toolProcessorDefinition);
277282

278283
$inputProcessors[] = new Reference('llm_chain.tool.chain_processor.'.$name);
@@ -298,7 +303,7 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
298303

299304
if ($config['include_tools']) {
300305
$systemPromptInputProcessorDefinition
301-
->setArgument('$toolBox', new Reference('llm_chain.toolbox.'.$name));
306+
->setArgument('$toolbox', new Reference('llm_chain.toolbox.'.$name));
302307
}
303308

304309
$inputProcessors[] = $systemPromptInputProcessorDefinition;
@@ -424,10 +429,11 @@ private function processEmbedderConfig(int|string $name, array $config, Containe
424429
$modelDefinition->addTag('llm_chain.model.embeddings_model');
425430
$container->setDefinition('llm_chain.embedder.'.$name.'.embeddings', $modelDefinition);
426431

427-
$definition = (new ChildDefinition('llm_chain.embedder.abstract'))
428-
->replaceArgument('$platform', new Reference($config['platform']))
429-
->replaceArgument('$store', new Reference($config['store']))
430-
->replaceArgument('$embeddings', new Reference('llm_chain.embedder.'.$name.'.embeddings'));
432+
$definition = new Definition(Embedder::class, [
433+
'$embeddings' => new Reference('llm_chain.embedder.'.$name.'.embeddings'),
434+
'$platform' => new Reference($config['platform']),
435+
'$store' => new Reference($config['store']),
436+
]);
431437

432438
$container->setDefinition('llm_chain.embedder.'.$name, $definition);
433439
}

src/Profiler/DataCollector.php

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

55
namespace PhpLlm\LlmChainBundle\Profiler;
66

7-
use PhpLlm\LlmChain\Chain\ToolBox\Metadata;
8-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBoxInterface;
7+
use PhpLlm\LlmChain\Chain\Toolbox\Metadata;
8+
use PhpLlm\LlmChain\Chain\Toolbox\ToolboxInterface;
99
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
1010
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
1111
use Symfony\Component\HttpFoundation\Request;
1212
use Symfony\Component\HttpFoundation\Response;
1313

1414
/**
1515
* @phpstan-import-type PlatformCallData from TraceablePlatform
16-
* @phpstan-import-type ToolCallData from TraceableToolBox
16+
* @phpstan-import-type ToolCallData from TraceableToolbox
1717
*/
1818
final class DataCollector extends AbstractDataCollector
1919
{
@@ -23,31 +23,31 @@ final class DataCollector extends AbstractDataCollector
2323
private readonly array $platforms;
2424

2525
/**
26-
* @var TraceableToolBox[]
26+
* @var TraceableToolbox[]
2727
*/
28-
private readonly array $toolBoxes;
28+
private readonly array $toolboxes;
2929

3030
/**
3131
* @param TraceablePlatform[] $platforms
32-
* @param TraceableToolBox[] $toolBoxes
32+
* @param TraceableToolbox[] $toolboxes
3333
*/
3434
public function __construct(
3535
#[TaggedIterator('llm_chain.traceable_platform')]
3636
iterable $platforms,
37-
private readonly ToolBoxInterface $defaultToolBox,
37+
private readonly ToolboxInterface $defaultToolBox,
3838
#[TaggedIterator('llm_chain.traceable_toolbox')]
39-
iterable $toolBoxes,
39+
iterable $toolboxes,
4040
) {
4141
$this->platforms = $platforms instanceof \Traversable ? iterator_to_array($platforms) : $platforms;
42-
$this->toolBoxes = $toolBoxes instanceof \Traversable ? iterator_to_array($toolBoxes) : $toolBoxes;
42+
$this->toolboxes = $toolboxes instanceof \Traversable ? iterator_to_array($toolboxes) : $toolboxes;
4343
}
4444

4545
public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
4646
{
4747
$this->data = [
4848
'tools' => $this->defaultToolBox->getMap(),
4949
'platform_calls' => array_merge(...array_map(fn (TraceablePlatform $platform) => $platform->calls, $this->platforms)),
50-
'tool_calls' => array_merge(...array_map(fn (TraceableToolBox $toolBox) => $toolBox->calls, $this->toolBoxes)),
50+
'tool_calls' => array_merge(...array_map(fn (TraceableToolbox $toolbox) => $toolbox->calls, $this->toolboxes)),
5151
];
5252
}
5353

src/Profiler/TraceableToolBox.php renamed to src/Profiler/TraceableToolbox.php

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

55
namespace PhpLlm\LlmChainBundle\Profiler;
66

7-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBoxInterface;
7+
use PhpLlm\LlmChain\Chain\Toolbox\ToolboxInterface;
88
use PhpLlm\LlmChain\Model\Response\ToolCall;
99

1010
/**
@@ -13,26 +13,26 @@
1313
* result: string,
1414
* }
1515
*/
16-
final class TraceableToolBox implements ToolBoxInterface
16+
final class TraceableToolbox implements ToolboxInterface
1717
{
1818
/**
1919
* @var ToolCallData[]
2020
*/
2121
public array $calls = [];
2222

2323
public function __construct(
24-
private readonly ToolBoxInterface $toolBox,
24+
private readonly ToolboxInterface $toolbox,
2525
) {
2626
}
2727

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

3333
public function execute(ToolCall $toolCall): mixed
3434
{
35-
$result = $this->toolBox->execute($toolCall);
35+
$result = $this->toolbox->execute($toolCall);
3636

3737
$this->calls[] = [
3838
'call' => $toolCall,

src/Resources/config/services.php

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,19 @@
77
use PhpLlm\LlmChain\Chain\StructuredOutput\ChainProcessor as StructureOutputProcessor;
88
use PhpLlm\LlmChain\Chain\StructuredOutput\ResponseFormatFactory;
99
use PhpLlm\LlmChain\Chain\StructuredOutput\ResponseFormatFactoryInterface;
10-
use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor as ToolProcessor;
11-
use PhpLlm\LlmChain\Chain\ToolBox\MetadataFactory;
12-
use PhpLlm\LlmChain\Chain\ToolBox\MetadataFactory\ReflectionFactory;
13-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBox;
14-
use PhpLlm\LlmChain\Chain\ToolBox\ToolBoxInterface;
15-
use PhpLlm\LlmChain\Embedder;
10+
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor as ToolProcessor;
11+
use PhpLlm\LlmChain\Chain\Toolbox\MetadataFactory;
12+
use PhpLlm\LlmChain\Chain\Toolbox\MetadataFactory\ReflectionFactory;
13+
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
14+
use PhpLlm\LlmChain\Chain\Toolbox\ToolboxInterface;
1615
use PhpLlm\LlmChainBundle\Profiler\DataCollector;
17-
use PhpLlm\LlmChainBundle\Profiler\TraceableToolBox;
16+
use PhpLlm\LlmChainBundle\Profiler\TraceableToolbox;
1817

1918
return static function (ContainerConfigurator $container): void {
2019
$container->services()
2120
->defaults()
2221
->autowire()
2322

24-
// high level feature
25-
->set('llm_chain.embedder.abstract', Embedder::class)
26-
->abstract()
27-
->args([
28-
'$embeddings' => abstract_arg('Embeddings model'),
29-
])
30-
3123
// structured output
3224
->set(ResponseFormatFactory::class)
3325
->alias(ResponseFormatFactoryInterface::class, ResponseFormatFactory::class)
@@ -37,40 +29,40 @@
3729

3830
// tools
3931
->set('llm_chain.toolbox.abstract')
40-
->class(ToolBox::class)
32+
->class(Toolbox::class)
4133
->autowire()
4234
->abstract()
4335
->args([
4436
'$tools' => abstract_arg('Collection of tools'),
4537
])
46-
->set(ToolBox::class)
38+
->set(Toolbox::class)
4739
->parent('llm_chain.toolbox.abstract')
4840
->args([
4941
'$tools' => tagged_iterator('llm_chain.tool'),
5042
])
51-
->alias(ToolBoxInterface::class, ToolBox::class)
43+
->alias(ToolboxInterface::class, Toolbox::class)
5244
->set(ReflectionFactory::class)
5345
->alias(MetadataFactory::class, ReflectionFactory::class)
5446
->set('llm_chain.tool.chain_processor.abstract')
5547
->class(ToolProcessor::class)
5648
->abstract()
5749
->args([
58-
'$toolBox' => abstract_arg('Tool box'),
50+
'$toolbox' => abstract_arg('Toolbox'),
5951
])
6052
->set(ToolProcessor::class)
6153
->parent('llm_chain.tool.chain_processor.abstract')
6254
->tag('llm_chain.chain.input_processor')
6355
->tag('llm_chain.chain.output_processor')
6456
->args([
65-
'$toolBox' => service(ToolBoxInterface::class),
57+
'$toolbox' => service(ToolboxInterface::class),
6658
'$eventDispatcher' => service('event_dispatcher')->nullOnInvalid(),
6759
])
6860

6961
// profiler
7062
->set(DataCollector::class)
7163
->tag('data_collector')
72-
->set(TraceableToolBox::class)
73-
->decorate(ToolBoxInterface::class)
64+
->set(TraceableToolbox::class)
65+
->decorate(ToolboxInterface::class)
7466
->tag('llm_chain.traceable_toolbox')
7567
;
7668
};

src/Resources/views/data_collector.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
<tr>
195195
<th>{{ tool.name }}</th>
196196
<td>{{ tool.description }}</td>
197-
<td>{{ tool.className }}::{{ tool.method }}</td>
197+
<td>{{ tool.reference.class }}::{{ tool.reference.method }}</td>
198198
<td>
199199
{% if tool.parameters %}
200200
<ul>

0 commit comments

Comments
 (0)