Skip to content

Commit eed8c1d

Browse files
committed
Update to latest 9.0.0 snapshot
1 parent 3f7140d commit eed8c1d

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

elasticsearch/src/inference.rs

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,164 @@ impl<'a, 'b> InferenceGet<'a, 'b> {
621621
}
622622
}
623623
#[derive(Debug, Clone, PartialEq, Eq)]
624+
#[doc = "API parts for the Inference Inference API"]
625+
pub enum InferenceInferenceParts<'b> {
626+
#[doc = "InferenceId"]
627+
InferenceId(&'b str),
628+
#[doc = "TaskType and InferenceId"]
629+
TaskTypeInferenceId(&'b str, &'b str),
630+
}
631+
impl<'b> InferenceInferenceParts<'b> {
632+
#[doc = "Builds a relative URL path to the Inference Inference API"]
633+
pub fn url(self) -> Cow<'static, str> {
634+
match self {
635+
InferenceInferenceParts::InferenceId(inference_id) => {
636+
let encoded_inference_id: Cow<str> =
637+
percent_encode(inference_id.as_bytes(), PARTS_ENCODED).into();
638+
let mut p = String::with_capacity(12usize + encoded_inference_id.len());
639+
p.push_str("/_inference/");
640+
p.push_str(encoded_inference_id.as_ref());
641+
p.into()
642+
}
643+
InferenceInferenceParts::TaskTypeInferenceId(task_type, inference_id) => {
644+
let encoded_task_type: Cow<str> =
645+
percent_encode(task_type.as_bytes(), PARTS_ENCODED).into();
646+
let encoded_inference_id: Cow<str> =
647+
percent_encode(inference_id.as_bytes(), PARTS_ENCODED).into();
648+
let mut p = String::with_capacity(
649+
13usize + encoded_task_type.len() + encoded_inference_id.len(),
650+
);
651+
p.push_str("/_inference/");
652+
p.push_str(encoded_task_type.as_ref());
653+
p.push('/');
654+
p.push_str(encoded_inference_id.as_ref());
655+
p.into()
656+
}
657+
}
658+
}
659+
}
660+
#[doc = "Builder for the [Inference Inference API](https://www.elastic.co/guide/en/elasticsearch/reference/9.0/post-inference-api.html)\n\nPerform inference"]
661+
#[derive(Clone, Debug)]
662+
pub struct InferenceInference<'a, 'b, B> {
663+
transport: &'a Transport,
664+
parts: InferenceInferenceParts<'b>,
665+
body: Option<B>,
666+
error_trace: Option<bool>,
667+
filter_path: Option<&'b [&'b str]>,
668+
headers: HeaderMap,
669+
human: Option<bool>,
670+
pretty: Option<bool>,
671+
request_timeout: Option<Duration>,
672+
source: Option<&'b str>,
673+
}
674+
impl<'a, 'b, B> InferenceInference<'a, 'b, B>
675+
where
676+
B: Body,
677+
{
678+
#[doc = "Creates a new instance of [InferenceInference] with the specified API parts"]
679+
pub fn new(transport: &'a Transport, parts: InferenceInferenceParts<'b>) -> Self {
680+
let headers = HeaderMap::new();
681+
InferenceInference {
682+
transport,
683+
parts,
684+
headers,
685+
body: None,
686+
error_trace: None,
687+
filter_path: None,
688+
human: None,
689+
pretty: None,
690+
request_timeout: None,
691+
source: None,
692+
}
693+
}
694+
#[doc = "The body for the API call"]
695+
pub fn body<T>(self, body: T) -> InferenceInference<'a, 'b, JsonBody<T>>
696+
where
697+
T: Serialize,
698+
{
699+
InferenceInference {
700+
transport: self.transport,
701+
parts: self.parts,
702+
body: Some(body.into()),
703+
error_trace: self.error_trace,
704+
filter_path: self.filter_path,
705+
headers: self.headers,
706+
human: self.human,
707+
pretty: self.pretty,
708+
request_timeout: self.request_timeout,
709+
source: self.source,
710+
}
711+
}
712+
#[doc = "Include the stack trace of returned errors."]
713+
pub fn error_trace(mut self, error_trace: bool) -> Self {
714+
self.error_trace = Some(error_trace);
715+
self
716+
}
717+
#[doc = "A comma-separated list of filters used to reduce the response."]
718+
pub fn filter_path(mut self, filter_path: &'b [&'b str]) -> Self {
719+
self.filter_path = Some(filter_path);
720+
self
721+
}
722+
#[doc = "Adds a HTTP header"]
723+
pub fn header(mut self, key: HeaderName, value: HeaderValue) -> Self {
724+
self.headers.insert(key, value);
725+
self
726+
}
727+
#[doc = "Return human readable values for statistics."]
728+
pub fn human(mut self, human: bool) -> Self {
729+
self.human = Some(human);
730+
self
731+
}
732+
#[doc = "Pretty format the returned JSON response."]
733+
pub fn pretty(mut self, pretty: bool) -> Self {
734+
self.pretty = Some(pretty);
735+
self
736+
}
737+
#[doc = "Sets a request timeout for this API call.\n\nThe timeout is applied from when the request starts connecting until the response body has finished."]
738+
pub fn request_timeout(mut self, timeout: Duration) -> Self {
739+
self.request_timeout = Some(timeout);
740+
self
741+
}
742+
#[doc = "The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests."]
743+
pub fn source(mut self, source: &'b str) -> Self {
744+
self.source = Some(source);
745+
self
746+
}
747+
#[doc = "Creates an asynchronous call to the Inference Inference API that can be awaited"]
748+
pub async fn send(self) -> Result<Response, Error> {
749+
let path = self.parts.url();
750+
let method = http::Method::Post;
751+
let headers = self.headers;
752+
let timeout = self.request_timeout;
753+
let query_string = {
754+
#[serde_with::skip_serializing_none]
755+
#[derive(Serialize)]
756+
struct QueryParams<'b> {
757+
error_trace: Option<bool>,
758+
#[serde(serialize_with = "crate::client::serialize_coll_qs")]
759+
filter_path: Option<&'b [&'b str]>,
760+
human: Option<bool>,
761+
pretty: Option<bool>,
762+
source: Option<&'b str>,
763+
}
764+
let query_params = QueryParams {
765+
error_trace: self.error_trace,
766+
filter_path: self.filter_path,
767+
human: self.human,
768+
pretty: self.pretty,
769+
source: self.source,
770+
};
771+
Some(query_params)
772+
};
773+
let body = self.body;
774+
let response = self
775+
.transport
776+
.send(method, &path, headers, query_string.as_ref(), body, timeout)
777+
.await?;
778+
Ok(response)
779+
}
780+
}
781+
#[derive(Debug, Clone, PartialEq, Eq)]
624782
#[doc = "API parts for the Inference Put API"]
625783
pub enum InferencePutParts<'b> {
626784
#[doc = "InferenceId"]
@@ -3945,6 +4103,13 @@ impl<'a> Inference<'a> {
39454103
pub fn get<'b>(&'a self, parts: InferenceGetParts<'b>) -> InferenceGet<'a, 'b> {
39464104
InferenceGet::new(self.transport(), parts)
39474105
}
4106+
#[doc = "[Inference Inference API](https://www.elastic.co/guide/en/elasticsearch/reference/9.0/post-inference-api.html)\n\nPerform inference"]
4107+
pub fn inference<'b>(
4108+
&'a self,
4109+
parts: InferenceInferenceParts<'b>,
4110+
) -> InferenceInference<'a, 'b, ()> {
4111+
InferenceInference::new(self.transport(), parts)
4112+
}
39484113
#[doc = "[Inference Put API](https://www.elastic.co/guide/en/elasticsearch/reference/9.0/put-inference-api.html)\n\nConfigure an inference endpoint for use in the Inference API"]
39494114
pub fn put<'b>(&'a self, parts: InferencePutParts<'b>) -> InferencePut<'a, 'b, ()> {
39504115
InferencePut::new(self.transport(), parts)

0 commit comments

Comments
 (0)