Skip to content

Commit bff641a

Browse files
committed
tool parameters
1 parent 69a71ca commit bff641a

File tree

4 files changed

+16
-110
lines changed

4 files changed

+16
-110
lines changed

src/Tools/Tool.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,12 @@
2222
use function method_exists;
2323

2424
/**
25-
* @method static static make(?string $name = null, ?string $description = null, array $properties = [], array $annotations = [])
25+
* @method static static make(?string $name = null, ?string $description = null, array $properties = [], array $parameters = [], array $annotations = [])
2626
*/
2727
class Tool implements ToolInterface
2828
{
2929
use StaticConstructor;
3030

31-
/**
32-
* @var ToolPropertyInterface[]
33-
*/
34-
protected array $properties = [];
35-
3631
/**
3732
* @var null|callable
3833
*/
@@ -64,18 +59,16 @@ class Tool implements ToolInterface
6459
* Tool constructor.
6560
*
6661
* @param ToolPropertyInterface[] $properties
62+
* @params array<int, mixed>|null $parameters
6763
* @params array<int, mixed>|null $annotations
6864
*/
6965
public function __construct(
7066
protected string $name,
7167
protected ?string $description = null,
72-
array $properties = [],
68+
protected array $properties = [],
7369
protected array $parameters = [],
7470
protected array $annotations = []
7571
) {
76-
if ($properties !== []) {
77-
$this->properties = $properties;
78-
}
7972
}
8073

8174
public function getName(): string
@@ -144,6 +137,12 @@ public function getAnnotations(): array
144137
return $this->annotations;
145138
}
146139

140+
public function setParameters(array $parameters): self
141+
{
142+
$this->parameters = $parameters;
143+
return $this;
144+
}
145+
147146
public function getParameters(): array
148147
{
149148
return $this->parameters;

tests/Stubs/Tools/TestToolClassWithoutParentConstructor.php

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

tests/Stubs/Tools/TestToolClassWithoutParentConstructorMixed.php

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

tests/Tools/ToolTest.php

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use NeuronAI\Tests\Stubs\StructuredOutput\Color;
99
use NeuronAI\Tests\Stubs\Tools\TestToolClassOnlyParentConstructor;
1010
use NeuronAI\Tests\Stubs\Tools\TestToolClassOnlyParentConstructorFluent;
11-
use NeuronAI\Tests\Stubs\Tools\TestToolClassWithoutParentConstructor;
12-
use NeuronAI\Tests\Stubs\Tools\TestToolClassWithoutParentConstructorMixed;
1311
use NeuronAI\Tests\Stubs\Tools\TestToolClassWithParentConstructor;
1412
use NeuronAI\Tests\Stubs\Tools\TestToolClassWithParentConstructorMixed;
1513
use NeuronAI\Tools\ArrayProperty;
@@ -21,8 +19,6 @@
2119
use PHPUnit\Framework\TestCase;
2220
use Error;
2321

24-
use function count;
25-
2622
class ToolTest extends TestCase
2723
{
2824
public function test_tool_instance(): void
@@ -415,28 +411,10 @@ public function test_tool_named_parameters(): void
415411
);
416412
}
417413

418-
public function test_properties_declaration_on_method_and_constructor_without_parent_constructor(): void
419-
{
420-
$tool = new TestToolClassWithoutParentConstructorMixed('test');
421-
$this->assertEquals(1, count($tool->getProperties()));
422-
$this->assertEquals('test_tool', $tool->getName());
423-
$this->assertEquals('test tool', $tool->getDescription());
424-
$this->assertEquals('test', $tool->getKey());
425-
}
426-
427-
public function test_properties_declaration_on_method_without_parent_constructor(): void
428-
{
429-
$tool = new TestToolClassWithoutParentConstructor('test');
430-
$this->assertEquals(2, count($tool->getProperties()));
431-
$this->assertEquals('test_tool', $tool->getName());
432-
$this->assertEquals('test tool', $tool->getDescription());
433-
$this->assertEquals('test', $tool->getKey());
434-
}
435-
436414
public function test_properties_declaration_on_method_and_constructor_with_parent_constructor(): void
437415
{
438416
$tool = new TestToolClassWithParentConstructorMixed('test');
439-
$this->assertEquals(1, count($tool->getProperties()));
417+
$this->assertCount(1, $tool->getProperties());
440418
$this->assertEquals('test_tool', $tool->getName());
441419
$this->assertEquals('test tool', $tool->getDescription());
442420
$this->assertEquals('test', $tool->getKey());
@@ -445,7 +423,7 @@ public function test_properties_declaration_on_method_and_constructor_with_paren
445423
public function test_properties_declaration_on_method_with_parent_constructor(): void
446424
{
447425
$tool = new TestToolClassWithParentConstructor('test');
448-
$this->assertEquals(1, count($tool->getProperties()));
426+
$this->assertCount(1, $tool->getProperties());
449427
$this->assertEquals('test_tool', $tool->getName());
450428
$this->assertEquals('test tool', $tool->getDescription());
451429
$this->assertEquals('test', $tool->getKey());
@@ -454,7 +432,7 @@ public function test_properties_declaration_on_method_with_parent_constructor():
454432
public function test_properties_declaration_on_constructor_with_parent_constructor(): void
455433
{
456434
$tool = new TestToolClassOnlyParentConstructor('test');
457-
$this->assertEquals(2, count($tool->getProperties()));
435+
$this->assertCount(2, $tool->getProperties());
458436
$this->assertEquals('test_tool', $tool->getName());
459437
$this->assertEquals('test tool', $tool->getDescription());
460438
$this->assertEquals('test', $tool->getKey());
@@ -463,7 +441,7 @@ public function test_properties_declaration_on_constructor_with_parent_construct
463441
public function test_properties_declaration_on_constructor_with_parent_constructor_fluent(): void
464442
{
465443
$tool = new TestToolClassOnlyParentConstructorFluent('test');
466-
$this->assertEquals(2, count($tool->getProperties()));
444+
$this->assertCount(2, $tool->getProperties());
467445
$this->assertEquals('test_tool', $tool->getName());
468446
$this->assertEquals('test tool', $tool->getDescription());
469447
$this->assertEquals('test', $tool->getKey());
@@ -493,6 +471,9 @@ public function test_parameters(): void
493471
parameters: ['foo' => 'bar'],
494472
);
495473
$this->assertEquals(['foo' => 'bar'], $tool->getParameters());
474+
475+
$tool->setParameters(['foo' => 'baz']);
476+
$this->assertEquals(['foo' => 'baz'], $tool->getParameters());
496477
}
497478

498479
public function test_callback_precedence(): void

0 commit comments

Comments
 (0)