99use GeminiAPI \Resources \Parts \PartInterface ;
1010use GeminiAPI \Resources \Parts \TextPart ;
1111use GeminiAPI \Resources \PromptFeedback ;
12- use InvalidArgumentException ;
1312use ValueError ;
1413
1514class GenerateContentResponse
@@ -18,11 +17,11 @@ class GenerateContentResponse
1817
1918 /**
2019 * @param Candidate[] $candidates
21- * @param PromptFeedback $promptFeedback
20+ * @param ? PromptFeedback $promptFeedback
2221 */
2322 public function __construct (
2423 public readonly array $ candidates ,
25- public readonly PromptFeedback $ promptFeedback ,
24+ public readonly ? PromptFeedback $ promptFeedback = null ,
2625 ) {
2726 $ this ->ensureArrayOfType ($ candidates , Candidate::class);
2827 }
@@ -72,7 +71,7 @@ public function text(): string
7271 * @param array{
7372 * promptFeedback: array{
7473 * blockReason: string|null,
75- * safetyRatings: array<int, array{category: string, probability: string, blocked: bool|null}>,
74+ * safetyRatings? : array<int, array{category: string, probability: string, blocked: bool|null}>,
7675 * },
7776 * candidates: array<int, array{
7877 * citationMetadata: array{citationSources: array<int, array{startIndex?: int|null, endIndex?: int|null, uri?: string|null, license?: string|null}>},
@@ -87,17 +86,16 @@ public function text(): string
8786 */
8887 public static function fromArray (array $ array ): self
8988 {
90- if (empty ($ array ['promptFeedback ' ]) || !is_array ($ array ['promptFeedback ' ])) {
91- throw new InvalidArgumentException ('invalid promptFeedback ' );
89+ $ promptFeedback = null ;
90+ if (!empty ($ array ['promptFeedback ' ])) {
91+ $ promptFeedback = PromptFeedback::fromArray ($ array ['promptFeedback ' ]);
9292 }
9393
9494 $ candidates = array_map (
9595 static fn (array $ candidate ): Candidate => Candidate::fromArray ($ candidate ),
9696 $ array ['candidates ' ] ?? [],
9797 );
9898
99- $ promptFeedback = PromptFeedback::fromArray ($ array ['promptFeedback ' ]);
100-
10199 return new self ($ candidates , $ promptFeedback );
102100 }
103101}
0 commit comments