assistant.php
2 years ago
base.php
2 years ago
embed.php
2 years ago
function.php
2 years ago
image.php
2 years ago
parameter.php
2 years ago
text.php
2 years ago
transcribe.php
2 years ago
parameter.php
34 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_Query_Parameter implements JsonSerializable { |
| 4 | public string $name; |
| 5 | public ?string $description; |
| 6 | public ?string $type; |
| 7 | public ?bool $required; |
| 8 | |
| 9 | public function __construct( string $name, ?string $description, |
| 10 | ?string $type = "string", ?bool $required = false ) { |
| 11 | // $name: The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. |
| 12 | if ( !preg_match('/^[a-zA-Z0-9_-]{1,64}$/', $name) ) { |
| 13 | throw new InvalidArgumentException( "Invalid function name." ); |
| 14 | } |
| 15 | |
| 16 | // Make sure the type is valid for JSON Schema. |
| 17 | if ( !in_array( $type, [ 'string', 'number', 'integer', 'boolean', 'array', 'object' ] ) ) { |
| 18 | throw new InvalidArgumentException( "Invalid parameter type ($type) for parameter '$name' in the function '$name'." ); |
| 19 | } |
| 20 | |
| 21 | $this->name = $name; |
| 22 | $this->description = empty( $description ) ? "" : $description; |
| 23 | $this->type = empty( $type ) ? 'string' : $type; |
| 24 | $this->required = empty( $required ) ? false : $required; |
| 25 | } |
| 26 | |
| 27 | #[\ReturnTypeWillChange] |
| 28 | public function jsonSerialize() { |
| 29 | return [ |
| 30 | 'type' => $this->type, |
| 31 | 'description' => $this->description |
| 32 | ]; |
| 33 | } |
| 34 | } |