artkit.model.diffusion.base.HTTPXDiffusionConnector#
- class artkit.model.diffusion.base.HTTPXDiffusionConnector(*, model_id, api_key_env=None, initial_delay=None, exponential_base=None, jitter=None, max_retries=None, httpx_client=None, **model_params)[source]#
Abstract base class to represent connecting to a custom endpoint.
- Bases:
DiffusionModelConnector
[AsyncClient
]- Metaclasses:
- Parameters:
model_id (
str
) – the ID of the model to useapi_key_env (
Optional
[str
]) – the environment variable that holds the API key; if not specified, use the default API key environment variable for the model as returned byget_default_api_key_env()
initial_delay (
Optional
[float
]) – the initial delay in seconds between client requests (defaults to1.0
)exponential_base (
Optional
[float
]) – the base for the exponential backoff (defaults to2.0
)jitter (
Optional
[bool
]) – whether to add jitter to the delay (defaults toTrue
)max_retries (
Optional
[int
]) – the maximum number of retries for client requests (defaults to5
) parameters withNone
values are considered unset and will be ignoredhttpx_client (
Optional
[AsyncClient
]) – optional HTTPX client to use for making requests:param model_params: additional model parameters, passed with every request;
Method summary
This method is responsible for formatting the input to the diffusion model.
Get the API key from the environment variable specified by
api_key_env
.Get a shared client instance for this connector; return a cached instance if for this model's API key if available.
Get the default name of the environment variable that holds the API key.
Get the parameters of the model as a mapping.
This method is responsible for formatting the
httpx.Response
after having made the request.Generate an image from text input
Render this object as an expression.
Attribute summary
The ID of the model to use.
url
The environment variable that holds the API key.
The initial delay in seconds between client requests.
The base for the exponential backoff.
Whether to add jitter to the delay.
The maximum number of retries for client requests.
Additional model parameters, passed with every request.
Definitions
- abstract build_request_arguments(text, **model_params)[source]#
This method is responsible for formatting the input to the diffusion model. For argument options see
httpx.AsyncClient.request
.
- get_api_key()#
Get the API key from the environment variable specified by
api_key_env
.- Return type:
- Returns:
the API key
- Raises:
ValueError – if the environment variable is not set
- get_client()#
Get a shared client instance for this connector; return a cached instance if for this model’s API key if available.
- Return type:
- Returns:
the shared client instance
- classmethod get_default_api_key_env()[source]#
Get the default name of the environment variable that holds the API key.
- Return type:
- Returns:
the default name of the api key environment variable
- get_model_params()#
Get the parameters of the model as a mapping.
This includes all parameters that influence the model’s behavior, but not parameters that determine the model itself or are are specific to the client such as the model ID or the API key.
- abstract parse_httpx_response(response)[source]#
This method is responsible for formatting the
httpx.Response
after having made the request.
- to_expression()#
Render this object as an expression.
- Return type:
Expression
- Returns:
the expression representing this object