|
20 | 20 | from elastic_transport import ObjectApiResponse
|
21 | 21 |
|
22 | 22 | 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 |
30 | 24 |
|
31 | 25 |
|
32 | 26 | class InferenceClient(NamespacedClient):
|
@@ -240,117 +234,6 @@ async def get(
|
240 | 234 | path_parts=__path_parts,
|
241 | 235 | )
|
242 | 236 |
|
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 |
| - |
354 | 237 | @_rewrite_parameters(
|
355 | 238 | body_name="inference_config",
|
356 | 239 | )
|
|
0 commit comments