openai/request/
create_moderation.rs1use serde_json::json;
2use crate::model::*;
3use crate::OpenAiClient;
4#[derive(Clone)]
8pub struct CreateModerationRequest<'a> {
9 pub(crate) http_client: &'a OpenAiClient,
10 pub input: serde_json::Value,
11 pub model: Option<String>,
12}
13impl<'a> CreateModerationRequest<'a> {
14 pub async fn send(self) -> ::httpclient::InMemoryResult<CreateModerationResponse> {
15 let mut r = self.http_client.client.post("/moderations");
16 r = r.json(json!({ "input" : self.input }));
17 if let Some(ref unwrapped) = self.model {
18 r = r.json(json!({ "model" : unwrapped }));
19 }
20 r = self.http_client.authenticate(r);
21 let res = r.send_awaiting_body().await?;
22 res.json()
23 }
24 pub fn model(mut self, model: &str) -> Self {
25 self.model = Some(model.to_owned());
26 self
27 }
28}
29impl<'a> ::std::future::IntoFuture for CreateModerationRequest<'a> {
30 type Output = httpclient::InMemoryResult<CreateModerationResponse>;
31 type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
32 fn into_future(self) -> Self::IntoFuture {
33 Box::pin(self.send())
34 }
35}