Skip to content

Commit 18afbb5

Browse files
committed
refactor: simplifies GenerativeAiResult::fromArray
1 parent 0f8f66d commit 18afbb5

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/Results/DTO/GenerativeAiResult.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,17 +415,13 @@ public function toArray(): array
415415
*/
416416
public static function fromArray(array $array): GenerativeAiResult
417417
{
418-
$candidatesData = $array['candidates'];
419-
$candidates = array_map(fn(array $candidateData) => Candidate::fromArray($candidateData), $candidatesData);
420-
421-
$tokenUsageData = $array['tokenUsage'];
422-
$providerMetadata = $array['providerMetadata'] ?? [];
418+
$candidates = array_map(fn(array $candidateData) => Candidate::fromArray($candidateData), $array['candidates']);
423419

424420
return new self(
425421
$array['id'],
426422
$candidates,
427-
TokenUsage::fromArray($tokenUsageData),
428-
$providerMetadata
423+
TokenUsage::fromArray($array['tokenUsage']),
424+
$array['providerMetadata'] ?? []
429425
);
430426
}
431427
}

0 commit comments

Comments
 (0)