-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [] |