Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add responseMimeType and responseSchema to GenerationConfig #65

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Enums/MimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum MimeType: string
case FILE_PDF = 'application/pdf'; // Will not rename to APPLICATION_PDF to keep the backwards compatibility
case APPLICATION_JAVASCRIPT = 'application/x-javascript';
case APPLICATION_PYTHON = 'application/x-python';
case APPLICATION_JSON = 'application/json';

case TEXT_PLAIN = 'text/plain';
case TEXT_HTML = 'text/html';
Expand Down
21 changes: 21 additions & 0 deletions src/GenerationConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace GeminiAPI;

use GeminiAPI\Enums\MimeType;
use GeminiAPI\Traits\ArrayTypeValidator;
use JsonSerializable;
use UnexpectedValueException;
Expand All @@ -19,6 +20,8 @@ class GenerationConfig implements JsonSerializable
* temperature?: float,
* topP?: float,
* topK?: int,
* responseMimeType?: string,
* responseSchema?: array
* }
*/
private array $config;
Expand Down Expand Up @@ -97,6 +100,22 @@ public function withTopK(int $topK): self
return $clone;
}

public function withResponseMimeType(MimeType $mimeType)
{
$clone = clone $this;
$clone->config['responseMimeType'] = $mimeType->value;

return $clone;
}

public function withResponseSchema(array $schema)
{
$clone = clone $this;
$clone->config['responseSchema'] = $schema;

return $clone;
}

/**
* @return array{
* candidateCount?: int,
Expand All @@ -105,6 +124,8 @@ public function withTopK(int $topK): self
* temperature?: float,
* topP?: float,
* topK?: int,
* responseMimeType?: string,
* responseSchema?: array
* }
*/
public function jsonSerialize(): array
Expand Down