File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed
Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change 55namespace GeminiAPI \Resources ;
66
77use GeminiAPI \Enums \FinishReason ;
8+ use GeminiAPI \Enums \Role ;
89use GeminiAPI \Traits \ArrayTypeValidator ;
910use UnexpectedValueException ;
1011
@@ -61,9 +62,17 @@ public static function fromArray(array $candidate): self
6162 $ candidate ['safetyRatings ' ] ?? [],
6263 );
6364
65+ $ content = isset ($ candidate ['content ' ])
66+ ? Content::fromArray ($ candidate ['content ' ])
67+ : Content::text ('' , Role::Model);
68+
69+ $ finishReason = isset ($ candidate ['finishReason ' ])
70+ ? FinishReason::from ($ candidate ['finishReason ' ])
71+ : FinishReason::OTHER ;
72+
6473 return new self (
65- Content:: fromArray ( $ candidate [ ' content ' ]) ,
66- FinishReason:: from ( $ candidate [ ' finishReason ' ]) ,
74+ $ content ,
75+ $ finishReason ,
6776 $ citationMetadata ,
6877 $ safetyRatings ,
6978 $ candidate ['tokenCount ' ] ?? 0 ,
Original file line number Diff line number Diff line change @@ -93,4 +93,31 @@ public function testFromArray()
9393
9494 self ::assertInstanceOf (Candidate::class, $ candidate );
9595 }
96+
97+ public function testFromArrayWithoutContent ()
98+ {
99+ $ candidate = Candidate::fromArray ([
100+ 'safetyRatings ' => [],
101+ 'citationMetadata ' => [],
102+ 'index ' => 1 ,
103+ 'tokenCount ' => 1 ,
104+ 'finishReason ' => 'OTHER ' ,
105+ ]);
106+
107+ self ::assertInstanceOf (Candidate::class, $ candidate );
108+ }
109+
110+ public function testFromArrayWithoutFinishReason ()
111+ {
112+ $ candidate = Candidate::fromArray ([
113+ 'content ' => ['parts ' => [], 'role ' => 'user ' ],
114+ 'safetyRatings ' => [],
115+ 'citationMetadata ' => [],
116+ 'index ' => 1 ,
117+ 'tokenCount ' => 1 ,
118+ ]);
119+
120+ self ::assertInstanceOf (Candidate::class, $ candidate );
121+ self ::assertEquals (FinishReason::OTHER , $ candidate ->finishReason );
122+ }
96123}
You can’t perform that action at this time.
0 commit comments