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,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Google\DTO;
|
||||
|
||||
class ImageGenerationPrediction
|
||||
{
|
||||
public readonly string $bytesBase64Encoded;
|
||||
public readonly string $mimeType;
|
||||
|
||||
public function __construct(string $bytesBase64Encoded, string $mimeType)
|
||||
{
|
||||
$this->bytesBase64Encoded = $bytesBase64Encoded;
|
||||
$this->mimeType = $mimeType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Google\DTO;
|
||||
|
||||
class ImageGenerationRequest
|
||||
{
|
||||
public function __construct(
|
||||
public readonly string $prompt,
|
||||
public readonly ?string $negativePrompt = null,
|
||||
public readonly ?int $sampleCount = null,
|
||||
public readonly ?string $aspectRatio = null,
|
||||
public readonly ?string $safetySetting = null,
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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