Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove tool metadata class awareness #255

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Chain/ToolBox/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* @param JsonSchema|null $parameters
*/
public function __construct(
public string $className,
public string $name,
public string $description,
public string $method,
Expand Down
1 change: 0 additions & 1 deletion src/Chain/ToolBox/MetadataFactory/ReflectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ private function convertAttribute(string $className, AsTool $attribute): Metadat
{
try {
return new Metadata(
$className,
$attribute->name,
$attribute->description,
$attribute->method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use PhpLlm\LlmChain\Model\Message\SystemMessage;
use PhpLlm\LlmChain\Model\Message\UserMessage;
use PhpLlm\LlmChain\Model\Response\ToolCall;
use PhpLlm\LlmChain\Tests\Fixture\Tool\ToolNoParams;
use PhpLlm\LlmChain\Tests\Fixture\Tool\ToolRequiredParams;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\Attributes\Test;
Expand Down Expand Up @@ -105,9 +103,8 @@ public function includeToolDefinitions(): void
public function getMap(): array
{
return [
new Metadata(ToolNoParams::class, 'tool_no_params', 'A tool without parameters', '__invoke', null),
new Metadata('tool_no_params', 'A tool without parameters', '__invoke', null),
new Metadata(
ToolRequiredParams::class,
'tool_required_params',
<<<DESCRIPTION
A tool with required parameters
Expand Down
8 changes: 4 additions & 4 deletions tests/Chain/ToolBox/ChainProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function processInputWithoutRegisteredToolsWillResultInNoOptionChange():
public function processInputWithRegisteredToolsWillResultInOptionChange(): void
{
$toolBox = $this->createStub(ToolBoxInterface::class);
$tool1 = new Metadata('ClassTool1', 'tool1', 'description1', 'method1', null);
$tool2 = new Metadata('ClassTool2', 'tool2', 'description2', 'method2', null);
$tool1 = new Metadata('tool1', 'description1', 'method1', null);
$tool2 = new Metadata('tool2', 'description2', 'method2', null);
$toolBox->method('getMap')->willReturn([$tool1, $tool2]);

$llm = $this->createMock(LanguageModel::class);
Expand All @@ -62,8 +62,8 @@ public function processInputWithRegisteredToolsWillResultInOptionChange(): void
public function processInputWithRegisteredToolsButToolOverride(): void
{
$toolBox = $this->createStub(ToolBoxInterface::class);
$tool1 = new Metadata('ClassTool1', 'tool1', 'description1', 'method1', null);
$tool2 = new Metadata('ClassTool2', 'tool2', 'description2', 'method2', null);
$tool1 = new Metadata('tool1', 'description1', 'method1', null);
$tool2 = new Metadata('tool2', 'description2', 'method2', null);
$toolBox->method('getMap')->willReturn([$tool1, $tool2]);

$llm = $this->createMock(LanguageModel::class);
Expand Down
6 changes: 2 additions & 4 deletions tests/Chain/ToolBox/FaultTolerantToolBoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use PhpLlm\LlmChain\Chain\ToolBox\Metadata;
use PhpLlm\LlmChain\Chain\ToolBox\ToolBoxInterface;
use PhpLlm\LlmChain\Model\Response\ToolCall;
use PhpLlm\LlmChain\Tests\Fixture\Tool\ToolNoParams;
use PhpLlm\LlmChain\Tests\Fixture\Tool\ToolRequiredParams;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
Expand Down Expand Up @@ -69,8 +67,8 @@ public function __construct(private readonly \Closure $exceptionFactory)
public function getMap(): array
{
return [
new Metadata(ToolNoParams::class, 'tool_no_params', 'A tool without parameters', '__invoke', null),
new Metadata(ToolRequiredParams::class, 'tool_required_params', 'A tool with required parameters', 'bar', null),
new Metadata('tool_no_params', 'A tool without parameters', '__invoke', null),
new Metadata('tool_required_params', 'A tool with required parameters', 'bar', null),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function getDefinition(): void

self::assertToolConfiguration(
metadata: $metadatas[0],
className: ToolRequiredParams::class,
name: 'tool_required_params',
description: 'A tool with required parameters',
method: 'bar',
Expand Down Expand Up @@ -102,7 +101,6 @@ public function getDefinitionWithMultiple(): void

self::assertToolConfiguration(
metadata: $first,
className: ToolMultiple::class,
name: 'tool_hello_world',
description: 'Function to say hello',
method: 'hello',
Expand All @@ -121,7 +119,6 @@ className: ToolMultiple::class,

self::assertToolConfiguration(
metadata: $second,
className: ToolMultiple::class,
name: 'tool_required_params',
description: 'Function to say a number',
method: 'bar',
Expand All @@ -143,9 +140,8 @@ className: ToolMultiple::class,
);
}

private function assertToolConfiguration(Metadata $metadata, string $className, string $name, string $description, string $method, array $parameters): void
private function assertToolConfiguration(Metadata $metadata, string $name, string $description, string $method, array $parameters): void
{
self::assertSame($className, $metadata->className);
self::assertSame($name, $metadata->name);
self::assertSame($description, $metadata->description);
self::assertSame($method, $metadata->method);
Expand Down