Skip to content

Commit 3baf4fa

Browse files
Revert "Add back inference.inference API (#2873)" (#2899) (#2902)
This reverts commit eac539d. This API will be added back through the specification and isn't deprecated anymore. (cherry picked from commit 0f845ea) Co-authored-by: Quentin Pradet <[email protected]>
1 parent ab5dbc6 commit 3baf4fa

File tree

3 files changed

+2
-243
lines changed

3 files changed

+2
-243
lines changed

Diff for: elasticsearch/_async/client/inference.py

+1-118
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@
2020
from elastic_transport import ObjectApiResponse
2121

2222
from ._base import NamespacedClient
23-
from .utils import (
24-
SKIP_IN_PATH,
25-
Stability,
26-
_quote,
27-
_rewrite_parameters,
28-
_stability_warning,
29-
)
23+
from .utils import SKIP_IN_PATH, _quote, _rewrite_parameters
3024

3125

3226
class InferenceClient(NamespacedClient):
@@ -240,117 +234,6 @@ async def get(
240234
path_parts=__path_parts,
241235
)
242236

243-
@_rewrite_parameters(
244-
body_fields=("input", "query", "task_settings"),
245-
)
246-
@_stability_warning(
247-
Stability.DEPRECATED,
248-
version="8.18.0",
249-
message="inference.inference() is deprecated in favor of provider-specific APIs such as inference.put_elasticsearch() or inference.put_hugging_face()",
250-
)
251-
async def inference(
252-
self,
253-
*,
254-
inference_id: str,
255-
input: t.Optional[t.Union[str, t.Sequence[str]]] = None,
256-
task_type: t.Optional[
257-
t.Union[
258-
str,
259-
t.Literal[
260-
"chat_completion",
261-
"completion",
262-
"rerank",
263-
"sparse_embedding",
264-
"text_embedding",
265-
],
266-
]
267-
] = None,
268-
error_trace: t.Optional[bool] = None,
269-
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
270-
human: t.Optional[bool] = None,
271-
pretty: t.Optional[bool] = None,
272-
query: t.Optional[str] = None,
273-
task_settings: t.Optional[t.Any] = None,
274-
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
275-
body: t.Optional[t.Dict[str, t.Any]] = None,
276-
) -> ObjectApiResponse[t.Any]:
277-
"""
278-
.. raw:: html
279-
280-
<p>Perform inference on the service.</p>
281-
<p>This API enables you to use machine learning models to perform specific tasks on data that you provide as an input.
282-
It returns a response with the results of the tasks.
283-
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>
284-
<blockquote>
285-
<p>info
286-
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>
287-
</blockquote>
288-
289-
290-
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-inference>`_
291-
292-
:param inference_id: The unique identifier for the inference endpoint.
293-
:param input: The text on which you want to perform the inference task. It can
294-
be a single string or an array. > info > Inference endpoints for the `completion`
295-
task type currently only support a single string as input.
296-
:param task_type: The type of inference task that the model performs.
297-
:param query: The query input, which is required only for the `rerank` task.
298-
It is not required for other tasks.
299-
:param task_settings: Task settings for the individual inference request. These
300-
settings are specific to the task type you specified and override the task
301-
settings specified when initializing the service.
302-
:param timeout: The amount of time to wait for the inference request to complete.
303-
"""
304-
if inference_id in SKIP_IN_PATH:
305-
raise ValueError("Empty value passed for parameter 'inference_id'")
306-
if input is None and body is None:
307-
raise ValueError("Empty value passed for parameter 'input'")
308-
__path_parts: t.Dict[str, str]
309-
if task_type not in SKIP_IN_PATH and inference_id not in SKIP_IN_PATH:
310-
__path_parts = {
311-
"task_type": _quote(task_type),
312-
"inference_id": _quote(inference_id),
313-
}
314-
__path = f'/_inference/{__path_parts["task_type"]}/{__path_parts["inference_id"]}'
315-
elif inference_id not in SKIP_IN_PATH:
316-
__path_parts = {"inference_id": _quote(inference_id)}
317-
__path = f'/_inference/{__path_parts["inference_id"]}'
318-
else:
319-
raise ValueError("Couldn't find a path for the given parameters")
320-
__query: t.Dict[str, t.Any] = {}
321-
__body: t.Dict[str, t.Any] = body if body is not None else {}
322-
if error_trace is not None:
323-
__query["error_trace"] = error_trace
324-
if filter_path is not None:
325-
__query["filter_path"] = filter_path
326-
if human is not None:
327-
__query["human"] = human
328-
if pretty is not None:
329-
__query["pretty"] = pretty
330-
if timeout is not None:
331-
__query["timeout"] = timeout
332-
if not __body:
333-
if input is not None:
334-
__body["input"] = input
335-
if query is not None:
336-
__body["query"] = query
337-
if task_settings is not None:
338-
__body["task_settings"] = task_settings
339-
if not __body:
340-
__body = None # type: ignore[assignment]
341-
__headers = {"accept": "application/json"}
342-
if __body is not None:
343-
__headers["content-type"] = "application/json"
344-
return await self.perform_request( # type: ignore[return-value]
345-
"POST",
346-
__path,
347-
params=__query,
348-
headers=__headers,
349-
body=__body,
350-
endpoint_id="inference.inference",
351-
path_parts=__path_parts,
352-
)
353-
354237
@_rewrite_parameters(
355238
body_name="inference_config",
356239
)

Diff for: elasticsearch/_sync/client/inference.py

+1-118
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@
2020
from elastic_transport import ObjectApiResponse
2121

2222
from ._base import NamespacedClient
23-
from .utils import (
24-
SKIP_IN_PATH,
25-
Stability,
26-
_quote,
27-
_rewrite_parameters,
28-
_stability_warning,
29-
)
23+
from .utils import SKIP_IN_PATH, _quote, _rewrite_parameters
3024

3125

3226
class InferenceClient(NamespacedClient):
@@ -240,117 +234,6 @@ def get(
240234
path_parts=__path_parts,
241235
)
242236

243-
@_rewrite_parameters(
244-
body_fields=("input", "query", "task_settings"),
245-
)
246-
@_stability_warning(
247-
Stability.DEPRECATED,
248-
version="8.18.0",
249-
message="inference.inference() is deprecated in favor of provider-specific APIs such as inference.put_elasticsearch() or inference.put_hugging_face()",
250-
)
251-
def inference(
252-
self,
253-
*,
254-
inference_id: str,
255-
input: t.Optional[t.Union[str, t.Sequence[str]]] = None,
256-
task_type: t.Optional[
257-
t.Union[
258-
str,
259-
t.Literal[
260-
"chat_completion",
261-
"completion",
262-
"rerank",
263-
"sparse_embedding",
264-
"text_embedding",
265-
],
266-
]
267-
] = None,
268-
error_trace: t.Optional[bool] = None,
269-
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
270-
human: t.Optional[bool] = None,
271-
pretty: t.Optional[bool] = None,
272-
query: t.Optional[str] = None,
273-
task_settings: t.Optional[t.Any] = None,
274-
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
275-
body: t.Optional[t.Dict[str, t.Any]] = None,
276-
) -> ObjectApiResponse[t.Any]:
277-
"""
278-
.. raw:: html
279-
280-
<p>Perform inference on the service.</p>
281-
<p>This API enables you to use machine learning models to perform specific tasks on data that you provide as an input.
282-
It returns a response with the results of the tasks.
283-
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>
284-
<blockquote>
285-
<p>info
286-
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>
287-
</blockquote>
288-
289-
290-
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-inference>`_
291-
292-
:param inference_id: The unique identifier for the inference endpoint.
293-
:param input: The text on which you want to perform the inference task. It can
294-
be a single string or an array. > info > Inference endpoints for the `completion`
295-
task type currently only support a single string as input.
296-
:param task_type: The type of inference task that the model performs.
297-
:param query: The query input, which is required only for the `rerank` task.
298-
It is not required for other tasks.
299-
:param task_settings: Task settings for the individual inference request. These
300-
settings are specific to the task type you specified and override the task
301-
settings specified when initializing the service.
302-
:param timeout: The amount of time to wait for the inference request to complete.
303-
"""
304-
if inference_id in SKIP_IN_PATH:
305-
raise ValueError("Empty value passed for parameter 'inference_id'")
306-
if input is None and body is None:
307-
raise ValueError("Empty value passed for parameter 'input'")
308-
__path_parts: t.Dict[str, str]
309-
if task_type not in SKIP_IN_PATH and inference_id not in SKIP_IN_PATH:
310-
__path_parts = {
311-
"task_type": _quote(task_type),
312-
"inference_id": _quote(inference_id),
313-
}
314-
__path = f'/_inference/{__path_parts["task_type"]}/{__path_parts["inference_id"]}'
315-
elif inference_id not in SKIP_IN_PATH:
316-
__path_parts = {"inference_id": _quote(inference_id)}
317-
__path = f'/_inference/{__path_parts["inference_id"]}'
318-
else:
319-
raise ValueError("Couldn't find a path for the given parameters")
320-
__query: t.Dict[str, t.Any] = {}
321-
__body: t.Dict[str, t.Any] = body if body is not None else {}
322-
if error_trace is not None:
323-
__query["error_trace"] = error_trace
324-
if filter_path is not None:
325-
__query["filter_path"] = filter_path
326-
if human is not None:
327-
__query["human"] = human
328-
if pretty is not None:
329-
__query["pretty"] = pretty
330-
if timeout is not None:
331-
__query["timeout"] = timeout
332-
if not __body:
333-
if input is not None:
334-
__body["input"] = input
335-
if query is not None:
336-
__body["query"] = query
337-
if task_settings is not None:
338-
__body["task_settings"] = task_settings
339-
if not __body:
340-
__body = None # type: ignore[assignment]
341-
__headers = {"accept": "application/json"}
342-
if __body is not None:
343-
__headers["content-type"] = "application/json"
344-
return self.perform_request( # type: ignore[return-value]
345-
"POST",
346-
__path,
347-
params=__query,
348-
headers=__headers,
349-
body=__body,
350-
endpoint_id="inference.inference",
351-
path_parts=__path_parts,
352-
)
353-
354237
@_rewrite_parameters(
355238
body_name="inference_config",
356239
)

Diff for: elasticsearch/_sync/client/utils.py

-7
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class Stability(Enum):
7777
STABLE = auto()
7878
BETA = auto()
7979
EXPERIMENTAL = auto()
80-
DEPRECATED = auto()
8180

8281

8382
_TYPE_HOSTS = Union[
@@ -480,12 +479,6 @@ def wrapped(*args: Any, **kwargs: Any) -> Any:
480479
category=GeneralAvailabilityWarning,
481480
stacklevel=warn_stacklevel(),
482481
)
483-
elif stability == Stability.DEPRECATED and message and version:
484-
warnings.warn(
485-
f"In elasticsearch-py {version}, {message}.",
486-
category=DeprecationWarning,
487-
stacklevel=warn_stacklevel(),
488-
)
489482

490483
return api(*args, **kwargs)
491484

0 commit comments

Comments
 (0)