openai/request/
create_image.rs1use serde_json::json;
2use crate::model::*;
3use crate::OpenAiClient;
4#[derive(Clone)]
8pub struct CreateImageRequest<'a> {
9 pub(crate) http_client: &'a OpenAiClient,
10 pub n: Option<i64>,
11 pub prompt: String,
12 pub response_format: Option<String>,
13 pub size: Option<String>,
14 pub user: Option<String>,
15}
16impl<'a> CreateImageRequest<'a> {
17 pub async fn send(self) -> ::httpclient::InMemoryResult<ImagesResponse> {
18 let mut r = self.http_client.client.post("/images/generations");
19 if let Some(ref unwrapped) = self.n {
20 r = r.json(json!({ "n" : unwrapped }));
21 }
22 r = r.json(json!({ "prompt" : self.prompt }));
23 if let Some(ref unwrapped) = self.response_format {
24 r = r.json(json!({ "response_format" : unwrapped }));
25 }
26 if let Some(ref unwrapped) = self.size {
27 r = r.json(json!({ "size" : unwrapped }));
28 }
29 if let Some(ref unwrapped) = self.user {
30 r = r.json(json!({ "user" : unwrapped }));
31 }
32 r = self.http_client.authenticate(r);
33 let res = r.send_awaiting_body().await?;
34 res.json()
35 }
36 pub fn n(mut self, n: i64) -> Self {
37 self.n = Some(n);
38 self
39 }
40 pub fn response_format(mut self, response_format: &str) -> Self {
41 self.response_format = Some(response_format.to_owned());
42 self
43 }
44 pub fn size(mut self, size: &str) -> Self {
45 self.size = Some(size.to_owned());
46 self
47 }
48 pub fn user(mut self, user: &str) -> Self {
49 self.user = Some(user.to_owned());
50 self
51 }
52}
53impl<'a> ::std::future::IntoFuture for CreateImageRequest<'a> {
54 type Output = httpclient::InMemoryResult<ImagesResponse>;
55 type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
56 fn into_future(self) -> Self::IntoFuture {
57 Box::pin(self.send())
58 }
59}