Skip to content

Commit

Permalink
WIP: refactor meta information class structure
Browse files Browse the repository at this point in the history
  • Loading branch information
gehrisandro committed Aug 22, 2023
1 parent 0cea6f2 commit 99933a0
Show file tree
Hide file tree
Showing 61 changed files with 187 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @internal
*/
interface ResponseMetaInformationContract extends ArrayAccess
interface MetaInformationContract extends ArrayAccess
{
/**
* Returns the array representation of the meta information.
Expand Down
4 changes: 2 additions & 2 deletions src/Contracts/ResponseHasMetaInformationContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace OpenAI\Contracts;

use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;

interface ResponseHasMetaInformationContract
{
public function meta(): ResponseMetaInformation;
public function meta(): MetaInformation;
}
6 changes: 3 additions & 3 deletions src/Responses/Audio/TranscriptionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenAI\Contracts\ResponseHasMetaInformationContract;
use OpenAI\Responses\Concerns\ArrayAccessible;
use OpenAI\Responses\Concerns\HasMetaInformation;
use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
Expand All @@ -33,7 +33,7 @@ private function __construct(
public readonly ?float $duration,
public readonly array $segments,
public readonly string $text,
private readonly ResponseMetaInformation $meta,
private readonly MetaInformation $meta,
) {
}

Expand All @@ -42,7 +42,7 @@ private function __construct(
*
* @param array{task: ?string, language: ?string, duration: ?float, segments: array<int, array{id: int, seek: int, start: float, end: float, text: string, tokens: array<int, int>, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes
*/
public static function from(array|string $attributes, ResponseMetaInformation $meta): self
public static function from(array|string $attributes, MetaInformation $meta): self
{
if (is_string($attributes)) {
$attributes = ['text' => $attributes];
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/Audio/TranslationResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenAI\Contracts\ResponseHasMetaInformationContract;
use OpenAI\Responses\Concerns\ArrayAccessible;
use OpenAI\Responses\Concerns\HasMetaInformation;
use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
Expand All @@ -33,7 +33,7 @@ private function __construct(
public readonly ?float $duration,
public readonly array $segments,
public readonly string $text,
private readonly ResponseMetaInformation $meta,
private readonly MetaInformation $meta,
) {
}

Expand All @@ -42,7 +42,7 @@ private function __construct(
*
* @param array{task: ?string, language: ?string, duration: ?float, segments: array<int, array{id: int, seek: int, start: float, end: float, text: string, tokens: array<int, int>, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string} $attributes
*/
public static function from(array|string $attributes, ResponseMetaInformation $meta): self
public static function from(array|string $attributes, MetaInformation $meta): self
{
if (is_string($attributes)) {
$attributes = ['text' => $attributes];
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/Chat/CreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenAI\Contracts\ResponseHasMetaInformationContract;
use OpenAI\Responses\Concerns\ArrayAccessible;
use OpenAI\Responses\Concerns\HasMetaInformation;
use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
Expand All @@ -34,7 +34,7 @@ private function __construct(
public readonly string $model,
public readonly array $choices,
public readonly CreateResponseUsage $usage,
private readonly ResponseMetaInformation $meta,
private readonly MetaInformation $meta,
) {
}

Expand All @@ -43,7 +43,7 @@ private function __construct(
*
* @param array{id: string, object: string, created: int, model: string, choices: array<int, array{index: int, message: array{role: string, content: ?string, function_call: ?array{name: string, arguments: string}}, finish_reason: string|null}>, usage: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}} $attributes
*/
public static function from(array $attributes, ResponseMetaInformation $meta): self
public static function from(array $attributes, MetaInformation $meta): self
{
$choices = array_map(fn (array $result): CreateResponseChoice => CreateResponseChoice::from(
$result
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/Completions/CreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenAI\Contracts\ResponseHasMetaInformationContract;
use OpenAI\Responses\Concerns\ArrayAccessible;
use OpenAI\Responses\Concerns\HasMetaInformation;
use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
Expand All @@ -34,7 +34,7 @@ private function __construct(
public readonly string $model,
public readonly array $choices,
public readonly CreateResponseUsage $usage,
private readonly ResponseMetaInformation $meta,
private readonly MetaInformation $meta,
) {
}

Expand All @@ -43,7 +43,7 @@ private function __construct(
*
* @param array{id: string, object: string, created: int, model: string, choices: array<int, array{text: string, index: int, logprobs: array{tokens: array<int, string>, token_logprobs: array<int, float>, top_logprobs: array<int, string>|null, text_offset: array<int, int>}|null, finish_reason: string}>, usage: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}} $attributes
*/
public static function from(array $attributes, ResponseMetaInformation $meta): self
public static function from(array $attributes, MetaInformation $meta): self
{
$choices = array_map(fn (array $result): CreateResponseChoice => CreateResponseChoice::from(
$result
Expand Down
4 changes: 2 additions & 2 deletions src/Responses/Concerns/HasMetaInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace OpenAI\Responses\Concerns;

use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;

trait HasMetaInformation
{
public function meta(): ResponseMetaInformation
public function meta(): MetaInformation
{
return $this->meta;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/Edits/CreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenAI\Contracts\ResponseHasMetaInformationContract;
use OpenAI\Responses\Concerns\ArrayAccessible;
use OpenAI\Responses\Concerns\HasMetaInformation;
use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
Expand All @@ -32,7 +32,7 @@ private function __construct(
public readonly int $created,
public readonly array $choices,
public readonly CreateResponseUsage $usage,
private readonly ResponseMetaInformation $meta,
private readonly MetaInformation $meta,
) {
}

Expand All @@ -41,7 +41,7 @@ private function __construct(
*
* @param array{object: string, created: int, choices: array<int, array{text: string, index: int}>, usage: array{prompt_tokens: int, completion_tokens: int, total_tokens: int}} $attributes
*/
public static function from(array $attributes, ResponseMetaInformation $meta): self
public static function from(array $attributes, MetaInformation $meta): self
{
$choices = array_map(fn (array $result): CreateResponseChoice => CreateResponseChoice::from(
$result
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/Embeddings/CreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenAI\Contracts\ResponseHasMetaInformationContract;
use OpenAI\Responses\Concerns\ArrayAccessible;
use OpenAI\Responses\Concerns\HasMetaInformation;
use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
Expand All @@ -31,7 +31,7 @@ private function __construct(
public readonly string $object,
public readonly array $embeddings,
public readonly CreateResponseUsage $usage,
private readonly ResponseMetaInformation $meta,
private readonly MetaInformation $meta,
) {
}

Expand All @@ -40,7 +40,7 @@ private function __construct(
*
* @param array{object: string, data: array<int, array{object: string, embedding: array<int, float>, index: int}>, usage: array{prompt_tokens: int, total_tokens: int}} $attributes
*/
public static function from(array $attributes, ResponseMetaInformation $meta): self
public static function from(array $attributes, MetaInformation $meta): self
{
$embeddings = array_map(fn (array $result): CreateResponseEmbedding => CreateResponseEmbedding::from(
$result
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/Files/CreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenAI\Contracts\ResponseHasMetaInformationContract;
use OpenAI\Responses\Concerns\ArrayAccessible;
use OpenAI\Responses\Concerns\HasMetaInformation;
use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
Expand Down Expand Up @@ -36,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 MetaInformation $meta,
) {
}

Expand All @@ -45,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<array-key, mixed>|string|null} $attributes
*/
public static function from(array $attributes, ResponseMetaInformation $meta): self
public static function from(array $attributes, MetaInformation $meta): self
{
return new self(
$attributes['id'],
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/Files/DeleteResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenAI\Contracts\ResponseHasMetaInformationContract;
use OpenAI\Responses\Concerns\ArrayAccessible;
use OpenAI\Responses\Concerns\HasMetaInformation;
use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
Expand All @@ -28,7 +28,7 @@ private function __construct(
public readonly string $id,
public readonly string $object,
public readonly bool $deleted,
private readonly ResponseMetaInformation $meta,
private readonly MetaInformation $meta,
) {
}

Expand All @@ -37,7 +37,7 @@ private function __construct(
*
* @param array{id: string, object: string, deleted: bool} $attributes
*/
public static function from(array $attributes, ResponseMetaInformation $meta): self
public static function from(array $attributes, MetaInformation $meta): self
{
return new self(
$attributes['id'],
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/Files/ListResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenAI\Contracts\ResponseHasMetaInformationContract;
use OpenAI\Responses\Concerns\ArrayAccessible;
use OpenAI\Responses\Concerns\HasMetaInformation;
use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
Expand All @@ -30,7 +30,7 @@ final class ListResponse implements ResponseContract, ResponseHasMetaInformation
private function __construct(
public readonly string $object,
public readonly array $data,
private readonly ResponseMetaInformation $meta,
private readonly MetaInformation $meta,
) {
}

Expand All @@ -39,7 +39,7 @@ private function __construct(
*
* @param array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>} $attributes
*/
public static function from(array $attributes, ResponseMetaInformation $meta): self
public static function from(array $attributes, MetaInformation $meta): self
{
$data = array_map(fn (array $result): RetrieveResponse => RetrieveResponse::from(
$result,
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/Files/RetrieveResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenAI\Contracts\ResponseHasMetaInformationContract;
use OpenAI\Responses\Concerns\ArrayAccessible;
use OpenAI\Responses\Concerns\HasMetaInformation;
use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
Expand Down Expand Up @@ -36,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 MetaInformation $meta,
) {
}

Expand All @@ -45,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<array-key, mixed>|string|null} $attributes
*/
public static function from(array $attributes, ResponseMetaInformation $meta): self
public static function from(array $attributes, MetaInformation $meta): self
{
return new self(
$attributes['id'],
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/FineTunes/ListEventsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenAI\Contracts\ResponseHasMetaInformationContract;
use OpenAI\Responses\Concerns\ArrayAccessible;
use OpenAI\Responses\Concerns\HasMetaInformation;
use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
Expand All @@ -30,7 +30,7 @@ final class ListEventsResponse implements ResponseContract, ResponseHasMetaInfor
private function __construct(
public readonly string $object,
public readonly array $data,
private readonly ResponseMetaInformation $meta,
private readonly MetaInformation $meta,
) {
}

Expand All @@ -39,7 +39,7 @@ private function __construct(
*
* @param array{object: string, data: array<int, array{object: string, created_at: int, level: string, message: string}>} $attributes
*/
public static function from(array $attributes, ResponseMetaInformation $meta): self
public static function from(array $attributes, MetaInformation $meta): self
{
$data = array_map(fn (array $result): RetrieveResponseEvent => RetrieveResponseEvent::from(
$result
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/FineTunes/ListResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenAI\Contracts\ResponseHasMetaInformationContract;
use OpenAI\Responses\Concerns\ArrayAccessible;
use OpenAI\Responses\Concerns\HasMetaInformation;
use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
Expand All @@ -30,7 +30,7 @@ final class ListResponse implements ResponseContract, ResponseHasMetaInformation
private function __construct(
public readonly string $object,
public readonly array $data,
private readonly ResponseMetaInformation $meta,
private readonly MetaInformation $meta,
) {
}

Expand All @@ -39,7 +39,7 @@ private function __construct(
*
* @param array{object: string, data: array<int, array{id: string, object: string, model: string, created_at: int, events: array<int, array{object: string, created_at: int, level: string, message: string}>, 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<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>, status: string, validation_files: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>, training_files: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>, updated_at: int}>} $attributes
*/
public static function from(array $attributes, ResponseMetaInformation $meta): self
public static function from(array $attributes, MetaInformation $meta): self
{
$data = array_map(fn (array $result): RetrieveResponse => RetrieveResponse::from(
$result,
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/FineTunes/RetrieveResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use OpenAI\Contracts\ResponseHasMetaInformationContract;
use OpenAI\Responses\Concerns\ArrayAccessible;
use OpenAI\Responses\Concerns\HasMetaInformation;
use OpenAI\Responses\ResponseMetaInformation;
use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
Expand Down Expand Up @@ -44,7 +44,7 @@ private function __construct(
public readonly array $validationFiles,
public readonly array $trainingFiles,
public readonly int $updatedAt,
private readonly ResponseMetaInformation $meta,
private readonly MetaInformation $meta,
) {
}

Expand All @@ -53,7 +53,7 @@ private function __construct(
*
* @param array{id: string, object: string, model: string, created_at: int, events?: array<int, array{object: string, created_at: int, level: string, message: string}>, 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<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>, status: string, validation_files: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>, training_files: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>, updated_at: int} $attributes
*/
public static function from(array $attributes, ResponseMetaInformation $meta): self
public static function from(array $attributes, MetaInformation $meta): self
{
$events = array_map(fn (array $result): RetrieveResponseEvent => RetrieveResponseEvent::from(
$result
Expand Down
Loading

0 comments on commit 99933a0

Please sign in to comment.