File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,22 +70,18 @@ public function embed(string $text): array
7070 $ payload
7171 );
7272 $ body = $ response ->getBody ();
73- /**
74- * @var array{
75- * error?: string,
76- * embeddings: array<int, array<int, float>>,
77- * total_duration: int,
78- * load_duration: int
79- * }|null $json
80- */
8173 $ json = is_string ($ body ) ? json_decode ($ body , true ) : null ;
8274
75+ if (! is_array ($ json )) {
76+ throw new \Exception ('Invalid response format received from the API ' );
77+ }
78+
8379 if (isset ($ json ['error ' ])) {
8480 throw new \Exception ($ json ['error ' ], $ response ->getStatusCode ());
8581 }
8682
8783 return [
88- 'embedding ' => $ json ['embeddings ' ] ? $ json [ ' embeddings ' ][ 0 ] : [],
84+ 'embedding ' => $ json ['embeddings ' ][ 0 ] ?? [],
8985 'total_duration ' => $ json ['total_duration ' ] ?? null ,
9086 'load_duration ' => $ json ['load_duration ' ] ?? null ,
9187 ];
You can’t perform that action at this time.
0 commit comments