Skip to content

Commit

Permalink
Fix: nEpochs on RetrieveJobResponseHyperparameters may be string
Browse files Browse the repository at this point in the history
  • Loading branch information
gehrisandro committed Oct 6, 2023
1 parent ff8b3ac commit 6e0d203
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/Resources/FineTuning.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function createJob(array $parameters): RetrieveJobResponse
{
$payload = Payload::create('fine_tuning/jobs', $parameters);

/** @var Response<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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> $response */
/** @var Response<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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> $response */
$response = $this->transporter->requestObject($payload);

return RetrieveJobResponse::from($response->data(), $response->meta());
Expand All @@ -45,7 +45,7 @@ public function listJobs(array $parameters = []): ListJobsResponse
{
$payload = Payload::list('fine_tuning/jobs', $parameters);

/** @var Response<array{object: string, data: array<int, 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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}> $response */
/** @var Response<array{object: string, data: array<int, 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<int, string>, 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());
Expand All @@ -60,7 +60,7 @@ public function retrieveJob(string $jobId): RetrieveJobResponse
{
$payload = Payload::retrieve('fine_tuning/jobs', $jobId);

/** @var Response<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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> $response */
/** @var Response<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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> $response */
$response = $this->transporter->requestObject($payload);

return RetrieveJobResponse::from($response->data(), $response->meta());
Expand All @@ -75,7 +75,7 @@ public function cancelJob(string $jobId): RetrieveJobResponse
{
$payload = Payload::cancel('fine_tuning/jobs', $jobId);

/** @var Response<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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> $response */
/** @var Response<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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}> $response */
$response = $this->transporter->requestObject($payload);

return RetrieveJobResponse::from($response->data(), $response->meta());
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/FineTuning/ListJobsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
* @implements ResponseContract<array{object: string, data: array<int, 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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}>
* @implements ResponseContract<array{object: string, data: array<int, 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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}>
*/
final class ListJobsResponse implements ResponseContract, ResponseHasMetaInformationContract
{
/**
* @use ArrayAccessible<array{object: string, data: array<int, 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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}>
* @use ArrayAccessible<array{object: string, data: array<int, 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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}>
*/
use ArrayAccessible;

Expand All @@ -38,7 +38,7 @@ private function __construct(
/**
* Acts as static factory, and returns a new Response instance.
*
* @param array{object: string, data: array<int, 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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool} $attributes
* @param array{object: string, data: array<int, 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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool} $attributes
*/
public static function from(array $attributes, MetaInformation $meta): self
{
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/FineTuning/RetrieveJobResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
* @implements ResponseContract<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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>
* @implements ResponseContract<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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>
*/
final class RetrieveJobResponse implements ResponseContract, ResponseHasMetaInformationContract
{
/**
* @use ArrayAccessible<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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>
* @use ArrayAccessible<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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>
*/
use ArrayAccessible;

Expand Down 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}, organization_id: string, result_files: array<int, string>, 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<int, string>, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int} $attributes
*/
public static function from(array $attributes, MetaInformation $meta): self
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
use OpenAI\Responses\Concerns\ArrayAccessible;

/**
* @implements ResponseContract<array{n_epochs: int}>
* @implements ResponseContract<array{n_epochs: int|string}>
*/
final class RetrieveJobResponseHyperparameters implements ResponseContract
{
/**
* @use ArrayAccessible<array{n_epochs: int}>
* @use ArrayAccessible<array{n_epochs: int|string}>
*/
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
{
Expand Down
10 changes: 10 additions & 0 deletions tests/Responses/FineTuning/RetrieveJobResponseHyperparameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit 6e0d203

Please sign in to comment.