From 18bb36924b7f25095a9d3f47da633327cab1b1d9 Mon Sep 17 00:00:00 2001 From: gehrisandro Date: Tue, 22 Aug 2023 09:54:22 +0200 Subject: [PATCH] WIP: refactor and improve tests --- src/Contracts/ResponseContract.php | 3 --- .../ResponseHasMetaInformationContract.php | 12 ++++++++++ ...hp => ResponseMetaInformationContract.php} | 2 +- src/Responses/Audio/TranscriptionResponse.php | 10 ++++----- src/Responses/Audio/TranslationResponse.php | 10 ++++----- src/Responses/Chat/CreateResponse.php | 10 ++++----- src/Responses/Completions/CreateResponse.php | 10 ++++----- src/Responses/Concerns/HasMetaInformation.php | 15 +++++++++++++ src/Responses/Edits/CreateResponse.php | 10 ++++----- src/Responses/Embeddings/CreateResponse.php | 10 ++++----- src/Responses/Files/CreateResponse.php | 10 ++++----- src/Responses/Files/DeleteResponse.php | 12 +++++----- src/Responses/Files/ListResponse.php | 15 ++++++------- src/Responses/Files/RetrieveResponse.php | 14 +++++------- .../FineTunes/ListEventsResponse.php | 10 ++++----- src/Responses/FineTunes/ListResponse.php | 13 +++++------ src/Responses/FineTunes/RetrieveResponse.php | 14 +++++------- src/Responses/Images/CreateResponse.php | 12 +++++----- src/Responses/Images/EditResponse.php | 12 +++++----- src/Responses/Images/VariationResponse.php | 12 +++++----- src/Responses/Models/DeleteResponse.php | 12 +++++----- src/Responses/Models/ListResponse.php | 12 +++++----- src/Responses/Models/RetrieveResponse.php | 12 +++++----- src/Responses/Moderations/CreateResponse.php | 7 ++++-- src/Responses/ResponseMetaInformation.php | 6 ++--- src/Responses/StreamResponse.php | 3 ++- tests/Resources/Audio.php | 19 ++++++++++++++++ tests/Resources/Chat.php | 10 ++++++++- tests/Resources/Completions.php | 10 ++++++++- tests/Resources/Edits.php | 4 ++++ tests/Resources/Embeddings.php | 4 ++++ tests/Resources/Files.php | 13 +++++++++++ tests/Resources/FineTunes.php | 22 ++++++++++++++++++- tests/Resources/Images.php | 10 +++++++++ tests/Resources/Models.php | 10 +++++++++ tests/Resources/Moderations.php | 4 ++++ .../Responses/Audio/TranscriptionResponse.php | 16 +++++++++----- tests/Responses/Audio/TranslationResponse.php | 16 +++++++++----- tests/Responses/Chat/CreateResponse.php | 7 ++++-- .../Responses/Completions/CreateResponse.php | 4 +++- tests/Responses/Edits/CreateResponse.php | 4 +++- tests/Responses/Embeddings/CreateResponse.php | 4 +++- tests/Responses/Files/CreateResponse.php | 7 ++++-- tests/Responses/Files/DeleteResponse.php | 4 +++- tests/Responses/Files/ListResponse.php | 4 +++- tests/Responses/Files/RetrieveResponse.php | 7 ++++-- .../FineTunes/ListEventsResponse.php | 4 +++- tests/Responses/FineTunes/ListResponse.php | 4 +++- .../Responses/FineTunes/RetrieveResponse.php | 4 +++- tests/Responses/Images/CreateResponse.php | 7 ++++-- tests/Responses/Images/EditResponse.php | 7 ++++-- tests/Responses/Images/VariationResponse.php | 7 ++++-- tests/Responses/Models/DeleteResponse.php | 4 +++- tests/Responses/Models/ListResponse.php | 4 +++- tests/Responses/Models/RetrieveResponse.php | 4 +++- .../Responses/Moderations/CreateResponse.php | 4 +++- 56 files changed, 321 insertions(+), 175 deletions(-) create mode 100644 src/Contracts/ResponseHasMetaInformationContract.php rename src/Contracts/{ResponseMetaContract.php => ResponseMetaInformationContract.php} (94%) create mode 100644 src/Responses/Concerns/HasMetaInformation.php diff --git a/src/Contracts/ResponseContract.php b/src/Contracts/ResponseContract.php index 37c94912..0dfcffea 100644 --- a/src/Contracts/ResponseContract.php +++ b/src/Contracts/ResponseContract.php @@ -5,7 +5,6 @@ namespace OpenAI\Contracts; use ArrayAccess; -use OpenAI\Responses\ResponseMetaInformation; /** * @template TArray of array @@ -50,6 +49,4 @@ public function offsetSet(mixed $offset, mixed $value): never; * @param TOffsetKey $offset */ public function offsetUnset(mixed $offset): never; - - // public function meta(): ResponseMetaInformation; } diff --git a/src/Contracts/ResponseHasMetaInformationContract.php b/src/Contracts/ResponseHasMetaInformationContract.php new file mode 100644 index 00000000..f3e15d30 --- /dev/null +++ b/src/Contracts/ResponseHasMetaInformationContract.php @@ -0,0 +1,12 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> */ -final class TranscriptionResponse implements ResponseContract +final class TranscriptionResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -75,9 +78,4 @@ public function toArray(): array 'text' => $this->text, ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Audio/TranslationResponse.php b/src/Responses/Audio/TranslationResponse.php index 7f2475eb..716378e1 100644 --- a/src/Responses/Audio/TranslationResponse.php +++ b/src/Responses/Audio/TranslationResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Audio; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> */ -final class TranslationResponse implements ResponseContract +final class TranslationResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -75,9 +78,4 @@ public function toArray(): array 'text' => $this->text, ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Chat/CreateResponse.php b/src/Responses/Chat/CreateResponse.php index b2e33020..716243a9 100644 --- a/src/Responses/Chat/CreateResponse.php +++ b/src/Responses/Chat/CreateResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Chat; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract, usage: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}}> */ -final class CreateResponse implements ResponseContract +final class CreateResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible, usage: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -74,9 +77,4 @@ public function toArray(): array 'usage' => $this->usage->toArray(), ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Completions/CreateResponse.php b/src/Responses/Completions/CreateResponse.php index a08221ca..e5326f24 100644 --- a/src/Responses/Completions/CreateResponse.php +++ b/src/Responses/Completions/CreateResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Completions; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract, token_logprobs: array, top_logprobs: array|null, text_offset: array}|null, finish_reason: string|null}>, usage: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}}> */ -final class CreateResponse implements ResponseContract +final class CreateResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible, token_logprobs: array, top_logprobs: array|null, text_offset: array}|null, finish_reason: string|null}>, usage: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -74,9 +77,4 @@ public function toArray(): array 'usage' => $this->usage->toArray(), ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Concerns/HasMetaInformation.php b/src/Responses/Concerns/HasMetaInformation.php new file mode 100644 index 00000000..00a2598d --- /dev/null +++ b/src/Responses/Concerns/HasMetaInformation.php @@ -0,0 +1,15 @@ +meta; + } +} diff --git a/src/Responses/Edits/CreateResponse.php b/src/Responses/Edits/CreateResponse.php index f5aff625..d7e62106 100644 --- a/src/Responses/Edits/CreateResponse.php +++ b/src/Responses/Edits/CreateResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Edits; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract, usage: array{prompt_tokens: int, completion_tokens: int, total_tokens: int}}> */ -final class CreateResponse implements ResponseContract +final class CreateResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible, usage: array{prompt_tokens: int, completion_tokens: int, total_tokens: int}}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -68,9 +71,4 @@ public function toArray(): array 'usage' => $this->usage->toArray(), ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Embeddings/CreateResponse.php b/src/Responses/Embeddings/CreateResponse.php index b0dd7128..6377b596 100644 --- a/src/Responses/Embeddings/CreateResponse.php +++ b/src/Responses/Embeddings/CreateResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Embeddings; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract, index: int}>, usage: array{prompt_tokens: int, total_tokens: int}}> */ -final class CreateResponse implements ResponseContract +final class CreateResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible, index: int}>, usage: array{prompt_tokens: int, total_tokens: int}}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -65,9 +68,4 @@ public function toArray(): array 'usage' => $this->usage->toArray(), ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Files/CreateResponse.php b/src/Responses/Files/CreateResponse.php index 386ce831..6c2c22e3 100644 --- a/src/Responses/Files/CreateResponse.php +++ b/src/Responses/Files/CreateResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Files; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract|string|null}> */ -final class CreateResponse implements ResponseContract +final class CreateResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible|string|null}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -73,9 +76,4 @@ public function toArray(): array 'status_details' => $this->statusDetails, ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Files/DeleteResponse.php b/src/Responses/Files/DeleteResponse.php index 35b20cb3..da839782 100644 --- a/src/Responses/Files/DeleteResponse.php +++ b/src/Responses/Files/DeleteResponse.php @@ -5,27 +5,30 @@ namespace OpenAI\Responses\Files; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract */ -final class DeleteResponse implements ResponseContract +final class DeleteResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; private function __construct( public readonly string $id, public readonly string $object, public readonly bool $deleted, - public readonly ResponseMetaInformation $meta, + private readonly ResponseMetaInformation $meta, ) { } @@ -55,9 +58,4 @@ public function toArray(): array 'deleted' => $this->deleted, ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Files/ListResponse.php b/src/Responses/Files/ListResponse.php index d3d9bf4b..d0fc985f 100644 --- a/src/Responses/Files/ListResponse.php +++ b/src/Responses/Files/ListResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Files; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract|string|null}>}> */ -final class ListResponse implements ResponseContract +final class ListResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible|string|null}>}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -27,7 +30,7 @@ final class ListResponse implements ResponseContract private function __construct( public readonly string $object, public readonly array $data, - public readonly ResponseMetaInformation $meta, + private readonly ResponseMetaInformation $meta, ) { } @@ -39,7 +42,8 @@ private function __construct( public static function from(array $attributes, ResponseMetaInformation $meta): self { $data = array_map(fn (array $result): RetrieveResponse => RetrieveResponse::from( - $result + $result, + $meta, ), $attributes['data']); return new self( @@ -62,9 +66,4 @@ public function toArray(): array ), ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Files/RetrieveResponse.php b/src/Responses/Files/RetrieveResponse.php index 6dc3eb85..a22d1031 100644 --- a/src/Responses/Files/RetrieveResponse.php +++ b/src/Responses/Files/RetrieveResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Files; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract|string|null}> */ -final class RetrieveResponse implements ResponseContract +final class RetrieveResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible|string|null}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -33,7 +36,7 @@ private function __construct( public readonly string $purpose, public readonly string $status, public readonly array|string|null $statusDetails, - private readonly ?ResponseMetaInformation $meta, + private readonly ResponseMetaInformation $meta, ) { } @@ -42,7 +45,7 @@ private function __construct( * * @param array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array|string|null} $attributes */ - public static function from(array $attributes, ResponseMetaInformation $meta = null): self + public static function from(array $attributes, ResponseMetaInformation $meta): self { return new self( $attributes['id'], @@ -73,9 +76,4 @@ public function toArray(): array 'status_details' => $this->statusDetails, ]; } - - public function meta(): ?ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/FineTunes/ListEventsResponse.php b/src/Responses/FineTunes/ListEventsResponse.php index 5e1efd74..2cbc0f51 100644 --- a/src/Responses/FineTunes/ListEventsResponse.php +++ b/src/Responses/FineTunes/ListEventsResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\FineTunes; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract}> */ -final class ListEventsResponse implements ResponseContract +final class ListEventsResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -62,9 +65,4 @@ public function toArray(): array ), ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/FineTunes/ListResponse.php b/src/Responses/FineTunes/ListResponse.php index 6075befa..2d508e69 100644 --- a/src/Responses/FineTunes/ListResponse.php +++ b/src/Responses/FineTunes/ListResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\FineTunes; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract, fine_tuned_model: ?string, hyperparams: array{batch_size: ?int, learning_rate_multiplier: ?float, n_epochs: int, prompt_loss_weight: float}, organization_id: string, result_files: array|string|null}>, status: string, validation_files: array|string|null}>, training_files: array|string|null}>, updated_at: int}>}> */ -final class ListResponse implements ResponseContract +final class ListResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible, fine_tuned_model: ?string, hyperparams: array{batch_size: ?int, learning_rate_multiplier: ?float, n_epochs: int, prompt_loss_weight: float}, organization_id: string, result_files: array|string|null}>, status: string, validation_files: array|string|null}>, training_files: array|string|null}>, updated_at: int}>}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -39,7 +42,8 @@ private function __construct( public static function from(array $attributes, ResponseMetaInformation $meta): self { $data = array_map(fn (array $result): RetrieveResponse => RetrieveResponse::from( - $result + $result, + $meta, ), $attributes['data']); return new self( @@ -62,9 +66,4 @@ public function toArray(): array ), ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/FineTunes/RetrieveResponse.php b/src/Responses/FineTunes/RetrieveResponse.php index 715fbc5f..2861e254 100644 --- a/src/Responses/FineTunes/RetrieveResponse.php +++ b/src/Responses/FineTunes/RetrieveResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\FineTunes; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract, fine_tuned_model: ?string, hyperparams: array{batch_size: ?int, learning_rate_multiplier: ?float, n_epochs: int, prompt_loss_weight: float}, organization_id: string, result_files: array|string|null}>, status: string, validation_files: array|string|null}>, training_files: array|string|null}>, updated_at: int}> */ -final class RetrieveResponse implements ResponseContract +final class RetrieveResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible, fine_tuned_model: ?string, hyperparams: array{batch_size: ?int, learning_rate_multiplier: ?float, n_epochs: int, prompt_loss_weight: float}, organization_id: string, result_files: array|string|null}>, status: string, validation_files: array|string|null}>, training_files: array|string|null}>, updated_at: int}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -41,7 +44,7 @@ private function __construct( public readonly array $validationFiles, public readonly array $trainingFiles, public readonly int $updatedAt, - private readonly ?ResponseMetaInformation $meta, + private readonly ResponseMetaInformation $meta, ) { } @@ -50,7 +53,7 @@ private function __construct( * * @param array{id: string, object: string, model: string, created_at: int, events?: array, fine_tuned_model: ?string, hyperparams: array{batch_size: ?int, learning_rate_multiplier: ?float, n_epochs: int, prompt_loss_weight: float}, organization_id: string, result_files: array|string|null}>, status: string, validation_files: array|string|null}>, training_files: array|string|null}>, updated_at: int} $attributes */ - public static function from(array $attributes, ResponseMetaInformation $meta = null): self + public static function from(array $attributes, ResponseMetaInformation $meta): self { $events = array_map(fn (array $result): RetrieveResponseEvent => RetrieveResponseEvent::from( $result @@ -119,9 +122,4 @@ public function toArray(): array 'updated_at' => $this->updatedAt, ]; } - - public function meta(): ?ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Images/CreateResponse.php b/src/Responses/Images/CreateResponse.php index 3c997eb5..d7bdbff1 100644 --- a/src/Responses/Images/CreateResponse.php +++ b/src/Responses/Images/CreateResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Images; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract}> */ -final class CreateResponse implements ResponseContract +final class CreateResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -27,7 +30,7 @@ final class CreateResponse implements ResponseContract private function __construct( public readonly int $created, public readonly array $data, - public readonly ResponseMetaInformation $meta, + private readonly ResponseMetaInformation $meta, ) { } @@ -62,9 +65,4 @@ public function toArray(): array ), ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Images/EditResponse.php b/src/Responses/Images/EditResponse.php index 38309050..c5c7c74b 100644 --- a/src/Responses/Images/EditResponse.php +++ b/src/Responses/Images/EditResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Images; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract}> */ -final class EditResponse implements ResponseContract +final class EditResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -27,7 +30,7 @@ final class EditResponse implements ResponseContract private function __construct( public readonly int $created, public readonly array $data, - public readonly ResponseMetaInformation $meta, + private readonly ResponseMetaInformation $meta, ) { } @@ -62,9 +65,4 @@ public function toArray(): array ), ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Images/VariationResponse.php b/src/Responses/Images/VariationResponse.php index 7ccedfc3..c591b9d2 100644 --- a/src/Responses/Images/VariationResponse.php +++ b/src/Responses/Images/VariationResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Images; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract}> */ -final class VariationResponse implements ResponseContract +final class VariationResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -27,7 +30,7 @@ final class VariationResponse implements ResponseContract private function __construct( public readonly int $created, public readonly array $data, - public readonly ResponseMetaInformation $meta, + private readonly ResponseMetaInformation $meta, ) { } @@ -62,9 +65,4 @@ public function toArray(): array ), ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Models/DeleteResponse.php b/src/Responses/Models/DeleteResponse.php index 17d588ac..ae83b9f8 100644 --- a/src/Responses/Models/DeleteResponse.php +++ b/src/Responses/Models/DeleteResponse.php @@ -5,27 +5,30 @@ namespace OpenAI\Responses\Models; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract */ -final class DeleteResponse implements ResponseContract +final class DeleteResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; private function __construct( public readonly string $id, public readonly string $object, public readonly bool $deleted, - public readonly ResponseMetaInformation $meta, + private readonly ResponseMetaInformation $meta, ) { } @@ -55,9 +58,4 @@ public function toArray(): array 'deleted' => $this->deleted, ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Models/ListResponse.php b/src/Responses/Models/ListResponse.php index ab59ad4d..774813d9 100644 --- a/src/Responses/Models/ListResponse.php +++ b/src/Responses/Models/ListResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Models; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract, root: string, parent: ?string}>}> */ -final class ListResponse implements ResponseContract +final class ListResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible, root: string, parent: ?string}>}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -27,7 +30,7 @@ final class ListResponse implements ResponseContract private function __construct( public readonly string $object, public readonly array $data, - public readonly ResponseMetaInformation $meta, + private readonly ResponseMetaInformation $meta, ) { } @@ -63,9 +66,4 @@ public function toArray(): array ), ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Models/RetrieveResponse.php b/src/Responses/Models/RetrieveResponse.php index 1a450154..904ec945 100644 --- a/src/Responses/Models/RetrieveResponse.php +++ b/src/Responses/Models/RetrieveResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Models; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract, root: string, parent: ?string}> */ -final class RetrieveResponse implements ResponseContract +final class RetrieveResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible, root: string, parent: ?string}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -32,7 +35,7 @@ private function __construct( public readonly array $permission, public readonly string $root, public readonly ?string $parent, - public readonly ResponseMetaInformation $meta, + private readonly ResponseMetaInformation $meta, ) { } @@ -77,9 +80,4 @@ public function toArray(): array 'parent' => $this->parent, ]; } - - public function meta(): ResponseMetaInformation - { - return $this->meta; - } } diff --git a/src/Responses/Moderations/CreateResponse.php b/src/Responses/Moderations/CreateResponse.php index 26eeacef..4d10d552 100644 --- a/src/Responses/Moderations/CreateResponse.php +++ b/src/Responses/Moderations/CreateResponse.php @@ -5,20 +5,23 @@ namespace OpenAI\Responses\Moderations; use OpenAI\Contracts\ResponseContract; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; +use OpenAI\Responses\Concerns\HasMetaInformation; use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Testing\Responses\Concerns\Fakeable; /** * @implements ResponseContract, category_scores: array, flagged: bool}>}> */ -final class CreateResponse implements ResponseContract +final class CreateResponse implements ResponseContract, ResponseHasMetaInformationContract { /** * @use ArrayAccessible, category_scores: array, flagged: bool}>}> */ use ArrayAccessible; + use HasMetaInformation; use Fakeable; /** @@ -28,7 +31,7 @@ private function __construct( public readonly string $id, public readonly string $model, public readonly array $results, - public readonly ResponseMetaInformation $meta, + private readonly ResponseMetaInformation $meta, ) { } diff --git a/src/Responses/ResponseMetaInformation.php b/src/Responses/ResponseMetaInformation.php index 7b26cfe3..d4f6e841 100644 --- a/src/Responses/ResponseMetaInformation.php +++ b/src/Responses/ResponseMetaInformation.php @@ -2,13 +2,13 @@ namespace OpenAI\Responses; -use OpenAI\Contracts\ResponseMetaContract; +use OpenAI\Contracts\ResponseMetaInformationContract; use OpenAI\Responses\Concerns\ArrayAccessible; /** - * @implements ResponseMetaContract + * @implements ResponseMetaInformationContract */ -final class ResponseMetaInformation implements ResponseMetaContract +final class ResponseMetaInformation implements ResponseMetaInformationContract { /** * @use ArrayAccessible diff --git a/src/Responses/StreamResponse.php b/src/Responses/StreamResponse.php index 121931a3..e5b10832 100644 --- a/src/Responses/StreamResponse.php +++ b/src/Responses/StreamResponse.php @@ -4,6 +4,7 @@ use Generator; use IteratorAggregate; +use OpenAI\Contracts\ResponseHasMetaInformationContract; use OpenAI\Exceptions\ErrorException; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -13,7 +14,7 @@ * * @implements IteratorAggregate */ -final class StreamResponse implements IteratorAggregate +final class StreamResponse implements IteratorAggregate, ResponseHasMetaInformationContract { /** * Creates a new Stream Response instance. diff --git a/tests/Resources/Audio.php b/tests/Resources/Audio.php index c454d955..26bbe18f 100644 --- a/tests/Resources/Audio.php +++ b/tests/Resources/Audio.php @@ -4,6 +4,7 @@ use OpenAI\Responses\Audio\TranscriptionResponseSegment; use OpenAI\Responses\Audio\TranslationResponse; use OpenAI\Responses\Audio\TranslationResponseSegment; +use OpenAI\Responses\ResponseMetaInformation; test('transcribe to text', function () { $client = mockClient('POST', 'audio/transcriptions', [ @@ -25,6 +26,9 @@ ->duration->toBeNull() ->segments->toBeEmpty() ->text->toBe('Hello, how are you?'); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('transcribe to json', function () { @@ -47,6 +51,9 @@ ->duration->toBeNull() ->segments->toBeEmpty() ->text->toBe('Hello, how are you?'); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('transcribe to verbose json', function () { @@ -87,6 +94,9 @@ ->compressionRatio->toBe(0.7037037037037037) ->noSpeechProb->toBe(0.1076972484588623) ->transient->toBeFalse(); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('translate to text', function () { @@ -109,6 +119,9 @@ ->duration->toBeNull() ->segments->toBeEmpty() ->text->toBe('Hello, how are you?'); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('translate to json', function () { @@ -131,6 +144,9 @@ ->duration->toBeNull() ->segments->toBeEmpty() ->text->toBe('Hello, how are you?'); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('translate to verbose json', function () { @@ -171,4 +187,7 @@ ->compressionRatio->toBe(0.7037037037037037) ->noSpeechProb->toBe(0.1076972484588623) ->transient->toBeFalse(); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); diff --git a/tests/Resources/Chat.php b/tests/Resources/Chat.php index 44513ad2..1ab5f597 100644 --- a/tests/Resources/Chat.php +++ b/tests/Resources/Chat.php @@ -7,6 +7,7 @@ use OpenAI\Responses\Chat\CreateResponseUsage; use OpenAI\Responses\Chat\CreateStreamedResponse; use OpenAI\Responses\Chat\CreateStreamedResponseChoice; +use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Responses\StreamResponse; test('create', function () { @@ -41,6 +42,9 @@ ->promptTokens->toBe(9) ->completionTokens->toBe(12) ->totalTokens->toBe(21); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('create throws an exception if stream option is true', function () { @@ -53,7 +57,8 @@ test('create streamed', function () { $response = new Response( - body: new Stream(chatCompletionStream()) + body: new Stream(chatCompletionStream()), + headers: metaHeaders(), ); $client = mockStreamClient('POST', 'chat/completions', [ @@ -89,6 +94,9 @@ ->index->toBe(0) ->logprobs->toBe(null) ->finishReason->toBeNull(); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('handles error messages in stream', function () { diff --git a/tests/Resources/Completions.php b/tests/Resources/Completions.php index 5d2bc68c..14e56847 100644 --- a/tests/Resources/Completions.php +++ b/tests/Resources/Completions.php @@ -7,6 +7,7 @@ use OpenAI\Responses\Completions\CreateResponseChoice; use OpenAI\Responses\Completions\CreateResponseUsage; use OpenAI\Responses\Completions\CreateStreamedResponse; +use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Responses\StreamResponse; test('create', function () { @@ -40,6 +41,9 @@ ->promptTokens->toBe(1) ->completionTokens->toBe(16) ->totalTokens->toBe(17); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('create throws an exception if stream option is true', function () { @@ -52,7 +56,8 @@ test('create streamed', function () { $response = new Response( - body: new Stream(completionStream()) + body: new Stream(completionStream()), + headers: metaHeaders(), ); $client = mockStreamClient('POST', 'completions', [ @@ -87,4 +92,7 @@ ->index->toBe(0) ->logprobs->toBe(null) ->finishReason->toBeNull(); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); diff --git a/tests/Resources/Edits.php b/tests/Resources/Edits.php index 6872b10a..c4d97563 100644 --- a/tests/Resources/Edits.php +++ b/tests/Resources/Edits.php @@ -3,6 +3,7 @@ use OpenAI\Responses\Edits\CreateResponse; use OpenAI\Responses\Edits\CreateResponseChoice; use OpenAI\Responses\Edits\CreateResponseUsage; +use OpenAI\Responses\ResponseMetaInformation; test('create', function () { $client = mockClient('POST', 'edits', [ @@ -33,4 +34,7 @@ ->promptTokens->toBe(25) ->completionTokens->toBe(28) ->totalTokens->toBe(53); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); diff --git a/tests/Resources/Embeddings.php b/tests/Resources/Embeddings.php index ffd1d8cb..608e1a84 100644 --- a/tests/Resources/Embeddings.php +++ b/tests/Resources/Embeddings.php @@ -3,6 +3,7 @@ use OpenAI\Responses\Embeddings\CreateResponse; use OpenAI\Responses\Embeddings\CreateResponseEmbedding; use OpenAI\Responses\Embeddings\CreateResponseUsage; +use OpenAI\Responses\ResponseMetaInformation; test('create', function () { $client = mockClient('POST', 'embeddings', [ @@ -34,4 +35,7 @@ expect($result->usage) ->promptTokens->toBe(8) ->totalTokens->toBe(8); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); diff --git a/tests/Resources/Files.php b/tests/Resources/Files.php index 5ee0ee23..7a6e0461 100644 --- a/tests/Resources/Files.php +++ b/tests/Resources/Files.php @@ -4,6 +4,7 @@ use OpenAI\Responses\Files\DeleteResponse; use OpenAI\Responses\Files\ListResponse; use OpenAI\Responses\Files\RetrieveResponse; +use OpenAI\Responses\ResponseMetaInformation; test('list', function () { $client = mockClient('GET', 'files', [], \OpenAI\ValueObjects\Transporter\Response::from(fileListResource(), metaHeaders())); @@ -15,6 +16,9 @@ ->object->toBe('list') ->data->toBeArray()->toHaveCount(2) ->data->each->toBeInstanceOf(RetrieveResponse::class); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('retrieve', function () { @@ -30,6 +34,9 @@ ->createdAt->toBe(1613779121) ->filename->toBe('mydata.jsonl') ->purpose->toBe('fine-tune'); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('download', function () { @@ -59,6 +66,9 @@ ->createdAt->toBe(1613779121) ->filename->toBe('mydata.jsonl') ->purpose->toBe('fine-tune'); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('delete', function () { @@ -71,4 +81,7 @@ ->id->toBe('file-XjGxS3KTG0uNmNOK362iJua3') ->object->toBe('file') ->deleted->toBe(true); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); diff --git a/tests/Resources/FineTunes.php b/tests/Resources/FineTunes.php index 742d51b0..96a44c4e 100644 --- a/tests/Resources/FineTunes.php +++ b/tests/Resources/FineTunes.php @@ -9,6 +9,7 @@ use OpenAI\Responses\FineTunes\RetrieveResponseFile; use OpenAI\Responses\FineTunes\RetrieveResponseHyperparams; use OpenAI\Responses\FineTunes\RetrieveStreamedResponseEvent; +use OpenAI\Responses\ResponseMetaInformation; use OpenAI\Responses\StreamResponse; test('create', function () { @@ -61,6 +62,9 @@ ->trainingFiles->toBeArray()->toHaveCount(2) ->trainingFiles->each->toBeInstanceOf(RetrieveResponseFile::class) ->updatedAt->toBe(1614807865); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('list', function () { @@ -72,6 +76,9 @@ ->toBeInstanceOf(ListResponse::class) ->data->toBeArray()->toHaveCount(2) ->data->each->toBeInstanceOf(RetrieveResponse::class); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('retrieve', function () { @@ -121,6 +128,9 @@ ->learningRateMultiplier->toBe(0.1) ->nEpochs->toBe(4) ->promptLossWeight->toBe(0.1); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('cancel', function () { @@ -147,6 +157,9 @@ ->trainingFiles->toBeArray()->toHaveCount(2) ->trainingFiles->each->toBeInstanceOf(RetrieveResponseFile::class) ->updatedAt->toBe(1614807865); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('list events', function () { @@ -165,11 +178,15 @@ ->createdAt->toBe(1614807352) ->level->toBe('info') ->message->toBe('Job enqueued. Waiting for jobs ahead to complete. Queue number => 0.'); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('list events streamed', function () { $response = new Response( - body: new Stream(fineTuneListEventsStream()) + body: new Stream(fineTuneListEventsStream()), + headers: metaHeaders(), ); $client = mockStreamClient('GET', 'fine-tunes/ft-MaoEAULREoazpupm8uB7qoIl/events', [], $response); @@ -189,4 +206,7 @@ ->createdAt->toBe(1678253295) ->level->toBe('info') ->message->toBe('Created fine-tune: ft-MaoEAULREoazpupm8uB7qoIl'); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); diff --git a/tests/Resources/Images.php b/tests/Resources/Images.php index 1151ee2b..bf095259 100644 --- a/tests/Resources/Images.php +++ b/tests/Resources/Images.php @@ -6,6 +6,7 @@ use OpenAI\Responses\Images\EditResponseData; use OpenAI\Responses\Images\VariationResponse; use OpenAI\Responses\Images\VariationResponseData; +use OpenAI\Responses\ResponseMetaInformation; test('create', function () { $client = mockClient('POST', 'images/generations', [ @@ -30,6 +31,9 @@ expect($result->data[0]) ->url->toBe('https://openai.com/image.png'); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('edit', function () { @@ -59,6 +63,9 @@ expect($result->data[0]) ->url->toBe('https://openai.com/image.png'); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('variation', function () { @@ -84,4 +91,7 @@ expect($result->data[0]) ->url->toBe('https://openai.com/image.png'); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); diff --git a/tests/Resources/Models.php b/tests/Resources/Models.php index 3775b20c..46542789 100644 --- a/tests/Resources/Models.php +++ b/tests/Resources/Models.php @@ -4,6 +4,7 @@ use OpenAI\Responses\Models\ListResponse; use OpenAI\Responses\Models\RetrieveResponse; use OpenAI\Responses\Models\RetrieveResponsePermission; +use OpenAI\Responses\ResponseMetaInformation; test('list', function () { $client = mockClient('GET', 'models', [], \OpenAI\ValueObjects\Transporter\Response::from(modelList(), metaHeaders())); @@ -18,6 +19,9 @@ expect($result->data[0]) ->id->toBe('text-babbage:001'); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('retrieve', function () { @@ -49,6 +53,9 @@ ->organization->toBe('*') ->group->toBe(null) ->isBlocking->toBe(false); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); test('delete fine tuned model', function () { @@ -61,4 +68,7 @@ ->id->toBe('curie:ft-acmeco-2021-03-03-21-44-20') ->object->toBe('model') ->deleted->toBe(true); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); diff --git a/tests/Resources/Moderations.php b/tests/Resources/Moderations.php index 8d28b737..c485bf79 100644 --- a/tests/Resources/Moderations.php +++ b/tests/Resources/Moderations.php @@ -4,6 +4,7 @@ use OpenAI\Responses\Moderations\CreateResponse; use OpenAI\Responses\Moderations\CreateResponseCategory; use OpenAI\Responses\Moderations\CreateResponseResult; +use OpenAI\Responses\ResponseMetaInformation; use OpenAI\ValueObjects\Transporter\Response; test('create', closure: function () { @@ -38,4 +39,7 @@ ->category->toBe(Category::Violence) ->violated->toBe(true) ->score->toBe(0.9223177433013916); + + expect($result->meta()) + ->toBeInstanceOf(ResponseMetaInformation::class); }); diff --git a/tests/Responses/Audio/TranscriptionResponse.php b/tests/Responses/Audio/TranscriptionResponse.php index 6aa1a8c6..98d4a170 100644 --- a/tests/Responses/Audio/TranscriptionResponse.php +++ b/tests/Responses/Audio/TranscriptionResponse.php @@ -2,6 +2,7 @@ use OpenAI\Responses\Audio\TranscriptionResponse; use OpenAI\Responses\Audio\TranscriptionResponseSegment; +use OpenAI\Responses\ResponseMetaInformation; test('from json', function () { $transcription = TranscriptionResponse::from(audioTranscriptionJson(), meta()); @@ -12,7 +13,8 @@ ->language->toBeNull() ->duration->toBeNull() ->segments->toBeEmpty() - ->text->toBe('Hello, how are you?'); + ->text->toBe('Hello, how are you?') + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('from verbose json', function () { @@ -26,7 +28,8 @@ ->segments->toBeArray() ->segments->toHaveCount(1) ->segments->each->toBeInstanceOf(TranscriptionResponseSegment::class) - ->text->toBe('Hello, how are you?'); + ->text->toBe('Hello, how are you?') + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('from text', function () { @@ -38,7 +41,8 @@ ->language->toBeNull() ->duration->toBeNull() ->segments->toBeEmpty() - ->text->toBe('Hello, how are you?'); + ->text->toBe('Hello, how are you?') + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('from srt', function () { @@ -56,7 +60,8 @@ Hello, how are you? SRT - ); + ) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('from vtt', function () { @@ -75,7 +80,8 @@ Hello, how are you? VTT - ); + ) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/Audio/TranslationResponse.php b/tests/Responses/Audio/TranslationResponse.php index 6a50fb04..9429215d 100644 --- a/tests/Responses/Audio/TranslationResponse.php +++ b/tests/Responses/Audio/TranslationResponse.php @@ -2,6 +2,7 @@ use OpenAI\Responses\Audio\TranslationResponse; use OpenAI\Responses\Audio\TranslationResponseSegment; +use OpenAI\Responses\ResponseMetaInformation; test('from json', function () { $Translation = TranslationResponse::from(audioTranslationJson(), meta()); @@ -12,7 +13,8 @@ ->language->toBeNull() ->duration->toBeNull() ->segments->toBeEmpty() - ->text->toBe('Hello, how are you?'); + ->text->toBe('Hello, how are you?') + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('from verbose json', function () { @@ -26,7 +28,8 @@ ->segments->toBeArray() ->segments->toHaveCount(1) ->segments->each->toBeInstanceOf(TranslationResponseSegment::class) - ->text->toBe('Hello, how are you?'); + ->text->toBe('Hello, how are you?') + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('from text', function () { @@ -38,7 +41,8 @@ ->language->toBeNull() ->duration->toBeNull() ->segments->toBeEmpty() - ->text->toBe('Hello, how are you?'); + ->text->toBe('Hello, how are you?') + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('from srt', function () { @@ -56,7 +60,8 @@ Hello, how are you? SRT - ); + ) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('from vtt', function () { @@ -75,7 +80,8 @@ Hello, how are you? VTT - ); + ) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/Chat/CreateResponse.php b/tests/Responses/Chat/CreateResponse.php index 60638840..ea52eb9f 100644 --- a/tests/Responses/Chat/CreateResponse.php +++ b/tests/Responses/Chat/CreateResponse.php @@ -3,6 +3,7 @@ use OpenAI\Responses\Chat\CreateResponse; use OpenAI\Responses\Chat\CreateResponseChoice; use OpenAI\Responses\Chat\CreateResponseUsage; +use OpenAI\Responses\ResponseMetaInformation; test('from', function () { $completion = CreateResponse::from(chatCompletion(), meta()); @@ -15,7 +16,8 @@ ->model->toBe('gpt-3.5-turbo') ->choices->toBeArray()->toHaveCount(1) ->choices->each->toBeInstanceOf(CreateResponseChoice::class) - ->usage->toBeInstanceOf(CreateResponseUsage::class); + ->usage->toBeInstanceOf(CreateResponseUsage::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('from function response', function () { @@ -29,7 +31,8 @@ ->model->toBe('gpt-3.5-turbo-0613') ->choices->toBeArray()->toHaveCount(1) ->choices->each->toBeInstanceOf(CreateResponseChoice::class) - ->usage->toBeInstanceOf(CreateResponseUsage::class); + ->usage->toBeInstanceOf(CreateResponseUsage::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/Completions/CreateResponse.php b/tests/Responses/Completions/CreateResponse.php index 0b053078..57f2406c 100644 --- a/tests/Responses/Completions/CreateResponse.php +++ b/tests/Responses/Completions/CreateResponse.php @@ -3,6 +3,7 @@ use OpenAI\Responses\Completions\CreateResponse; use OpenAI\Responses\Completions\CreateResponseChoice; use OpenAI\Responses\Completions\CreateResponseUsage; +use OpenAI\Responses\ResponseMetaInformation; test('from', function () { $completion = CreateResponse::from(completion(), meta()); @@ -15,7 +16,8 @@ ->model->toBe('davinci') ->choices->toBeArray()->toHaveCount(1) ->choices->each->toBeInstanceOf(CreateResponseChoice::class) - ->usage->toBeInstanceOf(CreateResponseUsage::class); + ->usage->toBeInstanceOf(CreateResponseUsage::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/Edits/CreateResponse.php b/tests/Responses/Edits/CreateResponse.php index 386846ce..de8b768e 100644 --- a/tests/Responses/Edits/CreateResponse.php +++ b/tests/Responses/Edits/CreateResponse.php @@ -3,6 +3,7 @@ use OpenAI\Responses\Edits\CreateResponse; use OpenAI\Responses\Edits\CreateResponseChoice; use OpenAI\Responses\Edits\CreateResponseUsage; +use OpenAI\Responses\ResponseMetaInformation; test('from', function () { $response = CreateResponse::from(edit(), meta()); @@ -13,7 +14,8 @@ ->created->toBe(1664135921) ->choices->toBeArray()->toHaveCount(1) ->choices->each->toBeInstanceOf(CreateResponseChoice::class) - ->usage->toBeInstanceOf(CreateResponseUsage::class); + ->usage->toBeInstanceOf(CreateResponseUsage::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/Embeddings/CreateResponse.php b/tests/Responses/Embeddings/CreateResponse.php index e4f6170c..0b69d926 100644 --- a/tests/Responses/Embeddings/CreateResponse.php +++ b/tests/Responses/Embeddings/CreateResponse.php @@ -2,6 +2,7 @@ use OpenAI\Responses\Embeddings\CreateResponse; use OpenAI\Responses\Embeddings\CreateResponseEmbedding; +use OpenAI\Responses\ResponseMetaInformation; test('from', function () { $response = CreateResponse::from(embeddingList(), meta()); @@ -10,7 +11,8 @@ ->toBeInstanceOf(CreateResponse::class) ->object->toBe('list') ->embeddings->toBeArray()->toHaveCount(2) - ->embeddings->each->toBeInstanceOf(CreateResponseEmbedding::class); + ->embeddings->each->toBeInstanceOf(CreateResponseEmbedding::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/Files/CreateResponse.php b/tests/Responses/Files/CreateResponse.php index ff4001c7..5eb4b215 100644 --- a/tests/Responses/Files/CreateResponse.php +++ b/tests/Responses/Files/CreateResponse.php @@ -1,6 +1,7 @@ filename->toBe('mydata.jsonl') ->purpose->toBe('fine-tune') ->status->toBe('succeeded') - ->statusDetails->toBeNull(); + ->statusDetails->toBeNull() + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('from with status error', function () { @@ -29,7 +31,8 @@ ->filename->toBe('mydata_corrupt.jsonl') ->purpose->toBe('fine-tune') ->status->toBe('error') - ->statusDetails->toBe("Invalid file format. Example 1273 cannot be parsed. Error: line contains invalid json: Expecting ',' delimiter: line 1 column 79 (char 78) (line 1273)"); + ->statusDetails->toBe("Invalid file format. Example 1273 cannot be parsed. Error: line contains invalid json: Expecting ',' delimiter: line 1 column 79 (char 78) (line 1273)") + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/Files/DeleteResponse.php b/tests/Responses/Files/DeleteResponse.php index 548dd088..fd2c03ca 100644 --- a/tests/Responses/Files/DeleteResponse.php +++ b/tests/Responses/Files/DeleteResponse.php @@ -1,6 +1,7 @@ id->toBe('file-XjGxS3KTG0uNmNOK362iJua3') ->object->toBe('file') - ->deleted->toBe(true); + ->deleted->toBe(true) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/Files/ListResponse.php b/tests/Responses/Files/ListResponse.php index 28aec6af..86bb21ff 100644 --- a/tests/Responses/Files/ListResponse.php +++ b/tests/Responses/Files/ListResponse.php @@ -2,6 +2,7 @@ use OpenAI\Responses\Files\ListResponse; use OpenAI\Responses\Files\RetrieveResponse; +use OpenAI\Responses\ResponseMetaInformation; test('from', function () { $response = ListResponse::from(fileListResource(), meta()); @@ -10,7 +11,8 @@ ->toBeInstanceOf(ListResponse::class) ->object->toBe('list') ->data->toBeArray()->toHaveCount(2) - ->data->each->toBeInstanceOf(RetrieveResponse::class); + ->data->each->toBeInstanceOf(RetrieveResponse::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/Files/RetrieveResponse.php b/tests/Responses/Files/RetrieveResponse.php index ed5766c0..fc574792 100644 --- a/tests/Responses/Files/RetrieveResponse.php +++ b/tests/Responses/Files/RetrieveResponse.php @@ -1,6 +1,7 @@ bytes->toBe(140) ->createdAt->toBe(1613779121) ->filename->toBe('mydata.jsonl') - ->purpose->toBe('fine-tune'); + ->purpose->toBe('fine-tune') + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('from with status error', function () { @@ -27,7 +29,8 @@ ->filename->toBe('mydata_corrupt.jsonl') ->purpose->toBe('fine-tune') ->status->toBe('error') - ->statusDetails->toBe("Invalid file format. Example 1273 cannot be parsed. Error: line contains invalid json: Expecting ',' delimiter: line 1 column 79 (char 78) (line 1273)"); + ->statusDetails->toBe("Invalid file format. Example 1273 cannot be parsed. Error: line contains invalid json: Expecting ',' delimiter: line 1 column 79 (char 78) (line 1273)") + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/FineTunes/ListEventsResponse.php b/tests/Responses/FineTunes/ListEventsResponse.php index f90471b0..d7825b12 100644 --- a/tests/Responses/FineTunes/ListEventsResponse.php +++ b/tests/Responses/FineTunes/ListEventsResponse.php @@ -2,6 +2,7 @@ use OpenAI\Responses\FineTunes\ListEventsResponse; use OpenAI\Responses\FineTunes\RetrieveResponseEvent; +use OpenAI\Responses\ResponseMetaInformation; test('from', function () { $response = ListEventsResponse::from(fineTuneListEventsResource(), meta()); @@ -10,7 +11,8 @@ ->toBeInstanceOf(ListEventsResponse::class) ->object->toBe('list') ->data->toBeArray()->toHaveCount(2) - ->data->each->toBeInstanceOf(RetrieveResponseEvent::class); + ->data->each->toBeInstanceOf(RetrieveResponseEvent::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/FineTunes/ListResponse.php b/tests/Responses/FineTunes/ListResponse.php index 2c11be20..b98b8980 100644 --- a/tests/Responses/FineTunes/ListResponse.php +++ b/tests/Responses/FineTunes/ListResponse.php @@ -2,6 +2,7 @@ use OpenAI\Responses\FineTunes\ListResponse; use OpenAI\Responses\FineTunes\RetrieveResponse; +use OpenAI\Responses\ResponseMetaInformation; test('from', function () { $response = ListResponse::from(fineTuneListResource(), meta()); @@ -10,7 +11,8 @@ ->toBeInstanceOf(ListResponse::class) ->object->toBe('list') ->data->toBeArray()->toHaveCount(2) - ->data->each->toBeInstanceOf(RetrieveResponse::class); + ->data->each->toBeInstanceOf(RetrieveResponse::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/FineTunes/RetrieveResponse.php b/tests/Responses/FineTunes/RetrieveResponse.php index 38479b3f..aca09515 100644 --- a/tests/Responses/FineTunes/RetrieveResponse.php +++ b/tests/Responses/FineTunes/RetrieveResponse.php @@ -4,6 +4,7 @@ use OpenAI\Responses\FineTunes\RetrieveResponseEvent; use OpenAI\Responses\FineTunes\RetrieveResponseFile; use OpenAI\Responses\FineTunes\RetrieveResponseHyperparams; +use OpenAI\Responses\ResponseMetaInformation; test('from', function () { $result = RetrieveResponse::from(fineTuneResource(), meta()); @@ -26,7 +27,8 @@ ->validationFiles->each->toBeInstanceOf(RetrieveResponseFile::class) ->trainingFiles->toBeArray()->toHaveCount(2) ->trainingFiles->each->toBeInstanceOf(RetrieveResponseFile::class) - ->updatedAt->toBe(1614807865); + ->updatedAt->toBe(1614807865) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/Images/CreateResponse.php b/tests/Responses/Images/CreateResponse.php index 8104f17f..7a0a9c7f 100644 --- a/tests/Responses/Images/CreateResponse.php +++ b/tests/Responses/Images/CreateResponse.php @@ -2,6 +2,7 @@ use OpenAI\Responses\Images\CreateResponse; use OpenAI\Responses\Images\CreateResponseData; +use OpenAI\Responses\ResponseMetaInformation; test('from with url', function () { $response = CreateResponse::from(imageCreateWithUrl(), meta()); @@ -10,7 +11,8 @@ ->toBeInstanceOf(CreateResponse::class) ->created->toBe(1664136088) ->data->toBeArray()->toHaveCount(1) - ->data->each->toBeInstanceOf(CreateResponseData::class); + ->data->each->toBeInstanceOf(CreateResponseData::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible with url', function () { @@ -34,7 +36,8 @@ ->toBeInstanceOf(CreateResponse::class) ->created->toBe(1664136088) ->data->toBeArray()->toHaveCount(1) - ->data->each->toBeInstanceOf(CreateResponseData::class); + ->data->each->toBeInstanceOf(CreateResponseData::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible with b64_json', function () { diff --git a/tests/Responses/Images/EditResponse.php b/tests/Responses/Images/EditResponse.php index 7cea9368..84febba1 100644 --- a/tests/Responses/Images/EditResponse.php +++ b/tests/Responses/Images/EditResponse.php @@ -2,6 +2,7 @@ use OpenAI\Responses\Images\EditResponse; use OpenAI\Responses\Images\EditResponseData; +use OpenAI\Responses\ResponseMetaInformation; test('from with url', function () { $response = EditResponse::from(imageEditWithUrl(), meta()); @@ -10,7 +11,8 @@ ->toBeInstanceOf(EditResponse::class) ->created->toBe(1664136088) ->data->toBeArray()->toHaveCount(1) - ->data->each->toBeInstanceOf(EditResponseData::class); + ->data->each->toBeInstanceOf(EditResponseData::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible with url', function () { @@ -34,7 +36,8 @@ ->toBeInstanceOf(EditResponse::class) ->created->toBe(1664136088) ->data->toBeArray()->toHaveCount(1) - ->data->each->toBeInstanceOf(EditResponseData::class); + ->data->each->toBeInstanceOf(EditResponseData::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible with b64_json', function () { diff --git a/tests/Responses/Images/VariationResponse.php b/tests/Responses/Images/VariationResponse.php index 5c9dd739..5acef65b 100644 --- a/tests/Responses/Images/VariationResponse.php +++ b/tests/Responses/Images/VariationResponse.php @@ -2,6 +2,7 @@ use OpenAI\Responses\Images\VariationResponse; use OpenAI\Responses\Images\VariationResponseData; +use OpenAI\Responses\ResponseMetaInformation; test('from with url', function () { $response = VariationResponse::from(imageVariationWithUrl(), meta()); @@ -10,7 +11,8 @@ ->toBeInstanceOf(VariationResponse::class) ->created->toBe(1664136088) ->data->toBeArray()->toHaveCount(1) - ->data->each->toBeInstanceOf(VariationResponseData::class); + ->data->each->toBeInstanceOf(VariationResponseData::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible with url', function () { @@ -34,7 +36,8 @@ ->toBeInstanceOf(VariationResponse::class) ->created->toBe(1664136088) ->data->toBeArray()->toHaveCount(1) - ->data->each->toBeInstanceOf(VariationResponseData::class); + ->data->each->toBeInstanceOf(VariationResponseData::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible with b64_json', function () { diff --git a/tests/Responses/Models/DeleteResponse.php b/tests/Responses/Models/DeleteResponse.php index 90a60fb5..35f6027f 100644 --- a/tests/Responses/Models/DeleteResponse.php +++ b/tests/Responses/Models/DeleteResponse.php @@ -1,6 +1,7 @@ id->toBe('curie:ft-acmeco-2021-03-03-21-44-20') ->object->toBe('model') - ->deleted->toBe(true); + ->deleted->toBe(true) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/Models/ListResponse.php b/tests/Responses/Models/ListResponse.php index b251fccc..0701ff06 100644 --- a/tests/Responses/Models/ListResponse.php +++ b/tests/Responses/Models/ListResponse.php @@ -2,6 +2,7 @@ use OpenAI\Responses\Models\ListResponse; use OpenAI\Responses\Models\RetrieveResponse; +use OpenAI\Responses\ResponseMetaInformation; test('from', function () { $response = ListResponse::from(modelList(), meta()); @@ -10,7 +11,8 @@ ->toBeInstanceOf(ListResponse::class) ->object->toBe('list') ->data->toBeArray()->toHaveCount(2) - ->data->each->toBeInstanceOf(RetrieveResponse::class); + ->data->each->toBeInstanceOf(RetrieveResponse::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/Models/RetrieveResponse.php b/tests/Responses/Models/RetrieveResponse.php index a74bc550..68d6f139 100644 --- a/tests/Responses/Models/RetrieveResponse.php +++ b/tests/Responses/Models/RetrieveResponse.php @@ -2,6 +2,7 @@ use OpenAI\Responses\Models\RetrieveResponse; use OpenAI\Responses\Models\RetrieveResponsePermission; +use OpenAI\Responses\ResponseMetaInformation; test('from', function () { $result = RetrieveResponse::from(model(), meta()); @@ -15,7 +16,8 @@ ->permission->toBeArray()->toHaveCount(1) ->permission->each->toBeInstanceOf(RetrieveResponsePermission::class) ->root->toBe('text-babbage:001') - ->parent->toBe(null); + ->parent->toBe(null) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () { diff --git a/tests/Responses/Moderations/CreateResponse.php b/tests/Responses/Moderations/CreateResponse.php index 26e3ae53..70fc0dba 100644 --- a/tests/Responses/Moderations/CreateResponse.php +++ b/tests/Responses/Moderations/CreateResponse.php @@ -2,6 +2,7 @@ use OpenAI\Responses\Moderations\CreateResponse; use OpenAI\Responses\Moderations\CreateResponseResult; +use OpenAI\Responses\ResponseMetaInformation; test('from', function () { $moderation = CreateResponse::from(moderationResource(), meta()); @@ -11,7 +12,8 @@ ->id->toBe('modr-5MWoLO') ->model->toBe('text-moderation-001') ->results->toBeArray()->toHaveCount(1) - ->results->each->toBeInstanceOf(CreateResponseResult::class); + ->results->each->toBeInstanceOf(CreateResponseResult::class) + ->meta()->toBeInstanceOf(ResponseMetaInformation::class); }); test('as array accessible', function () {