openai/request/
create_search.rs

1use serde_json::json;
2use crate::model::*;
3use crate::OpenAiClient;
4/**Create this with the associated client method.
5
6That method takes required values as arguments. Set optional values using builder methods on this struct.*/
7#[derive(Clone)]
8pub struct CreateSearchRequest<'a> {
9    pub(crate) http_client: &'a OpenAiClient,
10    pub documents: Option<Vec<String>>,
11    pub engine_id: String,
12    pub file: Option<String>,
13    pub max_rerank: Option<i64>,
14    pub query: String,
15    pub return_metadata: Option<bool>,
16    pub user: Option<String>,
17}
18impl<'a> CreateSearchRequest<'a> {
19    pub async fn send(self) -> ::httpclient::InMemoryResult<CreateSearchResponse> {
20        let mut r = self
21            .http_client
22            .client
23            .post(&format!("/engines/{engine_id}/search", engine_id = self.engine_id));
24        if let Some(ref unwrapped) = self.documents {
25            r = r.json(json!({ "documents" : unwrapped }));
26        }
27        if let Some(ref unwrapped) = self.file {
28            r = r.json(json!({ "file" : unwrapped }));
29        }
30        if let Some(ref unwrapped) = self.max_rerank {
31            r = r.json(json!({ "max_rerank" : unwrapped }));
32        }
33        r = r.json(json!({ "query" : self.query }));
34        if let Some(ref unwrapped) = self.return_metadata {
35            r = r.json(json!({ "return_metadata" : unwrapped }));
36        }
37        if let Some(ref unwrapped) = self.user {
38            r = r.json(json!({ "user" : unwrapped }));
39        }
40        r = self.http_client.authenticate(r);
41        let res = r.send_awaiting_body().await?;
42        res.json()
43    }
44    pub fn documents(
45        mut self,
46        documents: impl IntoIterator<Item = impl AsRef<str>>,
47    ) -> Self {
48        self
49            .documents = Some(
50            documents.into_iter().map(|s| s.as_ref().to_owned()).collect(),
51        );
52        self
53    }
54    pub fn file(mut self, file: &str) -> Self {
55        self.file = Some(file.to_owned());
56        self
57    }
58    pub fn max_rerank(mut self, max_rerank: i64) -> Self {
59        self.max_rerank = Some(max_rerank);
60        self
61    }
62    pub fn return_metadata(mut self, return_metadata: bool) -> Self {
63        self.return_metadata = Some(return_metadata);
64        self
65    }
66    pub fn user(mut self, user: &str) -> Self {
67        self.user = Some(user.to_owned());
68        self
69    }
70}
71impl<'a> ::std::future::IntoFuture for CreateSearchRequest<'a> {
72    type Output = httpclient::InMemoryResult<CreateSearchResponse>;
73    type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
74    fn into_future(self) -> Self::IntoFuture {
75        Box::pin(self.send())
76    }
77}