Skip to content

Commit

Permalink
add docs + isort
Browse files Browse the repository at this point in the history
  • Loading branch information
guillesanbri committed Apr 29, 2024
1 parent 341845f commit 8d04f6b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion unify/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Unify python module."""

from unify.clients import AsyncUnify, Unify # noqa: F403
from unify.chat import ChatBot # noqa: F403
from unify.clients import AsyncUnify, Unify # noqa: F403
from unify.utils import list_endpoints, list_models, list_providers
2 changes: 1 addition & 1 deletion unify/chat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from typing import Dict, Generator, List, Optional

from typing import Generator, Optional, List, Dict
from unify.clients import Unify
from unify.exceptions import UnifyError

Expand Down
48 changes: 42 additions & 6 deletions unify/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import requests
import json
from typing import Optional, Tuple, List
import os
from typing import List, Optional, Tuple

import requests
from unify.exceptions import UnifyError

_available_dynamic_modes = [
Expand All @@ -26,16 +26,52 @@ def _res_to_list(response: requests.Response) -> List[str]:


def list_models() -> List[str]:
return _res_to_list(requests.get(_base_url + "/models"))
"""
Get a list of available models.
Returns:
List[str]: A list of available model names if successful, otherwise an empty list.
Raises:
BadRequestError: If there was an HTTP error.
ValueError: If there was an error parsing the JSON response.
"""
url = f"{_base_url}/models"
return _res_to_list(requests.get(url))


def list_endpoints(model: str) -> List[str]:
url = _base_url + "/endpoints_of"
"""
Get a list of endpoints for a specific model.
Args:
model (str): The name of the model.
Returns:
List[str]: A list of endpoint names associated with the model if successful,
otherwise an empty list.
Raises:
BadRequestError: If there was an HTTP error.
ValueError: If there was an error parsing the JSON response.
"""
url = f"{_base_url}/endpoints_of"
return _res_to_list(requests.get(url, params={"model": model}))


def list_providers(model: str) -> List[str]:
url = _base_url + "/providers_of"
"""
Get a list of providers for a specific model.
Args:
model (str): The name of the model.
Returns:
List[str]: A list of provider names associated with the model if successful,
otherwise an empty list.
Raises:
BadRequestError: If there was an HTTP error.
ValueError: If there was an error parsing the JSON response.
"""
url = f"{_base_url}/providers_of"
return _res_to_list(requests.get(url, params={"model": model}))


Expand Down

0 comments on commit 8d04f6b

Please sign in to comment.