Skip to content

Commit

Permalink
add util functions to get models, providers and endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
guillesanbri committed Apr 29, 2024
1 parent 340a30c commit ad43d88
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ unify.set_provider("deepinfra")
### Supported Models
The list of supported models and providers is available in [the platform](https://unify.ai/hub).

You can also get this information directly in Python using `list_models()`, `list_providers()` and `list_endpoints()`.

```python
models = unify.list_models()
providers = unify.list_providers("mistral-7b-instruct-v0.1")
endpoints = unify.list_endpoints("mistral-7b-instruct-v0.1")
```

### API Key
You can get an API Key from [the Unify console](https://console.unify.ai/)

Expand Down
1 change: 1 addition & 0 deletions unify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

from unify.clients import AsyncUnify, Unify # noqa: F403
from unify.chat import ChatBot # noqa: F403
from unify.utils import list_endpoints, list_models, list_providers
17 changes: 17 additions & 0 deletions unify/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import requests
import json
from typing import Optional, Tuple

from unify.exceptions import UnifyError
Expand All @@ -16,6 +18,21 @@
"tks-per-sec",
]

_base_url = "https://api.unify.ai/v0"

def _res_to_list(response):
return json.loads(response.text)

def list_models():
return _res_to_list(requests.get(_base_url + "/models"))

def list_endpoints(model: str):
url = _base_url + "/endpoints_of"
return _res_to_list(requests.get(url, params={"model": model}))

def list_providers(model: str):
url = _base_url + "/providers_of"
return _res_to_list(requests.get(url, params={"model": model}))

def _validate_api_key(api_key: Optional[str]) -> str:
if api_key is None:
Expand Down

0 comments on commit ad43d88

Please sign in to comment.