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
33 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, string $type = "string", bool $required = false ) { |
| 10 | // $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. |
| 11 | if ( !preg_match('/^[a-zA-Z0-9_-]{1,64}$/', $name) ) { |
| 12 | throw new InvalidArgumentException( "Invalid function name." ); |
| 13 | } |
| 14 | |
| 15 | // Make sure the type is valid for JSON Schema. |
| 16 | if ( !in_array( $type, [ 'string', 'number', 'integer', 'boolean', 'array', 'object' ] ) ) { |
| 17 | throw new InvalidArgumentException( "Invalid parameter type ($type) for parameter '$name' in the function '$name'." ); |
| 18 | } |
| 19 | |
| 20 | $this->name = $name; |
| 21 | $this->description = $description; |
| 22 | $this->type = $type; |
| 23 | $this->required = $required; |
| 24 | } |
| 25 | |
| 26 | #[\ReturnTypeWillChange] |
| 27 | public function jsonSerialize() { |
| 28 | return [ |
| 29 | 'type' => $this->type, |
| 30 | 'description' => $this->description |
| 31 | ]; |
| 32 | } |
| 33 | } |