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'; diff --git a/src/GenerationConfig.php b/src/GenerationConfig.php index 6eeaca5..539ef58 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,8 @@ class GenerationConfig implements JsonSerializable * temperature?: float, * topP?: float, * topK?: int, + * responseMimeType?: string, + * responseSchema?: array * } */ private array $config; @@ -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, @@ -105,6 +124,8 @@ public function withTopK(int $topK): self * temperature?: float, * topP?: float, * topK?: int, + * responseMimeType?: string, + * responseSchema?: array * } */ public function jsonSerialize(): array