diff --git a/app/LlmDriver/Functions/FunctionContract.php b/app/LlmDriver/Functions/FunctionContract.php index 8a142c9b..28644c90 100644 --- a/app/LlmDriver/Functions/FunctionContract.php +++ b/app/LlmDriver/Functions/FunctionContract.php @@ -1,29 +1,44 @@ - $data + * @return array + */ + abstract public function handle(array $data): array; - public function getName(): string + public function getFunction(): FunctionDto { - return $this->name; - } + return FunctionDto::from( + [ + 'name' => $this->getName(), + 'description' => $this->getDescription(), + 'parameters' => $this->getParameters(), + ] + ); - public function getFunction() : FunctionDto { - return new FunctionDto($this->name, $this->getParameters()); - } + protected function getName(): string + { + return $this->name; + } - abstract public function getParameters(): array; + protected function getParameters(): array { + return []; + } - /** - * @param array $data - * @return array - */ - abstract public function handle(array $data): array; -} \ No newline at end of file + protected function getDescription(): string + { + return $this->name; + } +} diff --git a/app/LlmDriver/Functions/FunctionDto.php b/app/LlmDriver/Functions/FunctionDto.php index 32a65bf0..d25c961b 100644 --- a/app/LlmDriver/Functions/FunctionDto.php +++ b/app/LlmDriver/Functions/FunctionDto.php @@ -2,8 +2,6 @@ namespace App\LlmDriver\Functions; -use Spatie\LaravelData\Attributes\WithCastable; - class FunctionDto extends \Spatie\LaravelData\Data { public function __construct( diff --git a/app/LlmDriver/Functions/ParameterCaster.php b/app/LlmDriver/Functions/ParameterCaster.php deleted file mode 100644 index 9c9edb72..00000000 --- a/app/LlmDriver/Functions/ParameterCaster.php +++ /dev/null @@ -1,25 +0,0 @@ - 'bar', 'required' => true, ], - ], + ], ], ] ); - $this->assertNotNull($dto->name); $this->assertNotNull($dto->description); $this->assertInstanceOf(ParametersDto::class, $dto->parameters); @@ -57,7 +54,7 @@ public function test_dto(): void $this->assertEquals([], $parameterOne->enum); $this->assertEquals('', $parameterOne->default); $this->assertFalse($parameterOne->required); - + $parameterTwo = $dto->parameters->parameters[1]; $this->assertInstanceOf(ParameterDto::class, $parameterTwo); $this->assertEquals('test2', $parameterTwo->name);