diff --git a/src/Data/ThinkingConfig.php b/src/Data/ThinkingConfig.php index 750978c..8377b77 100644 --- a/src/Data/ThinkingConfig.php +++ b/src/Data/ThinkingConfig.php @@ -16,38 +16,33 @@ final class ThinkingConfig implements Arrayable { /** * @param bool $includeThoughts Indicates whether to include thoughts in the response. If true, thoughts are returned only when available. - * @param int $thinkingBudget The number of thoughts tokens that the model should generate. + * @param int|null $thinkingBudget The number of thoughts tokens that the model should generate. * @param ThinkingLevel|null $thinkingLevel Controls reasoning behavior. */ public function __construct( public readonly bool $includeThoughts, - public readonly int $thinkingBudget, + public readonly ?int $thinkingBudget = null, public readonly ?ThinkingLevel $thinkingLevel = null, ) {} /** - * @param array{ includeThoughts: bool, thinkingBudget: int, thinkingLevel: ?ThinkingLevel} $attributes + * @param array{ includeThoughts: bool, thinkingBudget?: int, thinkingLevel?: ?ThinkingLevel} $attributes */ public static function from(array $attributes): self { return new self( includeThoughts: $attributes['includeThoughts'], - thinkingBudget: $attributes['thinkingBudget'], + thinkingBudget: $attributes['thinkingBudget'] ?? null, thinkingLevel: $attributes['thinkingLevel'] ?? null ); } public function toArray(): array { - $items = [ + return array_filter([ 'includeThoughts' => $this->includeThoughts, 'thinkingBudget' => $this->thinkingBudget, - ]; - - if ($this->thinkingLevel) { - $items['thinkingLevel'] = $this->thinkingLevel->value; - } - - return $items; + 'thinkingLevel' => $this->thinkingLevel?->value, + ], fn ($value) => $value !== null); } } diff --git a/src/Enums/ThinkingLevel.php b/src/Enums/ThinkingLevel.php index 355a091..afcf092 100644 --- a/src/Enums/ThinkingLevel.php +++ b/src/Enums/ThinkingLevel.php @@ -9,6 +9,8 @@ * * Gemini 3 Pro: low, high * Gemini 3 Flash: minimal, low, medium, high + * + * https://ai.google.dev/gemini-api/docs/thinking#thinking-levels */ enum ThinkingLevel: string {