Skip to content

Commit

Permalink
Print remote models when queried with --models --remote
Browse files Browse the repository at this point in the history
  • Loading branch information
gmertes committed Mar 15, 2024
1 parent 4d065b8 commit 89138c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 13 additions & 1 deletion ai_models/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,19 @@ def _main(argv):
args, unknownargs = parser.parse_known_args(argv)

if args.models:
for p in sorted(available_models()):
if args.remote_execution:
from .remote import RemoteAPI

api = RemoteAPI()
models = api.models()
if len(models) == 0:
print(f"No remote models available on {api.url}")
sys.exit(0)
print(f"Models available on remote server {api.url}:")
else:
models = available_models()

for p in sorted(models):
print(p)
sys.exit(0)

Expand Down
10 changes: 9 additions & 1 deletion ai_models/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ def metadata(self, model, param) -> dict:
else:
raise ValueError("param must be a string, list, or dict with 'param' key.")

def models(self):
results = self._request(requests.get, "models")

if not isinstance(results, list):
return []

return results

def _request(self, type, href, data=None, json=None, auth=None):
response = robust(type, retry_after=30)(
urljoin(self.url, href),
Expand All @@ -229,7 +237,7 @@ def _request(self, type, href, data=None, json=None, auth=None):
try:
data = response.json()

if status := data.get("status"):
if isinstance(data, dict) and (status := data.get("status")):
data["status"] = status.lower()

return data
Expand Down

0 comments on commit 89138c1

Please sign in to comment.