-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathinference.py
2257 lines (2127 loc) · 106 KB
/
inference.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import typing as t
from elastic_transport import ObjectApiResponse
from ._base import NamespacedClient
from .utils import (
SKIP_IN_PATH,
Stability,
_quote,
_rewrite_parameters,
_stability_warning,
)
class InferenceClient(NamespacedClient):
@_rewrite_parameters(
body_fields=("input", "task_settings"),
)
def completion(
self,
*,
inference_id: str,
input: t.Optional[t.Union[str, t.Sequence[str]]] = 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,
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 completion inference on the service</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/post-inference-api.html>`_
:param inference_id: The inference Id
:param input: Inference input. Either a string or an array of strings.
:param task_settings: Optional task settings
:param timeout: Specifies 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] = {"inference_id": _quote(inference_id)}
__path = f'/_inference/completion/{__path_parts["inference_id"]}'
__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 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.completion",
path_parts=__path_parts,
)
@_rewrite_parameters()
def delete(
self,
*,
inference_id: str,
task_type: t.Optional[
t.Union[
str,
t.Literal[
"chat_completion",
"completion",
"rerank",
"sparse_embedding",
"text_embedding",
],
]
] = None,
dry_run: t.Optional[bool] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
force: t.Optional[bool] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Delete an inference endpoint</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/delete-inference-api.html>`_
:param inference_id: The inference identifier.
:param task_type: The task type
:param dry_run: When true, the endpoint is not deleted and a list of ingest processors
which reference this endpoint is returned.
:param force: When true, the inference endpoint is forcefully deleted even if
it is still being used by ingest processors or semantic text fields.
"""
if inference_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'inference_id'")
__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] = {}
if dry_run is not None:
__query["dry_run"] = dry_run
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if force is not None:
__query["force"] = force
if human is not None:
__query["human"] = human
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="inference.delete",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get(
self,
*,
task_type: t.Optional[
t.Union[
str,
t.Literal[
"chat_completion",
"completion",
"rerank",
"sparse_embedding",
"text_embedding",
],
]
] = None,
inference_id: t.Optional[str] = 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,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get an inference endpoint</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/get-inference-api.html>`_
:param task_type: The task type
:param inference_id: The inference Id
"""
__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:
__path_parts = {}
__path = "/_inference"
__query: t.Dict[str, t.Any] = {}
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
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="inference.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",
)
def put(
self,
*,
inference_id: str,
inference_config: t.Optional[t.Mapping[str, t.Any]] = None,
body: t.Optional[t.Mapping[str, t.Any]] = 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,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create an inference endpoint.
When you create an inference endpoint, the associated machine learning model is automatically deployed if it is not already running.
After creating the endpoint, wait for the model deployment to complete before using it.
To verify the deployment status, use the get trained model statistics API.
Look for <code>"state": "fully_allocated"</code> in the response and ensure that the <code>"allocation_count"</code> matches the <code>"target_allocation_count"</code>.
Avoid creating multiple endpoints for the same model unless required, as each endpoint consumes significant resources.</p>
<p>IMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Mistral, Azure OpenAI, 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>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/put-inference-api.html>`_
:param inference_id: The inference Id
:param inference_config:
:param task_type: The task type
"""
if inference_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'inference_id'")
if inference_config is None and body is None:
raise ValueError(
"Empty value passed for parameters 'inference_config' and 'body', one of them should be set."
)
elif inference_config is not None and body is not None:
raise ValueError("Cannot set both 'inference_config' and 'body'")
__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] = {}
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
__body = inference_config if inference_config is not None else body
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="inference.put",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"service",
"service_settings",
"chunking_settings",
"task_settings",
),
)
def put_alibabacloud(
self,
*,
task_type: t.Union[
str, t.Literal["completion", "rerank", "space_embedding", "text_embedding"]
],
alibabacloud_inference_id: str,
service: t.Optional[t.Union[str, t.Literal["alibabacloud-ai-search"]]] = None,
service_settings: t.Optional[t.Mapping[str, t.Any]] = None,
chunking_settings: t.Optional[t.Mapping[str, t.Any]] = 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,
task_settings: t.Optional[t.Mapping[str, t.Any]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create an AlibabaCloud AI Search inference endpoint.</p>
<p>Create an inference endpoint to perform an inference task with the <code>alibabacloud-ai-search</code> service.</p>
<p>When you create an inference endpoint, the associated machine learning model is automatically deployed if it is not already running.
After creating the endpoint, wait for the model deployment to complete before using it.
To verify the deployment status, use the get trained model statistics API.
Look for <code>"state": "fully_allocated"</code> in the response and ensure that the <code>"allocation_count"</code> matches the <code>"target_allocation_count"</code>.
Avoid creating multiple endpoints for the same model unless required, as each endpoint consumes significant resources.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/infer-service-alibabacloud-ai-search.html>`_
:param task_type: The type of the inference task that the model will perform.
:param alibabacloud_inference_id: The unique identifier of the inference endpoint.
:param service: The type of service supported for the specified task type. In
this case, `alibabacloud-ai-search`.
:param service_settings: Settings used to install the inference model. These
settings are specific to the `alibabacloud-ai-search` service.
:param chunking_settings: The chunking configuration object.
:param task_settings: Settings to configure the inference task. These settings
are specific to the task type you specified.
"""
if task_type in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'task_type'")
if alibabacloud_inference_id in SKIP_IN_PATH:
raise ValueError(
"Empty value passed for parameter 'alibabacloud_inference_id'"
)
if service is None and body is None:
raise ValueError("Empty value passed for parameter 'service'")
if service_settings is None and body is None:
raise ValueError("Empty value passed for parameter 'service_settings'")
__path_parts: t.Dict[str, str] = {
"task_type": _quote(task_type),
"alibabacloud_inference_id": _quote(alibabacloud_inference_id),
}
__path = f'/_inference/{__path_parts["task_type"]}/{__path_parts["alibabacloud_inference_id"]}'
__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 not __body:
if service is not None:
__body["service"] = service
if service_settings is not None:
__body["service_settings"] = service_settings
if chunking_settings is not None:
__body["chunking_settings"] = chunking_settings
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]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="inference.put_alibabacloud",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"service",
"service_settings",
"chunking_settings",
"task_settings",
),
)
def put_amazonbedrock(
self,
*,
task_type: t.Union[str, t.Literal["completion", "text_embedding"]],
amazonbedrock_inference_id: str,
service: t.Optional[t.Union[str, t.Literal["amazonbedrock"]]] = None,
service_settings: t.Optional[t.Mapping[str, t.Any]] = None,
chunking_settings: t.Optional[t.Mapping[str, t.Any]] = 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,
task_settings: t.Optional[t.Mapping[str, t.Any]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create an Amazon Bedrock inference endpoint.</p>
<p>Creates an inference endpoint to perform an inference task with the <code>amazonbedrock</code> service.</p>
<blockquote>
<p>info
You need to provide the access and secret keys only once, during the inference model creation. The get inference API does not retrieve your access or secret keys. After creating the inference model, you cannot change the associated key pairs. If you want to use a different access and secret key pair, delete the inference model and recreate it with the same name and the updated keys.</p>
</blockquote>
<p>When you create an inference endpoint, the associated machine learning model is automatically deployed if it is not already running.
After creating the endpoint, wait for the model deployment to complete before using it.
To verify the deployment status, use the get trained model statistics API.
Look for <code>"state": "fully_allocated"</code> in the response and ensure that the <code>"allocation_count"</code> matches the <code>"target_allocation_count"</code>.
Avoid creating multiple endpoints for the same model unless required, as each endpoint consumes significant resources.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/infer-service-amazon-bedrock.html>`_
:param task_type: The type of the inference task that the model will perform.
:param amazonbedrock_inference_id: The unique identifier of the inference endpoint.
:param service: The type of service supported for the specified task type. In
this case, `amazonbedrock`.
:param service_settings: Settings used to install the inference model. These
settings are specific to the `amazonbedrock` service.
:param chunking_settings: The chunking configuration object.
:param task_settings: Settings to configure the inference task. These settings
are specific to the task type you specified.
"""
if task_type in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'task_type'")
if amazonbedrock_inference_id in SKIP_IN_PATH:
raise ValueError(
"Empty value passed for parameter 'amazonbedrock_inference_id'"
)
if service is None and body is None:
raise ValueError("Empty value passed for parameter 'service'")
if service_settings is None and body is None:
raise ValueError("Empty value passed for parameter 'service_settings'")
__path_parts: t.Dict[str, str] = {
"task_type": _quote(task_type),
"amazonbedrock_inference_id": _quote(amazonbedrock_inference_id),
}
__path = f'/_inference/{__path_parts["task_type"]}/{__path_parts["amazonbedrock_inference_id"]}'
__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 not __body:
if service is not None:
__body["service"] = service
if service_settings is not None:
__body["service_settings"] = service_settings
if chunking_settings is not None:
__body["chunking_settings"] = chunking_settings
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]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="inference.put_amazonbedrock",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"service",
"service_settings",
"chunking_settings",
"task_settings",
),
)
def put_anthropic(
self,
*,
task_type: t.Union[str, t.Literal["completion"]],
anthropic_inference_id: str,
service: t.Optional[t.Union[str, t.Literal["anthropic"]]] = None,
service_settings: t.Optional[t.Mapping[str, t.Any]] = None,
chunking_settings: t.Optional[t.Mapping[str, t.Any]] = 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,
task_settings: t.Optional[t.Mapping[str, t.Any]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create an Anthropic inference endpoint.</p>
<p>Create an inference endpoint to perform an inference task with the <code>anthropic</code> service.</p>
<p>When you create an inference endpoint, the associated machine learning model is automatically deployed if it is not already running.
After creating the endpoint, wait for the model deployment to complete before using it.
To verify the deployment status, use the get trained model statistics API.
Look for <code>"state": "fully_allocated"</code> in the response and ensure that the <code>"allocation_count"</code> matches the <code>"target_allocation_count"</code>.
Avoid creating multiple endpoints for the same model unless required, as each endpoint consumes significant resources.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/infer-service-anthropic.html>`_
:param task_type: The task type. The only valid task type for the model to perform
is `completion`.
:param anthropic_inference_id: The unique identifier of the inference endpoint.
:param service: The type of service supported for the specified task type. In
this case, `anthropic`.
:param service_settings: Settings used to install the inference model. These
settings are specific to the `watsonxai` service.
:param chunking_settings: The chunking configuration object.
:param task_settings: Settings to configure the inference task. These settings
are specific to the task type you specified.
"""
if task_type in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'task_type'")
if anthropic_inference_id in SKIP_IN_PATH:
raise ValueError(
"Empty value passed for parameter 'anthropic_inference_id'"
)
if service is None and body is None:
raise ValueError("Empty value passed for parameter 'service'")
if service_settings is None and body is None:
raise ValueError("Empty value passed for parameter 'service_settings'")
__path_parts: t.Dict[str, str] = {
"task_type": _quote(task_type),
"anthropic_inference_id": _quote(anthropic_inference_id),
}
__path = f'/_inference/{__path_parts["task_type"]}/{__path_parts["anthropic_inference_id"]}'
__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 not __body:
if service is not None:
__body["service"] = service
if service_settings is not None:
__body["service_settings"] = service_settings
if chunking_settings is not None:
__body["chunking_settings"] = chunking_settings
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]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="inference.put_anthropic",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"service",
"service_settings",
"chunking_settings",
"task_settings",
),
)
def put_azureaistudio(
self,
*,
task_type: t.Union[str, t.Literal["completion", "text_embedding"]],
azureaistudio_inference_id: str,
service: t.Optional[t.Union[str, t.Literal["azureaistudio"]]] = None,
service_settings: t.Optional[t.Mapping[str, t.Any]] = None,
chunking_settings: t.Optional[t.Mapping[str, t.Any]] = 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,
task_settings: t.Optional[t.Mapping[str, t.Any]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create an Azure AI studio inference endpoint.</p>
<p>Create an inference endpoint to perform an inference task with the <code>azureaistudio</code> service.</p>
<p>When you create an inference endpoint, the associated machine learning model is automatically deployed if it is not already running.
After creating the endpoint, wait for the model deployment to complete before using it.
To verify the deployment status, use the get trained model statistics API.
Look for <code>"state": "fully_allocated"</code> in the response and ensure that the <code>"allocation_count"</code> matches the <code>"target_allocation_count"</code>.
Avoid creating multiple endpoints for the same model unless required, as each endpoint consumes significant resources.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/infer-service-azure-ai-studio.html>`_
:param task_type: The type of the inference task that the model will perform.
:param azureaistudio_inference_id: The unique identifier of the inference endpoint.
:param service: The type of service supported for the specified task type. In
this case, `azureaistudio`.
:param service_settings: Settings used to install the inference model. These
settings are specific to the `openai` service.
:param chunking_settings: The chunking configuration object.
:param task_settings: Settings to configure the inference task. These settings
are specific to the task type you specified.
"""
if task_type in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'task_type'")
if azureaistudio_inference_id in SKIP_IN_PATH:
raise ValueError(
"Empty value passed for parameter 'azureaistudio_inference_id'"
)
if service is None and body is None:
raise ValueError("Empty value passed for parameter 'service'")
if service_settings is None and body is None:
raise ValueError("Empty value passed for parameter 'service_settings'")
__path_parts: t.Dict[str, str] = {
"task_type": _quote(task_type),
"azureaistudio_inference_id": _quote(azureaistudio_inference_id),
}
__path = f'/_inference/{__path_parts["task_type"]}/{__path_parts["azureaistudio_inference_id"]}'
__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 not __body:
if service is not None:
__body["service"] = service
if service_settings is not None:
__body["service_settings"] = service_settings
if chunking_settings is not None:
__body["chunking_settings"] = chunking_settings
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]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="inference.put_azureaistudio",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"service",
"service_settings",
"chunking_settings",
"task_settings",
),
)
def put_azureopenai(
self,
*,
task_type: t.Union[str, t.Literal["completion", "text_embedding"]],
azureopenai_inference_id: str,
service: t.Optional[t.Union[str, t.Literal["azureopenai"]]] = None,
service_settings: t.Optional[t.Mapping[str, t.Any]] = None,
chunking_settings: t.Optional[t.Mapping[str, t.Any]] = 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,
task_settings: t.Optional[t.Mapping[str, t.Any]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create an Azure OpenAI inference endpoint.</p>
<p>Create an inference endpoint to perform an inference task with the <code>azureopenai</code> service.</p>
<p>The list of chat completion models that you can choose from in your Azure OpenAI deployment include:</p>
<ul>
<li><a href="https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models?tabs=global-standard%2Cstandard-chat-completions#gpt-4-and-gpt-4-turbo-models">GPT-4 and GPT-4 Turbo models</a></li>
<li><a href="https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models?tabs=global-standard%2Cstandard-chat-completions#gpt-35">GPT-3.5</a></li>
</ul>
<p>The list of embeddings models that you can choose from in your deployment can be found in the <a href="https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models?tabs=global-standard%2Cstandard-chat-completions#embeddings">Azure models documentation</a>.</p>
<p>When you create an inference endpoint, the associated machine learning model is automatically deployed if it is not already running.
After creating the endpoint, wait for the model deployment to complete before using it.
To verify the deployment status, use the get trained model statistics API.
Look for <code>"state": "fully_allocated"</code> in the response and ensure that the <code>"allocation_count"</code> matches the <code>"target_allocation_count"</code>.
Avoid creating multiple endpoints for the same model unless required, as each endpoint consumes significant resources.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/infer-service-azure-openai.html>`_
:param task_type: The type of the inference task that the model will perform.
NOTE: The `chat_completion` task type only supports streaming and only through
the _stream API.
:param azureopenai_inference_id: The unique identifier of the inference endpoint.
:param service: The type of service supported for the specified task type. In
this case, `azureopenai`.
:param service_settings: Settings used to install the inference model. These
settings are specific to the `azureopenai` service.
:param chunking_settings: The chunking configuration object.
:param task_settings: Settings to configure the inference task. These settings
are specific to the task type you specified.
"""
if task_type in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'task_type'")
if azureopenai_inference_id in SKIP_IN_PATH:
raise ValueError(
"Empty value passed for parameter 'azureopenai_inference_id'"
)
if service is None and body is None:
raise ValueError("Empty value passed for parameter 'service'")
if service_settings is None and body is None:
raise ValueError("Empty value passed for parameter 'service_settings'")
__path_parts: t.Dict[str, str] = {
"task_type": _quote(task_type),
"azureopenai_inference_id": _quote(azureopenai_inference_id),
}
__path = f'/_inference/{__path_parts["task_type"]}/{__path_parts["azureopenai_inference_id"]}'
__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 not __body:
if service is not None:
__body["service"] = service
if service_settings is not None:
__body["service_settings"] = service_settings
if chunking_settings is not None:
__body["chunking_settings"] = chunking_settings
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]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="inference.put_azureopenai",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"service",
"service_settings",
"chunking_settings",
"task_settings",
),
)
def put_cohere(
self,
*,
task_type: t.Union[str, t.Literal["completion", "rerank", "text_embedding"]],
cohere_inference_id: str,
service: t.Optional[t.Union[str, t.Literal["cohere"]]] = None,
service_settings: t.Optional[t.Mapping[str, t.Any]] = None,
chunking_settings: t.Optional[t.Mapping[str, t.Any]] = 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,
task_settings: t.Optional[t.Mapping[str, t.Any]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create a Cohere inference endpoint.</p>
<p>Create an inference endpoint to perform an inference task with the <code>cohere</code> service.</p>
<p>When you create an inference endpoint, the associated machine learning model is automatically deployed if it is not already running.
After creating the endpoint, wait for the model deployment to complete before using it.
To verify the deployment status, use the get trained model statistics API.
Look for <code>"state": "fully_allocated"</code> in the response and ensure that the <code>"allocation_count"</code> matches the <code>"target_allocation_count"</code>.
Avoid creating multiple endpoints for the same model unless required, as each endpoint consumes significant resources.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.18/infer-service-cohere.html>`_
:param task_type: The type of the inference task that the model will perform.
:param cohere_inference_id: The unique identifier of the inference endpoint.
:param service: The type of service supported for the specified task type. In
this case, `cohere`.
:param service_settings: Settings used to install the inference model. These
settings are specific to the `cohere` service.
:param chunking_settings: The chunking configuration object.
:param task_settings: Settings to configure the inference task. These settings
are specific to the task type you specified.
"""
if task_type in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'task_type'")
if cohere_inference_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'cohere_inference_id'")
if service is None and body is None:
raise ValueError("Empty value passed for parameter 'service'")
if service_settings is None and body is None:
raise ValueError("Empty value passed for parameter 'service_settings'")
__path_parts: t.Dict[str, str] = {
"task_type": _quote(task_type),
"cohere_inference_id": _quote(cohere_inference_id),
}
__path = f'/_inference/{__path_parts["task_type"]}/{__path_parts["cohere_inference_id"]}'
__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: