Skip to content

Commit

Permalink
add missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
rbx committed Oct 14, 2024
1 parent f35af12 commit 1f5857b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/ollama_utils.py
Original file line number Diff line number Diff line change
@@ -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 []

0 comments on commit 1f5857b

Please sign in to comment.