Skip to content

Commit 92b3f71

Browse files
Auto-generated API code
1 parent 521783c commit 92b3f71

File tree

2 files changed

+232
-14
lines changed

2 files changed

+232
-14
lines changed

elasticsearch/_async/client/inference.py

+116-7
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,122 @@ async def inference(
185185
186186
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-inference-api.html>`_
187187
188-
:param inference_id: The inference Id
189-
:param input: Inference input. Either a string or an array of strings.
190-
:param task_type: The task type
191-
:param query: Query input, required for rerank task. Not required for other tasks.
192-
:param task_settings: Optional task settings
193-
:param timeout: Specifies the amount of time to wait for the inference request
194-
to complete.
188+
:param inference_id: The unique identifier for the inference endpoint.
189+
:param input: The text on which you want to perform the inference task. It can
190+
be a single string or an array. > info > Inference endpoints for the `completion`
191+
task type currently only support a single string as input.
192+
:param task_type: The type of inference task that the model performs.
193+
:param query: The query input, which is required only for the `rerank` task.
194+
It is not required for other tasks.
195+
:param task_settings: Task settings for the individual inference request. These
196+
settings are specific to the task type you specified and override the task
197+
settings specified when initializing the service.
198+
:param timeout: The amount of time to wait for the inference request to complete.
199+
"""
200+
if inference_id in SKIP_IN_PATH:
201+
raise ValueError("Empty value passed for parameter 'inference_id'")
202+
if input is None and body is None:
203+
raise ValueError("Empty value passed for parameter 'input'")
204+
__path_parts: t.Dict[str, str]
205+
if task_type not in SKIP_IN_PATH and inference_id not in SKIP_IN_PATH:
206+
__path_parts = {
207+
"task_type": _quote(task_type),
208+
"inference_id": _quote(inference_id),
209+
}
210+
__path = f'/_inference/{__path_parts["task_type"]}/{__path_parts["inference_id"]}'
211+
elif inference_id not in SKIP_IN_PATH:
212+
__path_parts = {"inference_id": _quote(inference_id)}
213+
__path = f'/_inference/{__path_parts["inference_id"]}'
214+
else:
215+
raise ValueError("Couldn't find a path for the given parameters")
216+
__query: t.Dict[str, t.Any] = {}
217+
__body: t.Dict[str, t.Any] = body if body is not None else {}
218+
if error_trace is not None:
219+
__query["error_trace"] = error_trace
220+
if filter_path is not None:
221+
__query["filter_path"] = filter_path
222+
if human is not None:
223+
__query["human"] = human
224+
if pretty is not None:
225+
__query["pretty"] = pretty
226+
if timeout is not None:
227+
__query["timeout"] = timeout
228+
if not __body:
229+
if input is not None:
230+
__body["input"] = input
231+
if query is not None:
232+
__body["query"] = query
233+
if task_settings is not None:
234+
__body["task_settings"] = task_settings
235+
if not __body:
236+
__body = None # type: ignore[assignment]
237+
__headers = {"accept": "application/json"}
238+
if __body is not None:
239+
__headers["content-type"] = "application/json"
240+
return await self.perform_request( # type: ignore[return-value]
241+
"POST",
242+
__path,
243+
params=__query,
244+
headers=__headers,
245+
body=__body,
246+
endpoint_id="inference.inference",
247+
path_parts=__path_parts,
248+
)
249+
250+
@_rewrite_parameters(
251+
body_fields=("input", "query", "task_settings"),
252+
)
253+
@_stability_warning(
254+
Stability.DEPRECATED,
255+
version="8.18.0",
256+
message="inference.inference() is deprecated in favor of provider-specific APIs such as inference.put_elasticsearch() or inference.put_hugging_face()",
257+
)
258+
async def inference(
259+
self,
260+
*,
261+
inference_id: str,
262+
input: t.Optional[t.Union[str, t.Sequence[str]]] = None,
263+
task_type: t.Optional[
264+
t.Union[
265+
str,
266+
t.Literal["completion", "rerank", "sparse_embedding", "text_embedding"],
267+
]
268+
] = None,
269+
error_trace: t.Optional[bool] = None,
270+
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
271+
human: t.Optional[bool] = None,
272+
pretty: t.Optional[bool] = None,
273+
query: t.Optional[str] = None,
274+
task_settings: t.Optional[t.Any] = None,
275+
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
276+
body: t.Optional[t.Dict[str, t.Any]] = None,
277+
) -> ObjectApiResponse[t.Any]:
278+
"""
279+
.. raw:: html
280+
281+
<p>Perform inference on the service.</p>
282+
<p>This API enables you to use machine learning models to perform specific tasks on data that you provide as an input.
283+
It returns a response with the results of the tasks.
284+
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>
285+
<blockquote>
286+
<p>info
287+
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>
288+
</blockquote>
289+
290+
291+
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-inference>`_
292+
293+
:param inference_id: The unique identifier for the inference endpoint.
294+
:param input: The text on which you want to perform the inference task. It can
295+
be a single string or an array. > info > Inference endpoints for the `completion`
296+
task type currently only support a single string as input.
297+
:param task_type: The type of inference task that the model performs.
298+
:param query: The query input, which is required only for the `rerank` task.
299+
It is not required for other tasks.
300+
:param task_settings: Task settings for the individual inference request. These
301+
settings are specific to the task type you specified and override the task
302+
settings specified when initializing the service.
303+
:param timeout: The amount of time to wait for the inference request to complete.
195304
"""
196305
if inference_id in SKIP_IN_PATH:
197306
raise ValueError("Empty value passed for parameter 'inference_id'")

elasticsearch/_sync/client/inference.py

+116-7
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,122 @@ def inference(
185185
186186
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-inference-api.html>`_
187187
188-
:param inference_id: The inference Id
189-
:param input: Inference input. Either a string or an array of strings.
190-
:param task_type: The task type
191-
:param query: Query input, required for rerank task. Not required for other tasks.
192-
:param task_settings: Optional task settings
193-
:param timeout: Specifies the amount of time to wait for the inference request
194-
to complete.
188+
:param inference_id: The unique identifier for the inference endpoint.
189+
:param input: The text on which you want to perform the inference task. It can
190+
be a single string or an array. > info > Inference endpoints for the `completion`
191+
task type currently only support a single string as input.
192+
:param task_type: The type of inference task that the model performs.
193+
:param query: The query input, which is required only for the `rerank` task.
194+
It is not required for other tasks.
195+
:param task_settings: Task settings for the individual inference request. These
196+
settings are specific to the task type you specified and override the task
197+
settings specified when initializing the service.
198+
:param timeout: The amount of time to wait for the inference request to complete.
199+
"""
200+
if inference_id in SKIP_IN_PATH:
201+
raise ValueError("Empty value passed for parameter 'inference_id'")
202+
if input is None and body is None:
203+
raise ValueError("Empty value passed for parameter 'input'")
204+
__path_parts: t.Dict[str, str]
205+
if task_type not in SKIP_IN_PATH and inference_id not in SKIP_IN_PATH:
206+
__path_parts = {
207+
"task_type": _quote(task_type),
208+
"inference_id": _quote(inference_id),
209+
}
210+
__path = f'/_inference/{__path_parts["task_type"]}/{__path_parts["inference_id"]}'
211+
elif inference_id not in SKIP_IN_PATH:
212+
__path_parts = {"inference_id": _quote(inference_id)}
213+
__path = f'/_inference/{__path_parts["inference_id"]}'
214+
else:
215+
raise ValueError("Couldn't find a path for the given parameters")
216+
__query: t.Dict[str, t.Any] = {}
217+
__body: t.Dict[str, t.Any] = body if body is not None else {}
218+
if error_trace is not None:
219+
__query["error_trace"] = error_trace
220+
if filter_path is not None:
221+
__query["filter_path"] = filter_path
222+
if human is not None:
223+
__query["human"] = human
224+
if pretty is not None:
225+
__query["pretty"] = pretty
226+
if timeout is not None:
227+
__query["timeout"] = timeout
228+
if not __body:
229+
if input is not None:
230+
__body["input"] = input
231+
if query is not None:
232+
__body["query"] = query
233+
if task_settings is not None:
234+
__body["task_settings"] = task_settings
235+
if not __body:
236+
__body = None # type: ignore[assignment]
237+
__headers = {"accept": "application/json"}
238+
if __body is not None:
239+
__headers["content-type"] = "application/json"
240+
return self.perform_request( # type: ignore[return-value]
241+
"POST",
242+
__path,
243+
params=__query,
244+
headers=__headers,
245+
body=__body,
246+
endpoint_id="inference.inference",
247+
path_parts=__path_parts,
248+
)
249+
250+
@_rewrite_parameters(
251+
body_fields=("input", "query", "task_settings"),
252+
)
253+
@_stability_warning(
254+
Stability.DEPRECATED,
255+
version="8.18.0",
256+
message="inference.inference() is deprecated in favor of provider-specific APIs such as inference.put_elasticsearch() or inference.put_hugging_face()",
257+
)
258+
def inference(
259+
self,
260+
*,
261+
inference_id: str,
262+
input: t.Optional[t.Union[str, t.Sequence[str]]] = None,
263+
task_type: t.Optional[
264+
t.Union[
265+
str,
266+
t.Literal["completion", "rerank", "sparse_embedding", "text_embedding"],
267+
]
268+
] = None,
269+
error_trace: t.Optional[bool] = None,
270+
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
271+
human: t.Optional[bool] = None,
272+
pretty: t.Optional[bool] = None,
273+
query: t.Optional[str] = None,
274+
task_settings: t.Optional[t.Any] = None,
275+
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
276+
body: t.Optional[t.Dict[str, t.Any]] = None,
277+
) -> ObjectApiResponse[t.Any]:
278+
"""
279+
.. raw:: html
280+
281+
<p>Perform inference on the service.</p>
282+
<p>This API enables you to use machine learning models to perform specific tasks on data that you provide as an input.
283+
It returns a response with the results of the tasks.
284+
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>
285+
<blockquote>
286+
<p>info
287+
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>
288+
</blockquote>
289+
290+
291+
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-inference>`_
292+
293+
:param inference_id: The unique identifier for the inference endpoint.
294+
:param input: The text on which you want to perform the inference task. It can
295+
be a single string or an array. > info > Inference endpoints for the `completion`
296+
task type currently only support a single string as input.
297+
:param task_type: The type of inference task that the model performs.
298+
:param query: The query input, which is required only for the `rerank` task.
299+
It is not required for other tasks.
300+
:param task_settings: Task settings for the individual inference request. These
301+
settings are specific to the task type you specified and override the task
302+
settings specified when initializing the service.
303+
:param timeout: The amount of time to wait for the inference request to complete.
195304
"""
196305
if inference_id in SKIP_IN_PATH:
197306
raise ValueError("Empty value passed for parameter 'inference_id'")

0 commit comments

Comments
 (0)