Skip to content

Commit ac43c9f

Browse files
committed
refactor: adopt new toolbox lowercase
1 parent 66a0eb3 commit ac43c9f

File tree

9 files changed

+123
-121
lines changed

9 files changed

+123
-121
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ 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
- service: 'App\Chain\Tool\CompanyName'
5555
name: 'company_name'
5656
description: 'Provides the name of your company'
@@ -61,7 +61,7 @@ llm_chain:
6161
model:
6262
name: 'Claude'
6363
tools: # If undefined, all tools are injected into the chain, use "tools: false" to disable tools.
64-
- 'PhpLlm\LlmChain\Chain\ToolBox\Tool\Wikipedia'
64+
- 'PhpLlm\LlmChain\Chain\Toolbox\Tool\Wikipedia'
6565
- 'App\Chain\Tool\CompanyName'
6666
fault_tolerant_toolbox: false # Disables fault tolerant toolbox, default is true
6767
as_tool:
@@ -126,20 +126,21 @@ services:
126126
autowire: true
127127
autoconfigure: true
128128
129-
PhpLlm\LlmChain\Chain\ToolBox\Tool\Clock: ~
130-
PhpLlm\LlmChain\Chain\ToolBox\Tool\OpenMeteo: ~
131-
PhpLlm\LlmChain\Chain\ToolBox\Tool\SerpApi:
129+
PhpLlm\LlmChain\Chain\Toolbox\Tool\Clock: ~
130+
PhpLlm\LlmChain\Chain\Toolbox\Tool\OpenMeteo: ~
131+
PhpLlm\LlmChain\Chain\Toolbox\Tool\SerpApi:
132132
$apiKey: '%env(SERP_API_KEY)%'
133-
PhpLlm\LlmChain\Chain\ToolBox\Tool\SimilaritySearch: ~
134-
PhpLlm\LlmChain\Chain\ToolBox\Tool\Tavily:
133+
PhpLlm\LlmChain\Chain\Toolbox\Tool\SimilaritySearch: ~
134+
PhpLlm\LlmChain\Chain\Toolbox\Tool\Tavily:
135135
$apiKey: '%env(TAVILY_API_KEY)%'
136-
PhpLlm\LlmChain\Chain\ToolBox\Tool\Wikipedia: ~
137-
PhpLlm\LlmChain\Chain\ToolBox\Tool\YouTubeTranscriber: ~
136+
PhpLlm\LlmChain\Chain\Toolbox\Tool\Wikipedia: ~
137+
PhpLlm\LlmChain\Chain\Toolbox\Tool\YouTubeTranscriber: ~
138138
```
139139

140140
Custom tools can be registered by using the `#[AsTool]` attribute:
141+
141142
```php
142-
use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool;
143+
use PhpLlm\LlmChain\Chain\Toolbox\Attribute\AsTool;
143144
144145
#[AsTool('company_name', 'Provides the name of your company')]
145146
final class CompanyName
@@ -167,7 +168,7 @@ llm_chain:
167168
chain:
168169
my_chain:
169170
tools:
170-
- 'PhpLlm\LlmChain\Chain\ToolBox\Tool\SimilaritySearch'
171+
- 'PhpLlm\LlmChain\Chain\Toolbox\Tool\SimilaritySearch'
171172
```
172173

173174
### 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": "dev-feat-multiple-metadata-factories",
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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
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;
2929
use PhpLlm\LlmChain\ChainInterface;
3030
use PhpLlm\LlmChain\Embedder;
3131
use PhpLlm\LlmChain\Model\EmbeddingsModel;
@@ -38,7 +38,7 @@
3838
use PhpLlm\LlmChain\Store\VectorStoreInterface;
3939
use PhpLlm\LlmChainBundle\Profiler\DataCollector;
4040
use PhpLlm\LlmChainBundle\Profiler\TraceablePlatform;
41-
use PhpLlm\LlmChainBundle\Profiler\TraceableToolBox;
41+
use PhpLlm\LlmChainBundle\Profiler\TraceableToolbox;
4242
use Symfony\Component\Config\FileLocator;
4343
use Symfony\Component\DependencyInjection\ChildDefinition;
4444
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -126,7 +126,7 @@ public function load(array $configs, ContainerBuilder $container): void
126126

127127
if (false === $container->getParameter('kernel.debug')) {
128128
$container->removeDefinition(DataCollector::class);
129-
$container->removeDefinition(TraceableToolBox::class);
129+
$container->removeDefinition(TraceableToolbox::class);
130130
}
131131
}
132132

@@ -247,7 +247,7 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
247247

