API Client for interfacing with the Bytez API.
| 4 | |
| 5 | |
| 6 | class Bytez: |
| 7 | """ |
| 8 | API Client for interfacing with the Bytez API. |
| 9 | """ |
| 10 | |
| 11 | def __init__(self, api_key: str, dev: bool = False): |
| 12 | """ |
| 13 | Initialize the Bytez API client with an API key. |
| 14 | |
| 15 | Args: |
| 16 | api_key (str): Your Bytez API key. |
| 17 | dev (bool): Whether to use the development environment. |
| 18 | """ |
| 19 | self._client = Client(api_key, dev) |
| 20 | self.list = self._List(self) # Initialize the list object |
| 21 | |
| 22 | class _List: |
| 23 | """A helper class to expose list functions under `bytez.list`.""" |
| 24 | |
| 25 | def __init__(self, parent): |
| 26 | self._parent = parent # Store reference to the main Bytez instance |
| 27 | |
| 28 | def models(self, options: Optional[Dict[str, str]] = None): |
| 29 | """Lists available models and provides basic information about each.""" |
| 30 | return self._parent._list_models(options) |
| 31 | |
| 32 | def tasks(self): |
| 33 | """List available tasks.""" |
| 34 | return self._parent._list_tasks() |
| 35 | |
| 36 | def _list_models(self, options: Optional[Dict[str, str]] = None): |
| 37 | """Hidden function to list models.""" |
| 38 | query_params = [] |
| 39 | |
| 40 | if options: |
| 41 | if "task" in options: |
| 42 | query_params.append(f"task={options['task']}") |
| 43 | if "modelId" in options: |
| 44 | query_params.append(f"modelId={options['modelId']}") |
| 45 | |
| 46 | query_string = f"?{'&'.join(query_params)}" if query_params else "" |
| 47 | |
| 48 | return self._client.request(f"list/models{query_string}") |
| 49 | |
| 50 | def _list_tasks(self): |
| 51 | """Hidden function to list tasks.""" |
| 52 | return self._client.request("list/tasks") |
| 53 | |
| 54 | def model(self, model_id: str, provider_key: str = None): |
| 55 | """ |
| 56 | Get a model instance. |
| 57 | |
| 58 | Args: |
| 59 | model_id (str): The model ID, e.g., `openai-community/gpt2`. |
| 60 | provider_key (str, optional): Closed-source model provider's API key (e.g. OpenAI key) |
| 61 | |
| 62 | Returns: |
| 63 | Model instance. |
no outgoing calls
no test coverage detected