From 059475e6bb4df891292fdf8b821b4372257b0cc7 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Mon, 21 Oct 2024 09:31:34 -0500 Subject: [PATCH] add try/except around ollama initialization --- frigate/genai/ollama.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/frigate/genai/ollama.py b/frigate/genai/ollama.py index ae62208cb..e61441eba 100644 --- a/frigate/genai/ollama.py +++ b/frigate/genai/ollama.py @@ -21,12 +21,20 @@ class OllamaClient(GenAIClient): def _init_provider(self): """Initialize the client.""" - client = ApiClient(host=self.genai_config.base_url, timeout=self.timeout) - response = client.pull(self.genai_config.model) - if response["status"] != "success": - logger.error("Failed to pull %s model from Ollama", self.genai_config.model) + try: + client = ApiClient(host=self.genai_config.base_url, timeout=self.timeout) + # ensure the model is available locally + response = client.show(self.genai_config.model) + if response.get("error"): + logger.error( + "Ollama error: %s", + response["error"], + ) + return None + return client + except Exception as e: + logger.warning("Error initializing Ollama: %s", str(e)) return None - return client def _send(self, prompt: str, images: list[bytes]) -> Optional[str]: """Submit a request to Ollama"""