From 7e1ab5cad66b63e923a70ae4e9a31509802cac04 Mon Sep 17 00:00:00 2001 From: murilo Date: Sat, 8 Feb 2025 13:35:00 -0400 Subject: [PATCH 1/3] Add withResponseMimeType to GenerationConfig --- src/GenerationConfig.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/GenerationConfig.php b/src/GenerationConfig.php index 6eeaca5..2d044f4 100644 --- a/src/GenerationConfig.php +++ b/src/GenerationConfig.php @@ -4,6 +4,7 @@ namespace GeminiAPI; +use GeminiAPI\Enums\MimeType; use GeminiAPI\Traits\ArrayTypeValidator; use JsonSerializable; use UnexpectedValueException; @@ -19,6 +20,7 @@ class GenerationConfig implements JsonSerializable * temperature?: float, * topP?: float, * topK?: int, + * responseMimeType?: string * } */ private array $config; @@ -97,6 +99,14 @@ public function withTopK(int $topK): self return $clone; } + public function withResponseMimeType(MimeType $mimeType) + { + $clone = clone $this; + $clone->config['responseMimeType'] = $mimeType->value; + + return $clone; + } + /** * @return array{ * candidateCount?: int, @@ -105,6 +115,7 @@ public function withTopK(int $topK): self * temperature?: float, * topP?: float, * topK?: int, + * responseMimeType?: string * } */ public function jsonSerialize(): array From fb9add0a81f89ed5ea188df0330d3f21f4b765ba Mon Sep 17 00:00:00 2001 From: murilo Date: Sat, 8 Feb 2025 13:41:26 -0400 Subject: [PATCH 2/3] Add APPLICATION_JSON MimeType --- src/Enums/MimeType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Enums/MimeType.php b/src/Enums/MimeType.php index 71e6775..dceed80 100644 --- a/src/Enums/MimeType.php +++ b/src/Enums/MimeType.php @@ -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'; From cde545a0c69975770c4fe27f2f05f4632b2eaf09 Mon Sep 17 00:00:00 2001 From: murilo Date: Sat, 8 Feb 2025 13:48:11 -0400 Subject: [PATCH 3/3] Add withResponseSchema to GenerationConfig.php --- src/GenerationConfig.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/GenerationConfig.php b/src/GenerationConfig.php index 2d044f4..539ef58 100644 --- a/src/GenerationConfig.php +++ b/src/GenerationConfig.php @@ -20,7 +20,8 @@ class GenerationConfig implements JsonSerializable * temperature?: float, * topP?: float, * topK?: int, - * responseMimeType?: string + * responseMimeType?: string, + * responseSchema?: array * } */ private array $config; @@ -107,6 +108,14 @@ public function withResponseMimeType(MimeType $mimeType) return $clone; } + public function withResponseSchema(array $schema) + { + $clone = clone $this; + $clone->config['responseSchema'] = $schema; + + return $clone; + } + /** * @return array{ * candidateCount?: int, @@ -115,7 +124,8 @@ public function withResponseMimeType(MimeType $mimeType) * temperature?: float, * topP?: float, * topK?: int, - * responseMimeType?: string + * responseMimeType?: string, + * responseSchema?: array * } */ public function jsonSerialize(): array