Skip to content

Commit 62b8776

Browse files
committed
refactor: adjusts function requirements
1 parent e4d5c3f commit 62b8776

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

src/Tools/DTO/FunctionCall.php

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
class FunctionCall implements WithJsonSchemaInterface
1818
{
1919
/**
20-
* @var string Unique identifier for this function call.
20+
* @var string|null Unique identifier for this function call.
2121
*/
22-
private string $id;
22+
private ?string $id;
2323

2424
/**
25-
* @var string The name of the function to call.
25+
* @var string|null The name of the function to call.
2626
*/
27-
private string $name;
27+
private ?string $name;
2828

2929
/**
3030
* @var array<string, mixed> The arguments to pass to the function.
@@ -36,12 +36,17 @@ class FunctionCall implements WithJsonSchemaInterface
3636
*
3737
* @since n.e.x.t
3838
*
39-
* @param string $id Unique identifier for this function call.
40-
* @param string $name The name of the function to call.
39+
* @param string|null $id Unique identifier for this function call.
40+
* @param string|null $name The name of the function to call.
4141
* @param array<string, mixed> $args The arguments to pass to the function.
42+
* @throws \InvalidArgumentException If neither id nor name is provided.
4243
*/
43-
public function __construct(string $id, string $name, array $args)
44+
public function __construct(?string $id = null, ?string $name = null, array $args = [])
4445
{
46+
if ($id === null && $name === null) {
47+
throw new \InvalidArgumentException('At least one of id or name must be provided.');
48+
}
49+
4550
$this->id = $id;
4651
$this->name = $name;
4752
$this->args = $args;
@@ -52,9 +57,9 @@ public function __construct(string $id, string $name, array $args)
5257
*
5358
* @since n.e.x.t
5459
*
55-
* @return string The unique identifier.
60+
* @return string|null The unique identifier.
5661
*/
57-
public function getId(): string
62+
public function getId(): ?string
5863
{
5964
return $this->id;
6065
}
@@ -64,9 +69,9 @@ public function getId(): string
6469
*
6570
* @since n.e.x.t
6671
*
67-
* @return string The function name.
72+
* @return string|null The function name.
6873
*/
69-
public function getName(): string
74+
public function getName(): ?string
7075
{
7176
return $this->name;
7277
}
@@ -107,7 +112,17 @@ public static function getJsonSchema(): array
107112
'additionalProperties' => true,
108113
],
109114
],
110-
'required' => ['id', 'name', 'args'],
115+
'oneOf' => [
116+
[
117+
'required' => ['id'],
118+
],
119+
[
120+
'required' => ['name'],
121+
],
122+
[
123+
'required' => ['id', 'name'],
124+
],
125+
],
111126
];
112127
}
113128
}

src/Tools/DTO/FunctionDeclaration.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FunctionDeclaration implements WithJsonSchemaInterface
2727
private string $description;
2828

2929
/**
30-
* @var mixed The JSON schema for the function parameters.
30+
* @var mixed|null The JSON schema for the function parameters.
3131
*/
3232
private $parameters;
3333

@@ -38,9 +38,9 @@ class FunctionDeclaration implements WithJsonSchemaInterface
3838
*
3939
* @param string $name The name of the function.
4040
* @param string $description A description of what the function does.
41-
* @param mixed $parameters The JSON schema for the function parameters.
41+
* @param mixed|null $parameters The JSON schema for the function parameters.
4242
*/
43-
public function __construct(string $name, string $description, $parameters)
43+
public function __construct(string $name, string $description, $parameters = null)
4444
{
4545
$this->name = $name;
4646
$this->description = $description;
@@ -76,7 +76,7 @@ public function getDescription(): string
7676
*
7777
* @since n.e.x.t
7878
*
79-
* @return mixed The parameters schema.
79+
* @return mixed|null The parameters schema.
8080
*/
8181
public function getParameters()
8282
{
@@ -106,7 +106,7 @@ public static function getJsonSchema(): array
106106
'description' => 'The JSON schema for the function parameters.',
107107
],
108108
],
109-
'required' => ['name', 'description', 'parameters'],
109+
'required' => ['name', 'description'],
110110
];
111111
}
112112
}

0 commit comments

Comments
 (0)