From b82953af44ad2be39b9de31f1894f4ffcce395c3 Mon Sep 17 00:00:00 2001 From: Pawansingh3889 Date: Sun, 5 Apr 2026 16:40:29 +0100 Subject: [PATCH] feat: add exists() method to check if model is available locally --- ollama/_client.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ollama/_client.py b/ollama/_client.py index 18cb0fb4..81b2d12c 100644 --- a/ollama/_client.py +++ b/ollama/_client.py @@ -664,6 +664,16 @@ def show(self, model: str) -> ShowResponse: ).model_dump(exclude_none=True), ) + + def exists(self, model: str) -> bool: + """Check if a model is available locally.""" + try: + self.show(model) + return True + except ResponseError: + return False + + def ps(self) -> ProcessResponse: return self._request( ProcessResponse, @@ -1305,6 +1315,16 @@ async def show(self, model: str) -> ShowResponse: ).model_dump(exclude_none=True), ) + + async def exists(self, model: str) -> bool: + """Check if a model is available locally.""" + try: + await self.show(model) + return True + except ResponseError: + return False + + async def ps(self) -> ProcessResponse: return await self._request( ProcessResponse,