Skip to content

Commit

Permalink
fix up the stan
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Mar 30, 2024
1 parent 0ccbe50 commit 87bb67c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 58 deletions.
43 changes: 29 additions & 14 deletions app/LlmDriver/Functions/FunctionContract.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
<?php
<?php

namespace App\LlmDriver\Functions;

abstract class FunctionContract
{
protected string $name;

protected string $dscription;

/**
* @param array<string, mixed> $data
* @return array<string, mixed>
*/
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<string, mixed> $data
* @return array<string, mixed>
*/
abstract public function handle(array $data): array;
}
protected function getDescription(): string
{
return $this->name;
}
}
2 changes: 0 additions & 2 deletions app/LlmDriver/Functions/FunctionDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\LlmDriver\Functions;

use Spatie\LaravelData\Attributes\WithCastable;

class FunctionDto extends \Spatie\LaravelData\Data
{
public function __construct(
Expand Down
25 changes: 0 additions & 25 deletions app/LlmDriver/Functions/ParameterCaster.php

This file was deleted.

6 changes: 2 additions & 4 deletions app/LlmDriver/Functions/ParameterDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

namespace App\LlmDriver\Functions;

use Spatie\LaravelData\Attributes\WithCastable;

class ParameterDto extends \Spatie\LaravelData\Data
{
public function __construct(
public string $name,
public string $description,
public string $type = "string",
public string $type = 'string',
public array $enum = [],
public string $default = "",
public string $default = '',
public bool $required = false,
) {
}
Expand Down
11 changes: 3 additions & 8 deletions app/LlmDriver/Functions/ParametersDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@

namespace App\LlmDriver\Functions;

use Spatie\LaravelData\Attributes\WithCastable;

class ParametersDto extends \Spatie\LaravelData\Data
{

/**
*
* @param string $type
* @param ParameterDto[] $parameters
* @return void
* @param ParameterDto[] $parameters
* @return void
*/
public function __construct(
public string $type = "object",
public string $type = 'object',
public array $parameters = [],
) {
}
Expand Down
7 changes: 2 additions & 5 deletions tests/Feature/FunctionDtoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use App\LlmDriver\Functions\FunctionDto;
use App\LlmDriver\Functions\ParameterDto;
use App\LlmDriver\Functions\ParametersDto;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class FunctionDtoTest extends TestCase
Expand Down Expand Up @@ -39,12 +37,11 @@ public function test_dto(): void
'default' => 'bar',
'required' => true,
],
],
],
],
]
);


$this->assertNotNull($dto->name);
$this->assertNotNull($dto->description);
$this->assertInstanceOf(ParametersDto::class, $dto->parameters);
Expand All @@ -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);
Expand Down

0 comments on commit 87bb67c

Please sign in to comment.