Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gehrisandro committed Aug 22, 2023
1 parent 1b4e9a4 commit 90e9e2d
Show file tree
Hide file tree
Showing 31 changed files with 171 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/Contracts/ResponseContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ public function offsetSet(mixed $offset, mixed $value): never;
*/
public function offsetUnset(mixed $offset): never;

// public function meta(): ResponseMetaInformation;
// public function meta(): ResponseMetaInformation;
}
9 changes: 5 additions & 4 deletions src/Resources/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use OpenAI\Responses\Audio\TranscriptionResponse;
use OpenAI\Responses\Audio\TranslationResponse;
use OpenAI\ValueObjects\Transporter\Payload;
use OpenAI\ValueObjects\Transporter\Response;

final class Audio implements AudioContract
{
Expand All @@ -24,7 +25,7 @@ public function transcribe(array $parameters): TranscriptionResponse
{
$payload = Payload::upload('audio/transcriptions', $parameters);

/** @var 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 $result */
/** @var Response<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}> $response */
$response = $this->transporter->requestObject($payload);

return TranscriptionResponse::from($response->data(), $response->meta());
Expand All @@ -41,9 +42,9 @@ public function translate(array $parameters): TranslationResponse
{
$payload = Payload::upload('audio/translations', $parameters);

/** @var 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 $result */
$result = $this->transporter->requestObject($payload);
/** @var Response<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}> $response */
$response = $this->transporter->requestObject($payload);

return TranslationResponse::from($result);
return TranslationResponse::from($response->data(), $response->meta());
}
}
7 changes: 4 additions & 3 deletions src/Resources/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use OpenAI\Responses\Chat\CreateStreamedResponse;
use OpenAI\Responses\StreamResponse;
use OpenAI\ValueObjects\Transporter\Payload;
use OpenAI\ValueObjects\Transporter\Response;

final class Chat implements ChatContract
{
Expand All @@ -28,10 +29,10 @@ public function create(array $parameters): CreateResponse

$payload = Payload::create('chat/completions', $parameters);

/** @var 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}} $result */
$result = $this->transporter->requestObject($payload);
/** @var Response<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}}> $response */
$response = $this->transporter->requestObject($payload);

return CreateResponse::from($result);
return CreateResponse::from($response->data(), $response->meta());
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Resources/Edits.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OpenAI\Contracts\Resources\EditsContract;
use OpenAI\Responses\Edits\CreateResponse;
use OpenAI\ValueObjects\Transporter\Payload;
use OpenAI\ValueObjects\Transporter\Response;

final class Edits implements EditsContract
{
Expand All @@ -23,9 +24,9 @@ public function create(array $parameters): CreateResponse
{
$payload = Payload::create('edits', $parameters);

/** @var array{object: string, created: int, choices: array<int, array{text: string, index: int}>, usage: array{prompt_tokens: int, completion_tokens: int, total_tokens: int}} $result */
$result = $this->transporter->requestObject($payload);
/** @var Response<array{object: string, created: int, choices: array<int, array{text: string, index: int}>, usage: array{prompt_tokens: int, completion_tokens: int, total_tokens: int}}> $response */
$response = $this->transporter->requestObject($payload);

return CreateResponse::from($result);
return CreateResponse::from($response->data(), $response->meta());
}
}
7 changes: 4 additions & 3 deletions src/Resources/Embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OpenAI\Contracts\Resources\EmbeddingsContract;
use OpenAI\Responses\Embeddings\CreateResponse;
use OpenAI\ValueObjects\Transporter\Payload;
use OpenAI\ValueObjects\Transporter\Response;

final class Embeddings implements EmbeddingsContract
{
Expand All @@ -23,9 +24,9 @@ public function create(array $parameters): CreateResponse
{
$payload = Payload::create('embeddings', $parameters);

/** @var array{object: string, data: array<int, array{object: string, embedding: array<int, float>, index: int}>, usage: array{prompt_tokens: int, total_tokens: int}} $result */
$result = $this->transporter->requestObject($payload);
/** @var Response<array{object: string, data: array<int, array{object: string, embedding: array<int, float>, index: int}>, usage: array{prompt_tokens: int, total_tokens: int}}> $response */
$response = $this->transporter->requestObject($payload);

return CreateResponse::from($result);
return CreateResponse::from($response->data(), $response->meta());
}
}
17 changes: 9 additions & 8 deletions src/Resources/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OpenAI\Responses\Files\ListResponse;
use OpenAI\Responses\Files\RetrieveResponse;
use OpenAI\ValueObjects\Transporter\Payload;
use OpenAI\ValueObjects\Transporter\Response;

final class Files implements FilesContract
{
Expand All @@ -24,7 +25,7 @@ public function list(): ListResponse
{
$payload = Payload::list('files');

/** @var 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}>} $result */
/** @var Response<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}>}> $response */
$response = $this->transporter->requestObject($payload);

return ListResponse::from($response->data(), $response->meta());
Expand All @@ -39,10 +40,10 @@ public function retrieve(string $file): RetrieveResponse
{
$payload = Payload::retrieve('files', $file);

/** @var array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null} $result */
$result = $this->transporter->requestObject($payload);
/** @var Response<array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}> $response */
$response = $this->transporter->requestObject($payload);

return RetrieveResponse::from($result);
return RetrieveResponse::from($response->data(), $response->meta());
}

/**
Expand All @@ -68,10 +69,10 @@ public function upload(array $parameters): CreateResponse
{
$payload = Payload::upload('files', $parameters);

/** @var array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null} $result */
$result = $this->transporter->requestObject($payload);
/** @var Response<array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}> $response */
$response = $this->transporter->requestObject($payload);

return CreateResponse::from($result);
return CreateResponse::from($response->data(), $response->meta());
}

/**
Expand All @@ -83,7 +84,7 @@ public function delete(string $file): DeleteResponse
{
$payload = Payload::delete('files', $file);

/** @var array{id: string, object: string, deleted: bool} $response */
/** @var Response<array{id: string, object: string, deleted: bool}> $response */
$response = $this->transporter->requestObject($payload);

return DeleteResponse::from($response->data(), $response->meta());
Expand Down
31 changes: 16 additions & 15 deletions src/Resources/FineTunes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OpenAI\Responses\FineTunes\RetrieveStreamedResponseEvent;
use OpenAI\Responses\StreamResponse;
use OpenAI\ValueObjects\Transporter\Payload;
use OpenAI\ValueObjects\Transporter\Response;

final class FineTunes implements FineTunesContract
{
Expand All @@ -29,10 +30,10 @@ public function create(array $parameters): RetrieveResponse
{
$payload = Payload::create('fine-tunes', $parameters);

/** @var 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} $result */
$result = $this->transporter->requestObject($payload);
/** @var Response<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}> $response */
$response = $this->transporter->requestObject($payload);

return RetrieveResponse::from($result);
return RetrieveResponse::from($response->data(), $response->meta());
}

/**
Expand All @@ -44,10 +45,10 @@ public function list(): ListResponse
{
$payload = Payload::list('fine-tunes');

/** @var 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}>} $result */
$result = $this->transporter->requestObject($payload);
/** @var Response<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}>}> $response */
$response = $this->transporter->requestObject($payload);

return ListResponse::from($result);
return ListResponse::from($response->data(), $response->meta());
}

/**
Expand All @@ -59,10 +60,10 @@ public function retrieve(string $fineTuneId): RetrieveResponse
{
$payload = Payload::retrieve('fine-tunes', $fineTuneId);

/** @var 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} $result */
$result = $this->transporter->requestObject($payload);
/** @var Response<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}> $response */
$response = $this->transporter->requestObject($payload);

return RetrieveResponse::from($result);
return RetrieveResponse::from($response->data(), $response->meta());
}

/**
Expand All @@ -74,10 +75,10 @@ public function cancel(string $fineTuneId): RetrieveResponse
{
$payload = Payload::cancel('fine-tunes', $fineTuneId);

/** @var 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} $result */
$result = $this->transporter->requestObject($payload);
/** @var Response<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}> $response */
$response = $this->transporter->requestObject($payload);

return RetrieveResponse::from($result);
return RetrieveResponse::from($response->data(), $response->meta());
}

/**
Expand All @@ -89,10 +90,10 @@ public function listEvents(string $fineTuneId): ListEventsResponse
{
$payload = Payload::retrieve('fine-tunes', $fineTuneId, '/events');

/** @var array{object: string, data: array<int, array{object: string, created_at: int, level: string, message: string}>} $result */
$result = $this->transporter->requestObject($payload);
/** @var Response<array{object: string, data: array<int, array{object: string, created_at: int, level: string, message: string}>}> $response */
$response = $this->transporter->requestObject($payload);

return ListEventsResponse::from($result);
return ListEventsResponse::from($response->data(), $response->meta());
}

/**
Expand Down
Loading

0 comments on commit 90e9e2d

Please sign in to comment.