Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/api.clients.inference_models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
InferenceModelsClient
=====================

.. autoclass:: hcloud.inference_models.client.InferenceModelsClient
:members:

.. autoclass:: hcloud.inference_models.client.InferenceModelsPageResult
:members:

.. autoclass:: hcloud.inference_models.client.BoundInferenceModel
:members:

.. autoclass:: hcloud.inference_models.domain.InferenceModel
:members:

.. autoclass:: hcloud.inference_models.domain.InferenceModelPrices
:members:

.. autoclass:: hcloud.inference_models.domain.InferenceModelPricesUnits
:members:
17 changes: 17 additions & 0 deletions docs/api.clients.inference_token_types.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
InferenceTokenTypesClient
=========================

.. autoclass:: hcloud.inference_token_types.client.InferenceTokenTypesClient
:members:

.. autoclass:: hcloud.inference_token_types.client.InferenceTokenTypesPageResult
:members:

.. autoclass:: hcloud.inference_token_types.client.BoundInferenceTokenType
:members:

.. autoclass:: hcloud.inference_token_types.domain.InferenceTokenType
:members:

.. autoclass:: hcloud.inference_token_types.domain.InferenceTokenTypePrices
:members:
35 changes: 35 additions & 0 deletions docs/api.clients.inference_tokens.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
InferenceTokensClient
=====================

.. autoclass:: hcloud.inference_tokens.client.InferenceTokensClient
:members:

.. autoclass:: hcloud.inference_tokens.client.InferenceTokensPageResult
:members:

.. autoclass:: hcloud.inference_tokens.client.InferenceTokenModelsPageResult
:members:

.. autoclass:: hcloud.inference_tokens.client.BoundInferenceToken
:members:

.. autoclass:: hcloud.inference_tokens.domain.InferenceToken
:members:

.. autoclass:: hcloud.inference_tokens.domain.InferenceTokenCostCap
:members:

.. autoclass:: hcloud.inference_tokens.domain.InferenceTokenModel
:members:

.. autoclass:: hcloud.inference_tokens.domain.InferenceTokenModelUsages
:members:

.. autoclass:: hcloud.inference_tokens.domain.InferenceTokenModelUsageUnits
:members:

.. autoclass:: hcloud.inference_tokens.domain.InferenceTokenModelUsage
:members:

.. autoclass:: hcloud.inference_tokens.domain.CreateInferenceTokenResponse
:members:
5 changes: 5 additions & 0 deletions docs/api.prices.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Prices
======

.. autoclass:: hcloud.prices.domain.Price
:members:
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ Other

