Skip to content

Commit 32bb5a9

Browse files
Auto-generated API code
1 parent 6074eca commit 32bb5a9

File tree

5 files changed

+403
-7
lines changed

5 files changed

+403
-7
lines changed

elasticsearch/_async/client/inference.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,113 @@ async def get(
234234
path_parts=__path_parts,
235235
)
236236

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

elasticsearch/_sync/client/inference.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,113 @@ def get(
234234
path_parts=__path_parts,
235235
)
236236

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

0 commit comments

Comments
 (0)