Skip to content

Commit 3d2c158

Browse files
fixed the typings for the json response in the ollama json response
1 parent 22ed668 commit 3d2c158

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/Agents/Adapters/Ollama.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,15 @@ 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-
*/
73+
8174
$json = is_string($body) ? json_decode($body, true) : null;
8275

8376
if (isset($json['error'])) {
8477
throw new \Exception($json['error'], $response->getStatusCode());
8578
}
8679

8780
return [
88-
'embedding' => $json['embeddings'][0],
81+
'embedding' => $json['embeddings'] ? $json['embeddings'][0] : [],
8982
'total_duration' => $json['total_duration'] ?? null,
9083
'load_duration' => $json['load_duration'] ?? null,
9184
];
@@ -173,7 +166,7 @@ public function getName(): string
173166
*/
174167
protected function formatErrorMessage($json): string
175168
{
176-
if (!is_array($json)) {
169+
if (! is_array($json)) {
177170
return '(unknown_error) Unknown error';
178171
}
179172

0 commit comments

Comments
 (0)