api.helpers
api.deprecation
api.prices
21 changes: 21 additions & 0 deletions hcloud/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from .firewalls import FirewallsClient
from .floating_ips import FloatingIPsClient
from .images import ImagesClient
from .inference_models import InferenceModelsClient
from .inference_token_types import InferenceTokenTypesClient
from .inference_tokens import InferenceTokensClient
from .isos import IsosClient
from .load_balancer_types import LoadBalancerTypesClient
from .load_balancers import LoadBalancersClient
Expand Down Expand Up @@ -289,6 +292,24 @@ def __init__(
:type: :class:`StorageBoxesClient <hcloud.storage_boxes.client.StorageBoxesClient>`
"""

self.inference_models = InferenceModelsClient(self)
"""InferenceModelsClient Instance

:type: :class:`InferenceModelsClient <hcloud.inference_models.client.InferenceModelsClient>`
"""

self.inference_token_types = InferenceTokenTypesClient(self)
"""InferenceTokenTypesClient Instance

:type: :class:`InferenceTokenTypesClient <hcloud.inference_token_types.client.InferenceTokenTypesClient>`
"""

self.inference_tokens = InferenceTokensClient(self)
"""InferenceTokensClient Instance

:type: :class:`InferenceTokensClient <hcloud.inference_tokens.client.InferenceTokensClient>`
"""

def request( # type: ignore[no-untyped-def]
self,
method: str,
Expand Down
21 changes: 21 additions & 0 deletions hcloud/inference_models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from __future__ import annotations

from .client import (
BoundInferenceModel,
InferenceModelsClient,
InferenceModelsPageResult,
)
from .domain import (
InferenceModel,
InferenceModelPrices,
InferenceModelPricesUnits,
)

__all__ = [
"BoundInferenceModel",
"InferenceModel",
"InferenceModelPrices",
"InferenceModelPricesUnits",
"InferenceModelsClient",
"InferenceModelsPageResult",
]
137 changes: 137 additions & 0 deletions hcloud/inference_models/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, NamedTuple

from ..core import BoundModelBase, Meta, ResourceClientBase
from .domain import InferenceModel

if TYPE_CHECKING:
from .._client import Client

__all__ = [
"BoundInferenceModel",
"InferenceModelsPageResult",
"InferenceModelsClient",
]


class BoundInferenceModel(BoundModelBase[InferenceModel], InferenceModel):
_client: InferenceModelsClient

model = InferenceModel


class InferenceModelsPageResult(NamedTuple):
inference_models: list[BoundInferenceModel]
meta: Meta


class InferenceModelsClient(ResourceClientBase):
"""
A client for the Inference Models API.

See https://docs.hetzner.cloud/reference/hetzner#tag/inference-models

Experimental:
Support for the Inference API is experimental, breaking changes may occur within minor releases.
See https://github.com/hetznercloud/hcloud-python/issues/719 for more details.
"""

_base_url = "/inference_models"

def __init__(self, client: Client):
super().__init__(client)
self._client = client._client_hetzner

def get_by_id(self, id: int) -> BoundInferenceModel:
"""
Returns a specific Inference Model.

See https://docs.hetzner.cloud/reference/hetzner#tag/inference-models/get_inference_model

:param id: ID of the Inference Model.

Experimental:
Support for the Inference API is experimental, breaking changes may occur within minor releases.
See https://github.com/hetznercloud/hcloud-python/issues/719 for more details.
"""
response = self._client.request(
method="GET",
url=f"{self._base_url}/{id}",
)
return BoundInferenceModel(self, response["inference_model"])

def get_by_name(self, name: str) -> BoundInferenceModel | None:
"""
Returns a specific Inference Model.

See https://docs.hetzner.cloud/reference/hetzner#tag/inference-models/list_inference_models

:param name: Name of the Inference Model.

Experimental:
Support for the Inference API is experimental, breaking changes may occur within minor releases.
See https://github.com/hetznercloud/hcloud-python/issues/719 for more details.
"""
return self._get_first_by(self.get_list, name=name)

def get_list(
self,
*,
name: str | None = None,
page: int | None = None,
per_page: int | None = None,
) -> InferenceModelsPageResult:
"""
Returns a paginated list of Inference Models for a specific page.

See https://docs.hetzner.cloud/reference/hetzner#tag/inference-models/list_inference_models

:param name: Name of the Inference Model.
:param page: Page number to return.
:param per_page: Maximum number of entries returned per page.

Experimental:
Support for the Inference API is experimental, breaking changes may occur within minor releases.
See https://github.com/hetznercloud/hcloud-python/issues/719 for more details.
"""
params: dict[str, Any] = {}
if name is not None:
params["name"] = name
if page is not None:
params["page"] = page
if per_page is not None:
params["per_page"] = per_page

response = self._client.request(
method="GET",
url=f"{self._base_url}",
params=params,
)
return InferenceModelsPageResult(
inference_models=[
BoundInferenceModel(self, o) for o in response["inference_models"]
],
meta=Meta.parse_meta(response),
)

def get_all(
self,
*,
name: str | None = None,
) -> list[BoundInferenceModel]:
"""
Returns all Inference Models.

See https://docs.hetzner.cloud/reference/hetzner#tag/inference-models/list_inference_models

:param name: Name of the Inference Model.

Experimental:
Support for the Inference API is experimental, breaking changes may occur within minor releases.
See https://github.com/hetznercloud/hcloud-python/issues/719 for more details.
"""
return self._iter_pages(
self.get_list,
name=name,
)
117 changes: 117 additions & 0 deletions hcloud/inference_models/domain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
from __future__ import annotations

from typing import Any

from ..core import BaseDomain, DomainIdentityMixin
from ..deprecation import DeprecationInfo
from ..prices import Price

__all__ = [
"InferenceModel",
"InferenceModelPrices",
"InferenceModelPricesUnits",
]


class InferenceModel(BaseDomain, DomainIdentityMixin):
"""
Inference Model Domain.

See https://docs.hetzner.cloud/reference/hetzner#tag/inference-models

Experimental:
Support for the Inference API is experimental, breaking changes may occur within minor releases.
See https://github.com/hetznercloud/hcloud-python/issues/719 for more details.
"""

__api_properties__ = (
"id",
"name",
"description",
"category",
"tasks",
"quantization",
"parameter_size",
"context_size",
"deprecation",
"prices",
)
__slots__ = __api_properties__

def __init__(
self,
id: int | None = None,
name: str | None = None,
description: str | None = None,
category: str | None = None,
tasks: list[str] | None = None,
quantization: str | None = None,
parameter_size: str | None = None,
context_size: int | None = None,
deprecation: dict[str, Any] | None = None,
prices: dict[str, Any] | None = None,
):
self.id = id
self.name = name
self.description = description
self.category = category
self.quantization = quantization
self.parameter_size = parameter_size
self.context_size = context_size
self.tasks = tasks
self.deprecation = (
DeprecationInfo.from_dict(deprecation) if deprecation is not None else None
)
self.prices = (
InferenceModelPrices.from_dict(prices) if prices is not None else None
)


class InferenceModelPrices(BaseDomain):
"""
Inference Model Prices Domain.

See https://docs.hetzner.cloud/reference/hetzner#tag/inference-models
"""

__api_properties__ = (
"unbatched",
"batched",
)
__slots__ = __api_properties__

def __init__(
self,
unbatched: dict[str, Any],
batched: dict[str, Any],
):
self.unbatched = InferenceModelPricesUnits.from_dict(unbatched)
self.batched = InferenceModelPricesUnits.from_dict(batched)


class InferenceModelPricesUnits(BaseDomain):
"""
Inference Model Prices Units Domain.

See https://docs.hetzner.cloud/reference/hetzner#tag/inference-models
"""

__api_properties__ = (
"input",
"cached",
"output",
"hours",
)
__slots__ = __api_properties__

def __init__(
self,
input: dict[str, Any] | None = None,
cached: dict[str, Any] | None = None,
output: dict[str, Any] | None = None,
hours: dict[str, Any] | None = None,
):
self.input = None if input is None else Price.from_dict(input)
self.cached = None if cached is None else Price.from_dict(cached)
self.output = None if output is None else Price.from_dict(output)
self.hours = None if hours is None else Price.from_dict(hours)
Loading
Loading