openai/request/
create_answer.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 CreateAnswerRequest<'a> {
9    pub(crate) http_client: &'a OpenAiClient,
10    pub documents: Option<Vec<String>>,
11    pub examples: Vec<Vec<String>>,
12    pub examples_context: String,
13    pub expand: Option<Vec<serde_json::Value>>,
14    pub file: Option<String>,
15    pub logit_bias: Option<serde_json::Value>,
16    pub logprobs: Option<i64>,
17    pub max_rerank: Option<i64>,
18    pub max_tokens: Option<i64>,
19    pub model: String,
20    pub n: Option<i64>,
21    pub question: String,
22    pub return_metadata: Option<bool>,
23    pub return_prompt: Option<bool>,
24    pub search_model: Option<String>,
25    pub stop: Option<serde_json::Value>,
26    pub temperature: Option<f64>,
27    pub user: Option<String>,
28}
29impl<'a> CreateAnswerRequest<'a> {
30    pub async fn send(self) -> ::httpclient::InMemoryResult<CreateAnswerResponse> {
31        let mut r = self.http_client.client.post("/answers");
32        if let Some(ref unwrapped) = self.documents {
33            r = r.json(json!({ "documents" : unwrapped }));
34        }
35        r = r.json(json!({ "examples" : self.examples }));
36        r = r.json(json!({ "examples_context" : self.examples_context }));
37        if let Some(ref unwrapped) = self.expand {
38            r = r.json(json!({ "expand" : unwrapped }));
39        }
40        if let Some(ref unwrapped) = self.file {
41            r = r.json(json!({ "file" : unwrapped }));
42        }
43        if let Some(ref unwrapped) = self.logit_bias {
44            r = r.json(json!({ "logit_bias" : unwrapped }));
45        }
46        if let Some(ref unwrapped) = self.logprobs {
47            r = r.json(json!({ "logprobs" : unwrapped }));
48        }
49        if let Some(ref unwrapped) = self.max_rerank {
50            r = r.json(json!({ "max_rerank" : unwrapped }));
51        }
52        if let Some(ref unwrapped) = self.max_tokens {
53            r = r.json(json!({ "max_tokens" : unwrapped }));
54        }
55        r = r.json(json!({ "model" : self.model }));
56        if let Some(ref unwrapped) = self.n {
57            r = r.json(json!({ "n" : unwrapped }));
58        }
59        r = r.json(json!({ "question" : self.question }));
60        if let Some(ref unwrapped) = self.return_metadata {
61            r = r.json(json!({ "return_metadata" : unwrapped }));
62        }
63        if let Some(ref unwrapped) = self.return_prompt {
64            r = r.json(json!({ "return_prompt" : unwrapped }));
65        }
66        if let Some(ref unwrapped) = self.search_model {
67            r = r.json(json!({ "search_model" : unwrapped }));
68        }
69        if let Some(ref unwrapped) = self.stop {
70            r = r.json(json!({ "stop" : unwrapped }));
71        }
72        if let Some(ref unwrapped) = self.temperature {
73            r = r.json(json!({ "temperature" : unwrapped }));
74        }
75        if let Some(ref unwrapped) = self.user {
76            r = r.json(json!({ "user" : unwrapped }));
77        }
78        r = self.http_client.authenticate(r);
79        let res = r.send_awaiting_body().await?;
80        res.json()
81    }
82    pub fn documents(
83        mut self,
84        documents: impl IntoIterator<Item = impl AsRef<str>>,
85    ) -> Self {
86        self
87            .documents = Some(
88            documents.into_iter().map(|s| s.as_ref().to_owned()).collect(),
89        );
90        self
91    }
92    pub fn expand(mut self, expand: Vec<serde_json::Value>) -> Self {
93        self.expand = Some(expand);
94        self
95    }
96    pub fn file(mut self, file: &str) -> Self {
97        self.file = Some(file.to_owned());
98        self
99    }
100    pub fn logit_bias(mut self, logit_bias: serde_json::Value) -> Self {
101        self.logit_bias = Some(logit_bias);
102        self
103    }
104    pub fn logprobs(mut self, logprobs: i64) -> Self {
105        self.logprobs = Some(logprobs);
106        self
107    }
108    pub fn max_rerank(mut self, max_rerank: i64) -> Self {
109        self.max_rerank = Some(max_rerank);
110        self
111    }
112    pub fn max_tokens(mut self, max_tokens: i64) -> Self {
113        self.max_tokens = Some(max_tokens);
114        self
115    }
116    pub fn n(mut self, n: i64) -> Self {
117        self.n = Some(n);
118        self
119    }
120    pub fn return_metadata(mut self, return_metadata: bool) -> Self {
121        self.return_metadata = Some(return_metadata);
122        self
123    }
124    pub fn return_prompt(mut self, return_prompt: bool) -> Self {
125        self.return_prompt = Some(return_prompt);
126        self
127    }
128    pub fn search_model(mut self, search_model: &str) -> Self {
129        self.search_model = Some(search_model.to_owned());
130        self
131    }
132    pub fn stop(mut self, stop: serde_json::Value) -> Self {
133        self.stop = Some(stop);
134        self
135    }
136    pub fn temperature(mut self, temperature: f64) -> Self {
137        self.temperature = Some(temperature);
138        self
139    }
140    pub fn user(mut self, user: &str) -> Self {
141        self.user = Some(user.to_owned());
142        self
143    }
144}
145pub struct CreateAnswerRequired<'a> {
146    pub examples: &'a [&'a [&'a str]],
147    pub examples_context: &'a str,
148    pub model: &'a str,
149    pub question: &'a str,
150}
151impl<'a> CreateAnswerRequired<'a> {}
152impl<'a> ::std::future::IntoFuture for CreateAnswerRequest<'a> {
153    type Output = httpclient::InMemoryResult<CreateAnswerResponse>;
154    type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
155    fn into_future(self) -> Self::IntoFuture {
156        Box::pin(self.send())
157    }
158}