From 9671194cf43788bc67a06489e50450461c54bbb6 Mon Sep 17 00:00:00 2001 From: Sandro Gehri Date: Tue, 12 Nov 2024 21:10:18 +0100 Subject: [PATCH] Finetuning job response: error is sometimes present but empty --- src/Responses/FineTuning/RetrieveJobResponse.php | 9 +++++++-- src/Responses/FineTuning/RetrieveJobResponseError.php | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Responses/FineTuning/RetrieveJobResponse.php b/src/Responses/FineTuning/RetrieveJobResponse.php index 9db25d22..641148c3 100644 --- a/src/Responses/FineTuning/RetrieveJobResponse.php +++ b/src/Responses/FineTuning/RetrieveJobResponse.php @@ -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|string, batch_size: int|string|null, learning_rate_multiplier: float|string|null}, organization_id: string, result_files: array, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int, error: ?array{code: string, param: ?string, message: string}} $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, batch_size: int|string|null, learning_rate_multiplier: float|string|null}, organization_id: string, result_files: array, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int, error: ?array{code?: string, param?: ?string, message?: string}} $attributes */ public static function from(array $attributes, MetaInformation $meta): self { @@ -66,7 +66,12 @@ public static function from(array $attributes, MetaInformation $meta): self $attributes['validation_file'], $attributes['training_file'], $attributes['trained_tokens'], - isset($attributes['error']) ? RetrieveJobResponseError::from($attributes['error']) : null, + ( + isset($attributes['error']) && + isset($attributes['error']['code']) && + isset($attributes['error']['param']) && + isset($attributes['error']['message']) + ) ? RetrieveJobResponseError::from($attributes['error']) : null, $meta, ); } diff --git a/src/Responses/FineTuning/RetrieveJobResponseError.php b/src/Responses/FineTuning/RetrieveJobResponseError.php index e1ff2ef1..239f9f7c 100644 --- a/src/Responses/FineTuning/RetrieveJobResponseError.php +++ b/src/Responses/FineTuning/RetrieveJobResponseError.php @@ -31,9 +31,9 @@ private function __construct( public static function from(array $attributes): ?self { return new self( - $attributes['code']??"", - $attributes['param']??null, - $attributes['message']??"", + $attributes['code'], + $attributes['param'], + $attributes['message'], ); }