mirror of
https://github.com/sakaljurgis/actions-api.git
synced 2026-07-08 22:07:40 +00:00
initial commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Google\DTO;
|
||||
|
||||
use App\Services\Google\Error\APIError;
|
||||
|
||||
class ImageGenerationResponse
|
||||
{
|
||||
/**
|
||||
* @var \App\Services\Google\DTO\ImageGenerationPrediction[]
|
||||
*/
|
||||
public readonly array $predictions;
|
||||
public readonly ?APIError $error;
|
||||
|
||||
public function __construct(array $rawResponse)
|
||||
{
|
||||
if (isset($rawResponse['predictions']) && count($rawResponse['predictions']) > 0) {
|
||||
$predictions = [];
|
||||
foreach ($rawResponse['predictions'] as $prediction) {
|
||||
$predictions[] = new ImageGenerationPrediction($prediction['bytesBase64Encoded'], $prediction['mimeType']);
|
||||
}
|
||||
$this->predictions = $predictions;
|
||||
$this->error = null;
|
||||
}
|
||||
|
||||
if (isset($rawResponse['error'])) {
|
||||
$error = $rawResponse['error'];
|
||||
$this->error = new APIError($error['message'], $error['code']);
|
||||
}
|
||||
|
||||
if (!isset($this->predictions) && !isset($this->error)) {
|
||||
$this->error = new APIError('An unknown error occurred.', 0,);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user