Skip to content

Commit 06f3b62

Browse files
refactor: rename Registry to ToolBox (#15)
* Rename `Registry` to `Toolbox` * refactor: rename tool registry to ToolBox --------- Co-authored-by: Christopher Hertel <[email protected]>
1 parent f38a005 commit 06f3b62

File tree

9 files changed

+30
-30
lines changed

9 files changed

+30
-30
lines changed

examples/toolchain-clock.php renamed to examples/toolbox-clock.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
88
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
99
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
10-
use PhpLlm\LlmChain\ToolBox\Registry;
1110
use PhpLlm\LlmChain\ToolBox\Tool\Clock;
1211
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
12+
use PhpLlm\LlmChain\ToolBox\ToolBox;
1313
use Symfony\Component\Clock\Clock as SymfonyClock;
1414
use Symfony\Component\HttpClient\HttpClient;
1515

@@ -19,8 +19,8 @@
1919
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
2020

2121
$clock = new Clock(new SymfonyClock());
22-
$registry = new Registry(new ToolAnalyzer(new ParameterAnalyzer()), [$clock]);
23-
$chain = new Chain($llm, $registry);
22+
$toolBox = new ToolBox(new ToolAnalyzer(new ParameterAnalyzer()), [$clock]);
23+
$chain = new Chain($llm, $toolBox);
2424

2525
$messages = new MessageBag(Message::ofUser('What date and time is it?'));
2626
$response = $chain->call($messages);

examples/toolchain-serpapi.php renamed to examples/toolbox-serpapi.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
88
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
99
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
10-
use PhpLlm\LlmChain\ToolBox\Registry;
1110
use PhpLlm\LlmChain\ToolBox\Tool\SerpApi;
1211
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
12+
use PhpLlm\LlmChain\ToolBox\ToolBox;
1313
use Symfony\Component\HttpClient\HttpClient;
1414

1515
require_once dirname(__DIR__).'/vendor/autoload.php';
@@ -19,8 +19,8 @@
1919
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
2020

2121
$serpApi = new SerpApi($httpClient, getenv('SERP_API_KEY'));
22-
$registry = new Registry(new ToolAnalyzer(new ParameterAnalyzer()), [$serpApi]);
23-
$chain = new Chain($llm, $registry);
22+
$toolBox = new ToolBox(new ToolAnalyzer(new ParameterAnalyzer()), [$serpApi]);
23+
$chain = new Chain($llm, $toolBox);
2424

2525
$messages = new MessageBag(Message::ofUser('Who is the current chancellor of Germany?'));
2626
$response = $chain->call($messages);

examples/toolchain-weather.php renamed to examples/toolbox-weather.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
88
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
99
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
10-
use PhpLlm\LlmChain\ToolBox\Registry;
1110
use PhpLlm\LlmChain\ToolBox\Tool\OpenMeteo;
1211
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
12+
use PhpLlm\LlmChain\ToolBox\ToolBox;
1313
use Symfony\Component\HttpClient\HttpClient;
1414

1515
require_once dirname(__DIR__).'/vendor/autoload.php';
@@ -19,8 +19,8 @@
1919
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
2020

2121
$wikipedia = new OpenMeteo($httpClient);
22-
$registry = new Registry(new ToolAnalyzer(new ParameterAnalyzer()), [$wikipedia]);
23-
$chain = new Chain($llm, $registry);
22+
$toolBox = new ToolBox(new ToolAnalyzer(new ParameterAnalyzer()), [$wikipedia]);
23+
$chain = new Chain($llm, $toolBox);
2424

2525
$messages = new MessageBag(Message::ofUser('How is the weather currently in Berlin?'));
2626
$response = $chain->call($messages);

examples/toolchain-wikipedia.php renamed to examples/toolbox-wikipedia.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
88
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
99
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
10-
use PhpLlm\LlmChain\ToolBox\Registry;
1110
use PhpLlm\LlmChain\ToolBox\Tool\Wikipedia;
1211
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
12+
use PhpLlm\LlmChain\ToolBox\ToolBox;
1313
use Symfony\Component\HttpClient\HttpClient;
1414

1515
require_once dirname(__DIR__).'/vendor/autoload.php';
@@ -19,8 +19,8 @@
1919
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
2020

2121
$wikipedia = new Wikipedia($httpClient);
22-
$registry = new Registry(new ToolAnalyzer(new ParameterAnalyzer()), [$wikipedia]);
23-
$chain = new Chain($llm, $registry);
22+
$toolBox = new ToolBox(new ToolAnalyzer(new ParameterAnalyzer()), [$wikipedia]);
23+
$chain = new Chain($llm, $toolBox);
2424

2525
$messages = new MessageBag(Message::ofUser('Who is the current chancellor of Germany?'));
2626
$response = $chain->call($messages);

examples/toolchain-youtube.php renamed to examples/toolbox-youtube.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
88
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
99
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
10-
use PhpLlm\LlmChain\ToolBox\Registry;
1110
use PhpLlm\LlmChain\ToolBox\Tool\YouTubeTranscriber;
1211
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
12+
use PhpLlm\LlmChain\ToolBox\ToolBox;
1313
use Symfony\Component\HttpClient\HttpClient;
1414

1515
require_once dirname(__DIR__).'/vendor/autoload.php';
@@ -19,8 +19,8 @@
1919
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
2020

2121
$transcriber = new YouTubeTranscriber($httpClient);
22-
$registry = new Registry(new ToolAnalyzer(new ParameterAnalyzer()), [$transcriber]);
23-
$chain = new Chain($llm, $registry);
22+
$toolBox = new ToolBox(new ToolAnalyzer(new ParameterAnalyzer()), [$transcriber]);
23+
$chain = new Chain($llm, $toolBox);
2424

2525
$messages = new MessageBag(Message::ofUser('Please summarize this video for me: https://www.youtube.com/watch?v=6uXW-ulpj0s'));
2626
$response = $chain->call($messages);

src/Chain.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
use PhpLlm\LlmChain\Message\Message;
88
use PhpLlm\LlmChain\Message\MessageBag;
99
use PhpLlm\LlmChain\StructuredOutput\ResponseFormatFactory;
10-
use PhpLlm\LlmChain\ToolBox\RegistryInterface;
10+
use PhpLlm\LlmChain\ToolBox\ToolBoxInterface;
1111
use Symfony\Component\Serializer\SerializerInterface;
1212

1313
final readonly class Chain
1414
{
1515
public function __construct(
1616
private LanguageModel $llm,
17-
private ?RegistryInterface $toolRegistry = null,
17+
private ?ToolBoxInterface $toolBox = null,
1818
private ?ResponseFormatFactory $responseFormatFactory = null,
1919
private ?SerializerInterface $serializer = null,
2020
) {
@@ -27,8 +27,8 @@ public function call(MessageBag $messages, array $options = []): string|object
2727
{
2828
$llmOptions = $options;
2929

30-
if (!array_key_exists('tools', $llmOptions) && null !== $this->toolRegistry && $this->llm->supportsToolCalling()) {
31-
$llmOptions['tools'] = $this->toolRegistry->getMap();
30+
if (!array_key_exists('tools', $llmOptions) && null !== $this->toolBox && $this->llm->supportsToolCalling()) {
31+
$llmOptions['tools'] = $this->toolBox->getMap();
3232
}
3333

3434
if (array_key_exists('output_structure', $llmOptions) && null !== $this->responseFormatFactory && $this->llm->supportsStructuredOutput()) {
@@ -43,7 +43,7 @@ public function call(MessageBag $messages, array $options = []): string|object
4343
$clonedMessages[] = Message::ofAssistant(toolCalls: $response->getToolCalls());
4444

4545
foreach ($response->getToolCalls() as $toolCall) {
46-
$result = $this->toolRegistry->execute($toolCall);
46+
$result = $this->toolBox->execute($toolCall);
4747
$clonedMessages[] = Message::ofToolCall($toolCall, $result);
4848
}
4949

src/ToolBox/Registry.php renamed to src/ToolBox/ToolBox.php

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

77
use PhpLlm\LlmChain\Response\ToolCall;
88

9-
final class Registry implements RegistryInterface
9+
final class ToolBox implements ToolBoxInterface
1010
{
1111
/**
1212
* @var list<object>

src/ToolBox/RegistryInterface.php renamed to src/ToolBox/ToolBoxInterface.php

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

77
use PhpLlm\LlmChain\Response\ToolCall;
88

9-
interface RegistryInterface
9+
interface ToolBoxInterface
1010
{
1111
/**
1212
* @return Metadata[]

tests/ToolBox/RegistryTest.php renamed to tests/ToolBox/ToolBoxTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,35 @@
1111
use PhpLlm\LlmChain\ToolBox\AsTool;
1212
use PhpLlm\LlmChain\ToolBox\Metadata;
1313
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
14-
use PhpLlm\LlmChain\ToolBox\Registry;
1514
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
15+
use PhpLlm\LlmChain\ToolBox\ToolBox;
1616
use PHPUnit\Framework\Attributes\CoversClass;
1717
use PHPUnit\Framework\Attributes\UsesClass;
1818
use PHPUnit\Framework\TestCase;
1919

20-
#[CoversClass(Registry::class)]
20+
#[CoversClass(ToolBox::class)]
2121
#[UsesClass(ToolCall::class)]
2222
#[UsesClass(AsTool::class)]
2323
#[UsesClass(Metadata::class)]
2424
#[UsesClass(ParameterAnalyzer::class)]
2525
#[UsesClass(ToolAnalyzer::class)]
26-
final class RegistryTest extends TestCase
26+
final class ToolBoxTest extends TestCase
2727
{
28-
private Registry $registry;
28+
private ToolBox $toolBox;
2929

3030
protected function setUp(): void
3131
{
3232
$toolAnalyzer = new ToolAnalyzer(new ParameterAnalyzer());
33-
$this->registry = new Registry($toolAnalyzer, [
33+
$this->toolBox = new ToolBox($toolAnalyzer, [
3434
new ToolRequiredParams(),
3535
new ToolOptionalParam(),
3636
new ToolNoParams(),
3737
]);
3838
}
3939

40-
public function testFunctionsMap(): void
40+
public function testToolsMap(): void
4141
{
42-
$actual = $this->registry->getMap();
42+
$actual = $this->toolBox->getMap();
4343
$expected = [
4444
[
4545
'type' => 'function',
@@ -102,7 +102,7 @@ public function testFunctionsMap(): void
102102

103103
public function testExecute(): void
104104
{
105-
$actual = $this->registry->execute(new ToolCall('call_1234', 'tool_required_params', ['text' => 'Hello', 'number' => 3]));
105+
$actual = $this->toolBox->execute(new ToolCall('call_1234', 'tool_required_params', ['text' => 'Hello', 'number' => 3]));
106106
$expected = 'Hello says "3".';
107107

108108
self::assertSame($expected, $actual);

0 commit comments

Comments
 (0)