-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from outl1ne/Virtual-branch
refactor: Add JsonBoolean and JsonInteger classes and update ChatTest
- Loading branch information
Showing
6 changed files
with
141 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Outl1ne\NovaOpenAI\Capabilities\Chat\Parameters\JsonSchema; | ||
|
||
use Outl1ne\NovaOpenAI\Traits\StaticMake; | ||
|
||
class JsonAnyOf implements Arrayable | ||
{ | ||
use StaticMake; | ||
|
||
protected array $schemas = []; | ||
|
||
public function schema(array|Arrayable $schema): self | ||
{ | ||
$this->schemas[] = $schema instanceof Arrayable ? $schema->toArray() : $schema; | ||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'anyOf' => $this->schemas, | ||
]; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Capabilities/Chat/Parameters/JsonSchema/JsonBoolean.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Outl1ne\NovaOpenAI\Capabilities\Chat\Parameters\JsonSchema; | ||
|
||
use Outl1ne\NovaOpenAI\Traits\StaticMake; | ||
|
||
class JsonBoolean implements Arrayable | ||
{ | ||
use StaticMake; | ||
|
||
public function __construct(protected ?string $description = null) {} | ||
|
||
public function toArray(): array | ||
{ | ||
$return = [ | ||
'type' => 'boolean', | ||
]; | ||
|
||
if ($this->description) { | ||
$return['description'] = $this->description; | ||
} | ||
|
||
return $return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Outl1ne\NovaOpenAI\Capabilities\Chat\Parameters\JsonSchema; | ||
|
||
use Exception; | ||
use Outl1ne\NovaOpenAI\Traits\StaticMake; | ||
|
||
class JsonEnum implements Arrayable | ||
{ | ||
use StaticMake; | ||
|
||
public function __construct(protected ?string $description = null, protected ?array $enum = null) {} | ||
|
||
public function enums(array $enum): self | ||
{ | ||
$this->enum = $enum; | ||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
if (!$this->enum) { | ||
throw new Exception('Enum values are required for JsonEnum'); | ||
} | ||
|
||
$return = [ | ||
'type' => 'string', | ||
]; | ||
|
||
if ($this->description) { | ||
$return['description'] = $this->description; | ||
} | ||
|
||
if ($this->enum) { | ||
$return['enum'] = $this->enum; | ||
} | ||
|
||
return $return; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Capabilities/Chat/Parameters/JsonSchema/JsonInteger.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Outl1ne\NovaOpenAI\Capabilities\Chat\Parameters\JsonSchema; | ||
|
||
use Outl1ne\NovaOpenAI\Traits\StaticMake; | ||
|
||
class JsonInteger implements Arrayable | ||
{ | ||
use StaticMake; | ||
|
||
public function __construct(protected ?string $description = null) {} | ||
|
||
public function toArray(): array | ||
{ | ||
$return = [ | ||
'type' => 'integer', | ||
]; | ||
|
||
if ($this->description) { | ||
$return['description'] = $this->description; | ||
} | ||
|
||
return $return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters