Skip to content

Commit

Permalink
Merge pull request #499 from openai-php/fix-fine-tuning-job-response-…
Browse files Browse the repository at this point in the history
…error

Finetuning job response: error is sometimes present but empty
  • Loading branch information
gehrisandro authored Nov 12, 2024
2 parents 5c59196 + 9671194 commit a3b4e44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/Responses/FineTuning/RetrieveJobResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, string>, 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<int, string>, 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
{
Expand All @@ -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,
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/FineTuning/RetrieveJobResponseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
);
}

Expand Down

0 comments on commit a3b4e44

Please sign in to comment.