From 80c30736ae2e272efe4febbb6ca41a48e7f6b986 Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Fri, 11 Apr 2025 09:14:15 +0400 Subject: [PATCH] Revert "Add back inference.inference API (#2873)" (#2899) This reverts commit eac539dcc301b6062716f1540dc0d1efe888671c. This API will be added back through the specification and isn't deprecated anymore. (cherry picked from commit 0f845eaa78427c37231fdd43e0cb549c2acc72f1) --- elasticsearch/_async/client/inference.py | 119 +---------------------- elasticsearch/_sync/client/inference.py | 119 +---------------------- elasticsearch/_sync/client/utils.py | 7 -- 3 files changed, 2 insertions(+), 243 deletions(-) diff --git a/elasticsearch/_async/client/inference.py b/elasticsearch/_async/client/inference.py index c2ca3ef33..b86740319 100644 --- a/elasticsearch/_async/client/inference.py +++ b/elasticsearch/_async/client/inference.py @@ -20,13 +20,7 @@ from elastic_transport import ObjectApiResponse from ._base import NamespacedClient -from .utils import ( - SKIP_IN_PATH, - Stability, - _quote, - _rewrite_parameters, - _stability_warning, -) +from .utils import SKIP_IN_PATH, _quote, _rewrite_parameters class InferenceClient(NamespacedClient): @@ -240,117 +234,6 @@ async def get( path_parts=__path_parts, ) - @_rewrite_parameters( - body_fields=("input", "query", "task_settings"), - ) - @_stability_warning( - Stability.DEPRECATED, - version="8.18.0", - message="inference.inference() is deprecated in favor of provider-specific APIs such as inference.put_elasticsearch() or inference.put_hugging_face()", - ) - async def inference( - self, - *, - inference_id: str, - input: t.Optional[t.Union[str, t.Sequence[str]]] = None, - task_type: t.Optional[ - t.Union[ - str, - t.Literal[ - "chat_completion", - "completion", - "rerank", - "sparse_embedding", - "text_embedding", - ], - ] - ] = None, - error_trace: t.Optional[bool] = None, - filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None, - human: t.Optional[bool] = None, - pretty: t.Optional[bool] = None, - query: t.Optional[str] = None, - task_settings: t.Optional[t.Any] = None, - timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None, - body: t.Optional[t.Dict[str, t.Any]] = None, - ) -> ObjectApiResponse[t.Any]: - """ - .. raw:: html - -

Perform inference on the service.

-

This API enables you to use machine learning models to perform specific tasks on data that you provide as an input. - It returns a response with the results of the tasks. - The inference endpoint you use can perform one specific task that has been defined when the endpoint was created with the create inference API.

-
-

info - The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face. For built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models. However, if you do not plan to use the inference APIs to use these models or if you want to use non-NLP models, use the machine learning trained model APIs.

-
- - - ``_ - - :param inference_id: The unique identifier for the inference endpoint. - :param input: The text on which you want to perform the inference task. It can - be a single string or an array. > info > Inference endpoints for the `completion` - task type currently only support a single string as input. - :param task_type: The type of inference task that the model performs. - :param query: The query input, which is required only for the `rerank` task. - It is not required for other tasks. - :param task_settings: Task settings for the individual inference request. These - settings are specific to the task type you specified and override the task - settings specified when initializing the service. - :param timeout: The amount of time to wait for the inference request to complete. - """ - if inference_id in SKIP_IN_PATH: - raise ValueError("Empty value passed for parameter 'inference_id'") - if input is None and body is None: - raise ValueError("Empty value passed for parameter 'input'") - __path_parts: t.Dict[str, str] - if task_type not in SKIP_IN_PATH and inference_id not in SKIP_IN_PATH: - __path_parts = { - "task_type": _quote(task_type), - "inference_id": _quote(inference_id), - } - __path = f'/_inference/{__path_parts["task_type"]}/{__path_parts["inference_id"]}' - elif inference_id not in SKIP_IN_PATH: - __path_parts = {"inference_id": _quote(inference_id)} - __path = f'/_inference/{__path_parts["inference_id"]}' - else: - raise ValueError("Couldn't find a path for the given parameters") - __query: t.Dict[str, t.Any] = {} - __body: t.Dict[str, t.Any] = body if body is not None else {} - if error_trace is not None: - __query["error_trace"] = error_trace - if filter_path is not None: - __query["filter_path"] = filter_path - if human is not None: - __query["human"] = human - if pretty is not None: - __query["pretty"] = pretty - if timeout is not None: - __query["timeout"] = timeout - if not __body: - if input is not None: - __body["input"] = input - if query is not None: - __body["query"] = query - if task_settings is not None: - __body["task_settings"] = task_settings - if not __body: - __body = None # type: ignore[assignment] - __headers = {"accept": "application/json"} - if __body is not None: - __headers["content-type"] = "application/json" - return await self.perform_request( # type: ignore[return-value] - "POST", - __path, - params=__query, - headers=__headers, - body=__body, - endpoint_id="inference.inference", - path_parts=__path_parts, - ) - @_rewrite_parameters( body_name="inference_config", ) diff --git a/elasticsearch/_sync/client/inference.py b/elasticsearch/_sync/client/inference.py index 5bfe426da..c98a22de8 100644 --- a/elasticsearch/_sync/client/inference.py +++ b/elasticsearch/_sync/client/inference.py @@ -20,13 +20,7 @@ from elastic_transport import ObjectApiResponse from ._base import NamespacedClient -from .utils import ( - SKIP_IN_PATH, - Stability, - _quote, - _rewrite_parameters, - _stability_warning, -) +from .utils import SKIP_IN_PATH, _quote, _rewrite_parameters class InferenceClient(NamespacedClient): @@ -240,117 +234,6 @@ def get( path_parts=__path_parts, ) - @_rewrite_parameters( - body_fields=("input", "query", "task_settings"), - ) - @_stability_warning( - Stability.DEPRECATED, - version="8.18.0", - message="inference.inference() is deprecated in favor of provider-specific APIs such as inference.put_elasticsearch() or inference.put_hugging_face()", - ) - def inference( - self, - *, - inference_id: str, - input: t.Optional[t.Union[str, t.Sequence[str]]] = None, - task_type: t.Optional[ - t.Union[ - str, - t.Literal[ - "chat_completion", - "completion", - "rerank", - "sparse_embedding", - "text_embedding", - ], - ] - ] = None, - error_trace: t.Optional[bool] = None, - filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None, - human: t.Optional[bool] = None, - pretty: t.Optional[bool] = None, - query: t.Optional[str] = None, - task_settings: t.Optional[t.Any] = None, - timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None, - body: t.Optional[t.Dict[str, t.Any]] = None, - ) -> ObjectApiResponse[t.Any]: - """ - .. raw:: html - -

Perform inference on the service.

-

This API enables you to use machine learning models to perform specific tasks on data that you provide as an input. - It returns a response with the results of the tasks. - The inference endpoint you use can perform one specific task that has been defined when the endpoint was created with the create inference API.

-
-

info - The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face. For built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models. However, if you do not plan to use the inference APIs to use these models or if you want to use non-NLP models, use the machine learning trained model APIs.

-
- - - ``_ - - :param inference_id: The unique identifier for the inference endpoint. - :param input: The text on which you want to perform the inference task. It can - be a single string or an array. > info > Inference endpoints for the `completion` - task type currently only support a single string as input. - :param task_type: The type of inference task that the model performs. - :param query: The query input, which is required only for the `rerank` task. - It is not required for other tasks. - :param task_settings: Task settings for the individual inference request. These - settings are specific to the task type you specified and override the task - settings specified when initializing the service. - :param timeout: The amount of time to wait for the inference request to complete. - """ - if inference_id in SKIP_IN_PATH: - raise ValueError("Empty value passed for parameter 'inference_id'") - if input is None and body is None: - raise ValueError("Empty value passed for parameter 'input'") - __path_parts: t.Dict[str, str] - if task_type not in SKIP_IN_PATH and inference_id not in SKIP_IN_PATH: - __path_parts = { - "task_type": _quote(task_type), - "inference_id": _quote(inference_id), - } - __path = f'/_inference/{__path_parts["task_type"]}/{__path_parts["inference_id"]}' - elif inference_id not in SKIP_IN_PATH: - __path_parts = {"inference_id": _quote(inference_id)} - __path = f'/_inference/{__path_parts["inference_id"]}' - else: - raise ValueError("Couldn't find a path for the given parameters") - __query: t.Dict[str, t.Any] = {} - __body: t.Dict[str, t.Any] = body if body is not None else {} - if error_trace is not None: - __query["error_trace"] = error_trace - if filter_path is not None: - __query["filter_path"] = filter_path - if human is not None: - __query["human"] = human - if pretty is not None: - __query["pretty"] = pretty - if timeout is not None: - __query["timeout"] = timeout - if not __body: - if input is not None: - __body["input"] = input - if query is not None: - __body["query"] = query - if task_settings is not None: - __body["task_settings"] = task_settings - if not __body: - __body = None # type: ignore[assignment] - __headers = {"accept": "application/json"} - if __body is not None: - __headers["content-type"] = "application/json" - return self.perform_request( # type: ignore[return-value] - "POST", - __path, - params=__query, - headers=__headers, - body=__body, - endpoint_id="inference.inference", - path_parts=__path_parts, - ) - @_rewrite_parameters( body_name="inference_config", ) diff --git a/elasticsearch/_sync/client/utils.py b/elasticsearch/_sync/client/utils.py index 2d7a93d65..51afe1c78 100644 --- a/elasticsearch/_sync/client/utils.py +++ b/elasticsearch/_sync/client/utils.py @@ -77,7 +77,6 @@ class Stability(Enum): STABLE = auto() BETA = auto() EXPERIMENTAL = auto() - DEPRECATED = auto() _TYPE_HOSTS = Union[ @@ -480,12 +479,6 @@ def wrapped(*args: Any, **kwargs: Any) -> Any: category=GeneralAvailabilityWarning, stacklevel=warn_stacklevel(), ) - elif stability == Stability.DEPRECATED and message and version: - warnings.warn( - f"In elasticsearch-py {version}, {message}.", - category=DeprecationWarning, - stacklevel=warn_stacklevel(), - ) return api(*args, **kwargs)