248248
// TOOL & PROCESSOR
249249
if ($config['tools']['enabled']) {
250-
// Create specific tool box and process if tools are explicitly defined
250+
// Create specific toolbox and process if tools are explicitly defined
251251
if (0 !== count($config['tools']['services'])) {
252252
$tools = array_map(static fn (string $tool) => new Reference($tool), $config['tools']['services']);
253253
$toolboxDefinition = (new ChildDefinition('llm_chain.toolbox.abstract'))
@@ -256,23 +256,23 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
256256

257257
if ($config['fault_tolerant_toolbox']) {
258258
$faultTolerantToolboxDefinition = (new Definition('llm_chain.fault_tolerant_toolbox.'.$name))
259-
->setClass(FaultTolerantToolBox::class)
259+
->setClass(FaultTolerantToolbox::class)
260260
->setAutowired(true)
261261
->setDecoratedService('llm_chain.toolbox.'.$name);
262262
$container->setDefinition('llm_chain.fault_tolerant_toolbox.'.$name, $faultTolerantToolboxDefinition);
263263
}
264264

265265
if ($container->getParameter('kernel.debug')) {
266266
$traceableToolboxDefinition = (new Definition('llm_chain.traceable_toolbox.'.$name))
267-
->setClass(TraceableToolBox::class)
267+
->setClass(TraceableToolbox::class)
268268
->setAutowired(true)
269269
->setDecoratedService('llm_chain.toolbox.'.$name)
270270
->addTag('llm_chain.traceable_toolbox');
271271
$container->setDefinition('llm_chain.traceable_toolbox.'.$name, $traceableToolboxDefinition);
272272
}
273273

274274
$toolProcessorDefinition = (new ChildDefinition('llm_chain.tool.chain_processor.abstract'))
275-
->replaceArgument('$toolBox', new Reference('llm_chain.toolbox.'.$name));
275+
->replaceArgument('$toolbox', new Reference('llm_chain.toolbox.'.$name));
276276
$container->setDefinition('llm_chain.tool.chain_processor.'.$name, $toolProcessorDefinition);
277277

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

299299
if ($config['include_tools']) {
300300
$systemPromptInputProcessorDefinition
301-
->setArgument('$toolBox', new Reference('llm_chain.toolbox.'.$name));
301+
->setArgument('$toolbox', new Reference('llm_chain.toolbox.'.$name));
302302
}
303303

304304
$inputProcessors[] = $systemPromptInputProcessorDefinition;

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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
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;
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;
1515
use PhpLlm\LlmChain\Embedder;
1616
use PhpLlm\LlmChainBundle\Profiler\DataCollector;
17-
use PhpLlm\LlmChainBundle\Profiler\TraceableToolBox;
17+
use PhpLlm\LlmChainBundle\Profiler\TraceableToolbox;
1818

1919
return static function (ContainerConfigurator $container): void {
2020
$container->services()
@@ -37,40 +37,40 @@
3737

3838
// tools
3939
->set('llm_chain.toolbox.abstract')
40-
->class(ToolBox::class)
40+
->class(Toolbox::class)
4141
->autowire()
4242
->abstract()
4343
->args([
4444
'$tools' => abstract_arg('Collection of tools'),
4545
])
46-
->set(ToolBox::class)
46+
->set(Toolbox::class)
4747
->parent('llm_chain.toolbox.abstract')
4848
->args([
4949
'$tools' => tagged_iterator('llm_chain.tool'),
5050
])
51-
->alias(ToolBoxInterface::class, ToolBox::class)
51+
->alias(ToolboxInterface::class, Toolbox::class)
5252
->set(ReflectionFactory::class)
5353
->alias(MetadataFactory::class, ReflectionFactory::class)
5454
->set('llm_chain.tool.chain_processor.abstract')
5555
->class(ToolProcessor::class)
5656
->abstract()
5757
->args([
58-
'$toolBox' => abstract_arg('Tool box'),
58+
'$toolbox' => abstract_arg('Toolbox'),
5959
])
6060
->set(ToolProcessor::class)
6161
->parent('llm_chain.tool.chain_processor.abstract')
6262
->tag('llm_chain.chain.input_processor')
6363
->tag('llm_chain.chain.output_processor')
6464
->args([
65-
'$toolBox' => service(ToolBoxInterface::class),
65+
'$toolbox' => service(ToolboxInterface::class),
6666
'$eventDispatcher' => service('event_dispatcher')->nullOnInvalid(),
6767
])
6868

6969
// profiler
7070
->set(DataCollector::class)
7171
->tag('data_collector')
72-
->set(TraceableToolBox::class)
73-
->decorate(ToolBoxInterface::class)
72+
->set(TraceableToolbox::class)
73+
->decorate(ToolboxInterface::class)
7474
->tag('llm_chain.traceable_toolbox')
7575
;
7676
};

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>

tests/Profiler/TraceableToolBoxTest.php

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)