Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhhui committed Oct 10, 2024
2 parents 084b785 + 7a7996b commit eab3d41
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Api/OpenAI/Request/ToolDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Hyperf\Odin\Api\OpenAI\Request;

use Closure;
use Hyperf\Contract\Arrayable;
use InvalidArgumentException;

Expand All @@ -26,15 +27,16 @@ class ToolDefinition implements Arrayable
/**
* @var callable[]
*/
protected array $toolHandler = [];
protected array|Closure $toolHandler = [];

protected array $examples;

public function __construct(
string $name,
string $description = '',
?ToolParameters $parameters = null,
array $examples = [],
callable|array $toolHandler = [],
array|callable|Closure $toolHandler = [],
) {
$this->name = $name;
$this->description = $description;
Expand All @@ -51,7 +53,7 @@ public function toArray(): array
'name' => $this->getName(),
'description' => $this->getDescription(),
'parameters' => $this->getParameters()?->toArray(),
]
],
];
}

Expand All @@ -64,16 +66,16 @@ public function toArrayWithExamples(): array
'description' => $this->getDescription(),
'parameters' => $this->getParameters()?->toArray(),
'examples' => $this->getExamples(),
]
],
];
}

public function getToolHandler(): array
public function getToolHandler(): array|callable|Closure
{
return $this->toolHandler;
}

public function setToolHandler(array|callable $toolHandler): static
public function setToolHandler(array|callable|Closure $toolHandler): static
{
if (! is_callable($toolHandler)) {
throw new InvalidArgumentException('Tool handler must be callable.');
Expand All @@ -87,7 +89,7 @@ public function getName(): string
return $this->name;
}

public function setName(string $name)
public function setName(string $name): static
{
$this->name = $name;
return $this;
Expand Down Expand Up @@ -120,7 +122,7 @@ public function getExamples(): array
return $this->examples;
}

public function setExamples(array $examples)
public function setExamples(array $examples): static
{
$this->examples = $examples;
return $this;
Expand Down

0 comments on commit eab3d41

Please sign in to comment.