From 1f5857b0c8ceea36a3a3f49fcebbfc5548fa31ee Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Mon, 14 Oct 2024 14:48:36 +0200 Subject: [PATCH] add missing file --- src/ollama_utils.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/ollama_utils.py diff --git a/src/ollama_utils.py b/src/ollama_utils.py new file mode 100644 index 0000000..fc80ae6 --- /dev/null +++ b/src/ollama_utils.py @@ -0,0 +1,30 @@ +import requests + +OLLAMA_API_BASE_URL = "http://localhost:11434/api" + +def is_model_available(model_name): + try: + response = requests.get(f"{OLLAMA_API_BASE_URL}/tags") + if response.status_code == 200: + models = response.json().get("models", []) + available_models = [model["name"].split(":")[0] for model in models] + return model_name in available_models + else: + print(f"Error checking model availability: HTTP {response.status_code}") + return False + except requests.RequestException as e: + print(f"Error connecting to Ollama API: {e}") + return False + +def get_available_models(): + try: + response = requests.get(f"{OLLAMA_API_BASE_URL}/tags") + if response.status_code == 200: + models = response.json().get("models", []) + return [model["name"].split(":")[0] for model in models] + else: + print(f"Error fetching available models: HTTP {response.status_code}") + return [] + except requests.RequestException as e: + print(f"Error connecting to Ollama API: {e}") + return []