Skip to content

[Backport 8.x] Revert "Add back inference.inference API (#2873)" #2901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025
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
119 changes: 1 addition & 118 deletions elasticsearch/_async/client/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

<p>Perform inference on the service.</p>
<p>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.</p>
<blockquote>
<p>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.</p>
</blockquote>


`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-inference>`_

: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",
)
Expand Down
119 changes: 1 addition & 118 deletions elasticsearch/_sync/client/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

<p>Perform inference on the service.</p>
<p>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.</p>
<blockquote>
<p>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.</p>
</blockquote>


`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-inference>`_

: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",
)
Expand Down
7 changes: 0 additions & 7 deletions elasticsearch/_sync/client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class Stability(Enum):
STABLE = auto()
BETA = auto()
EXPERIMENTAL = auto()
DEPRECATED = auto()


_TYPE_HOSTS = Union[
Expand Down Expand Up @@ -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)

Expand Down