Skip to content

Commit 31e44d8

Browse files
* added full error messages from the exception
* removed reduant timeout
1 parent b448a4d commit 31e44d8

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

src/Agents/Adapters/Ollama.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ class Ollama extends Adapter
1818
*/
1919
protected string $model;
2020

21-
/**
22-
* @var int
23-
*/
24-
protected int $timeout;
25-
2621
private string $endpoint = 'http://ollama:11434/api/embed';
2722

2823
public const MODELS = [self::MODEL_EMBEDDING_GEMMA];
@@ -45,7 +40,7 @@ public function __construct(
4540
int $timeout = 90
4641
) {
4742
$this->model = $model;
48-
$this->timeout = $timeout;
43+
$this->setTimeout($timeout);
4944
}
5045

5146
/**
@@ -76,8 +71,8 @@ public function embed(string $text): array
7671
);
7772
$body = $response->getBody();
7873
$json = is_string($body) ? json_decode($body, true) : null;
79-
if (! is_array($json) || ! isset($json['embeddings'][0])) {
80-
throw new \Exception('Invalid response from Ollama embed API');
74+
if (isset($json['error'])) {
75+
throw new \Exception($json['error']);
8176
}
8277

8378
return [
@@ -172,9 +167,7 @@ protected function formatErrorMessage($json): string
172167
if (! is_array($json)) {
173168
return '(unknown_error) Unknown error';
174169
}
175-
$msg = $json['error'] ?? ($json['message'] ?? 'Unknown error');
176-
177-
return '(ollama_error) '.$msg;
170+
return $json['error'] ?? ($json['message'] ?? 'Unknown error');
178171
}
179172

180173
/**

0 commit comments

Comments
 (0)