From cbbfcb31782dfec1ec0caa6cf1dbaa879d27ad01 Mon Sep 17 00:00:00 2001 From: gehrisandro Date: Fri, 6 Oct 2023 15:42:58 +0200 Subject: [PATCH] Fix: nEpochs on RetrieveJobResponseHyperparameters may be string --- src/Resources/FineTuning.php | 8 ++++---- src/Responses/FineTuning/ListJobsResponse.php | 6 +++--- src/Responses/FineTuning/RetrieveJobResponse.php | 6 +++--- .../FineTuning/RetrieveJobResponseHyperparameters.php | 8 ++++---- .../FineTuning/RetrieveJobResponseHyperparameters.php | 10 ++++++++++ 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Resources/FineTuning.php b/src/Resources/FineTuning.php index 9ddd6293..342e0529 100644 --- a/src/Resources/FineTuning.php +++ b/src/Resources/FineTuning.php @@ -28,7 +28,7 @@ public function createJob(array $parameters): RetrieveJobResponse { $payload = Payload::create('fine_tuning/jobs', $parameters); - /** @var Response, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> $response */ + /** @var Response, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> $response */ $response = $this->transporter->requestObject($payload); return RetrieveJobResponse::from($response->data(), $response->meta()); @@ -45,7 +45,7 @@ public function listJobs(array $parameters = []): ListJobsResponse { $payload = Payload::list('fine_tuning/jobs', $parameters); - /** @var Response, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}> $response */ + /** @var Response, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}> $response */ $response = $this->transporter->requestObject($payload); return ListJobsResponse::from($response->data(), $response->meta()); @@ -60,7 +60,7 @@ public function retrieveJob(string $jobId): RetrieveJobResponse { $payload = Payload::retrieve('fine_tuning/jobs', $jobId); - /** @var Response, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> $response */ + /** @var Response, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> $response */ $response = $this->transporter->requestObject($payload); return RetrieveJobResponse::from($response->data(), $response->meta()); @@ -75,7 +75,7 @@ public function cancelJob(string $jobId): RetrieveJobResponse { $payload = Payload::cancel('fine_tuning/jobs', $jobId); - /** @var Response, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> $response */ + /** @var Response, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> $response */ $response = $this->transporter->requestObject($payload); return RetrieveJobResponse::from($response->data(), $response->meta()); diff --git a/src/Responses/FineTuning/ListJobsResponse.php b/src/Responses/FineTuning/ListJobsResponse.php index 77c259b3..8b2ea959 100644 --- a/src/Responses/FineTuning/ListJobsResponse.php +++ b/src/Responses/FineTuning/ListJobsResponse.php @@ -12,12 +12,12 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @implements ResponseContract, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}> + * @implements ResponseContract, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}> */ final class ListJobsResponse implements ResponseContract, ResponseHasMetaInformationContract { /** - * @use ArrayAccessible, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}> + * @use ArrayAccessible, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}> */ use ArrayAccessible; @@ -38,7 +38,7 @@ private function __construct( /** * Acts as static factory, and returns a new Response instance. * - * @param array{object: string, data: array, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool} $attributes + * @param array{object: string, data: array, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool} $attributes */ public static function from(array $attributes, MetaInformation $meta): self { diff --git a/src/Responses/FineTuning/RetrieveJobResponse.php b/src/Responses/FineTuning/RetrieveJobResponse.php index cd8cefcf..0e5900f6 100644 --- a/src/Responses/FineTuning/RetrieveJobResponse.php +++ b/src/Responses/FineTuning/RetrieveJobResponse.php @@ -12,12 +12,12 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @implements ResponseContract, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> + * @implements ResponseContract, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> */ final class RetrieveJobResponse implements ResponseContract, ResponseHasMetaInformationContract { /** - * @use ArrayAccessible, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> + * @use ArrayAccessible, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> */ use ArrayAccessible; @@ -48,7 +48,7 @@ private function __construct( /** * Acts as static factory, and returns a new Response instance. * - * @param array{id: string, object: string, model: string, created_at: int, finished_at: ?int, fine_tuned_model: ?string, hyperparameters: array{n_epochs: int}, organization_id: string, result_files: array, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int} $attributes + * @param array{id: string, object: string, model: string, created_at: int, finished_at: ?int, fine_tuned_model: ?string, hyperparameters: array{n_epochs: int|string}, organization_id: string, result_files: array, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int} $attributes */ public static function from(array $attributes, MetaInformation $meta): self { diff --git a/src/Responses/FineTuning/RetrieveJobResponseHyperparameters.php b/src/Responses/FineTuning/RetrieveJobResponseHyperparameters.php index c4698317..188b5157 100644 --- a/src/Responses/FineTuning/RetrieveJobResponseHyperparameters.php +++ b/src/Responses/FineTuning/RetrieveJobResponseHyperparameters.php @@ -8,24 +8,24 @@ use OpenAI\Responses\Concerns\ArrayAccessible; /** - * @implements ResponseContract + * @implements ResponseContract */ final class RetrieveJobResponseHyperparameters implements ResponseContract { /** - * @use ArrayAccessible + * @use ArrayAccessible */ use ArrayAccessible; private function __construct( - public readonly int $nEpochs, + public readonly int|string $nEpochs, ) { } /** * Acts as static factory, and returns a new Response instance. * - * @param array{n_epochs: int} $attributes + * @param array{n_epochs: int|string} $attributes */ public static function from(array $attributes): self { diff --git a/tests/Responses/FineTuning/RetrieveJobResponseHyperparameters.php b/tests/Responses/FineTuning/RetrieveJobResponseHyperparameters.php index 8d7eb961..590a89c4 100644 --- a/tests/Responses/FineTuning/RetrieveJobResponseHyperparameters.php +++ b/tests/Responses/FineTuning/RetrieveJobResponseHyperparameters.php @@ -16,3 +16,13 @@ expect($result->toArray()) ->toBe(fineTuningJobRetrieveResource()['hyperparameters']); }); + +test('nEpochs can be a string', function () { + $result = RetrieveJobResponseHyperparameters::from([ + 'n_epochs' => 'auto', + ]); + + expect($result) + ->toBeInstanceOf(RetrieveJobResponseHyperparameters::class) + ->nEpochs->toBe('auto'); +});