Skip to content

Commit 4e96831

Browse files
committed
[Platform] Throw exception when ollama model information cannot be retrieved
1 parent 0407910 commit 4e96831

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/platform/src/Bridge/Ollama/OllamaClient.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,16 @@ public function request(Model $model, array|string $payload, array $options = []
4141
],
4242
]);
4343

44-
$modelInformationsPayload = $response->toArray();
44+
$capabilities = $response->toArray()['capabilities'] ?? null;
45+
46+
if (null === $capabilities) {
47+
throw new InvalidArgumentException('The model information could not be retrieved from the Ollama API. Your Ollama server might be too old. Try upgrade it.');
48+
}
4549

4650
return match (true) {
47-
\in_array('completion', $modelInformationsPayload['capabilities'], true) => $this->doCompletionRequest($payload, $options),
48-
\in_array('embedding', $modelInformationsPayload['capabilities'], true) => $this->doEmbeddingsRequest($model, $payload, $options),
49-
default => throw new InvalidArgumentException(\sprintf('Unsupported model "%s".', $model::class)),
51+
\in_array('completion', $capabilities, true) => $this->doCompletionRequest($payload, $options),
52+
\in_array('embedding', $capabilities, true) => $this->doEmbeddingsRequest($model, $payload, $options),
53+
default => throw new InvalidArgumentException(\sprintf('Unsupported model "%s": "%s".', $model::class, $model->getName())),
5054
};
5155
}
5256

0 commit comments

Comments
 (0)