Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gehrisandro committed Nov 14, 2023
1 parent f27e19f commit aa57a38
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
8 changes: 2 additions & 6 deletions src/Responses/FineTuning/RetrieveJobResponseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ private function __construct(
/**
* Acts as static factory, and returns a new Response instance.
*
* @param array{code: string, param: ?string, message: string}|null $attributes
* @param array{code: string, param: ?string, message: string} $attributes
*/
public static function from(?array $attributes): ?self
public static function from(array $attributes): ?self
{
if (is_null($attributes)) {
return null;
}

return new self(
$attributes['code'],
$attributes['param'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/FineTuning.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function fineTuningJobRetrieveResource(): array
'hyperparameters' => [
'n_epochs' => 9,
'batch_size' => 1,
'learning_rate_multiplier' => 2.0,
'learning_rate_multiplier' => 2.2,
],
'organization_id' => 'org-jwe45798ASN82s',
'result_files' => [
Expand Down
15 changes: 4 additions & 11 deletions tests/Responses/FineTuning/RetrieveJobResponseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
use OpenAI\Responses\FineTuning\RetrieveJobResponseError;

test('from', function () {
$result = \OpenAI\Responses\FineTuning\RetrieveJobResponseError::from(fineTuningJobRetrieveResource()['error']);

expect($result)->toBeNull();
});

test('failed job from', function () {
$result = RetrieveJobResponseError::from(fineTuningFailedJobRetrieveResource()['error']);

expect($result)
Expand All @@ -18,14 +12,13 @@
->message->toBe('Training file has 3 example(s), but must have at least 10 examples');
});

test('to array', function () {
$result = RetrieveJobResponseError::from(fineTuningJobRetrieveResource()['error']);
test('as array accessible', function () {
$result = RetrieveJobResponseError::from(fineTuningFailedJobRetrieveResource()['error']);

expect($result?->toArray())
->toBeNull();
expect($result['code'])->toBe('invalid_n_examples');
});

test('failed job to array', function () {
test('to array', function () {
$result = RetrieveJobResponseError::from(fineTuningFailedJobRetrieveResource()['error']);

expect($result->toArray())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
->toBeInstanceOf(RetrieveJobResponseHyperparameters::class)
->nEpochs->toBe(9)
->batchSize->toBe(1)
->learningRateMultiplier->toBe(2.0);
->learningRateMultiplier->toBe(2.2);
});

test('failed job from', function () {
test('from failed job', function () {
$result = RetrieveJobResponseHyperparameters::from(fineTuningFailedJobRetrieveResource()['hyperparameters']);

expect($result)
Expand All @@ -29,14 +29,14 @@
->toBe(fineTuningJobRetrieveResource()['hyperparameters']);
});

test('failed to array', function () {
test('to array from failed', function () {
$result = RetrieveJobResponseHyperparameters::from(fineTuningFailedJobRetrieveResource()['hyperparameters']);

expect($result->toArray())
->toBe(fineTuningFailedJobRetrieveResource()['hyperparameters']);
});

test('hyperparameters params can be a string', function () {
test('hyperparameters params can be strings', function () {
$result = RetrieveJobResponseHyperparameters::from([
'n_epochs' => 'auto',
'batch_size' => 'auto',
Expand Down

0 comments on commit aa57a38

Please sign in to comment.