openai/request/
create_edit.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 CreateEditRequest<'a> {
9    pub(crate) http_client: &'a OpenAiClient,
10    pub input: Option<String>,
11    pub instruction: String,
12    pub model: String,
13    pub n: Option<i64>,
14    pub temperature: Option<f64>,
15    pub top_p: Option<f64>,
16}
17impl<'a> CreateEditRequest<'a> {
18    pub async fn send(self) -> ::httpclient::InMemoryResult<CreateEditResponse> {
19        let mut r = self.http_client.client.post("/edits");
20        if let Some(ref unwrapped) = self.input {
21            r = r.json(json!({ "input" : unwrapped }));
22        }
23        r = r.json(json!({ "instruction" : self.instruction }));
24        r = r.json(json!({ "model" : self.model }));
25        if let Some(ref unwrapped) = self.n {
26            r = r.json(json!({ "n" : unwrapped }));
27        }
28        if let Some(ref unwrapped) = self.temperature {
29            r = r.json(json!({ "temperature" : unwrapped }));
30        }
31        if let Some(ref unwrapped) = self.top_p {
32            r = r.json(json!({ "top_p" : unwrapped }));
33        }
34        r = self.http_client.authenticate(r);
35        let res = r.send_awaiting_body().await?;
36        res.json()
37    }
38    pub fn input(mut self, input: &str) -> Self {
39        self.input = Some(input.to_owned());
40        self
41    }
42    pub fn n(mut self, n: i64) -> Self {
43        self.n = Some(n);
44        self
45    }
46    pub fn temperature(mut self, temperature: f64) -> Self {
47        self.temperature = Some(temperature);
48        self
49    }
50    pub fn top_p(mut self, top_p: f64) -> Self {
51        self.top_p = Some(top_p);
52        self
53    }
54}
55impl<'a> ::std::future::IntoFuture for CreateEditRequest<'a> {
56    type Output = httpclient::InMemoryResult<CreateEditResponse>;
57    type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
58    fn into_future(self) -> Self::IntoFuture {
59        Box::pin(self.send())
60    }
61}