openai/request/
create_classification.rs1use serde_json::json;
2use crate::model::*;
3use crate::OpenAiClient;
4#[derive(Clone)]
8pub struct CreateClassificationRequest<'a> {
9 pub(crate) http_client: &'a OpenAiClient,
10 pub examples: Option<Vec<Vec<String>>>,
11 pub expand: Option<Vec<serde_json::Value>>,
12 pub file: Option<String>,
13 pub labels: Option<Vec<String>>,
14 pub logit_bias: Option<serde_json::Value>,
15 pub logprobs: Option<i64>,
16 pub max_examples: Option<i64>,
17 pub model: String,
18 pub query: String,
19 pub return_metadata: Option<bool>,
20 pub return_prompt: Option<bool>,
21 pub search_model: Option<String>,
22 pub temperature: Option<f64>,
23 pub user: Option<String>,
24}
25impl<'a> CreateClassificationRequest<'a> {
26 pub async fn send(
27 self,
28 ) -> ::httpclient::InMemoryResult<CreateClassificationResponse> {
29 let mut r = self.http_client.client.post("/classifications");
30 if let Some(ref unwrapped) = self.examples {
31 r = r.json(json!({ "examples" : unwrapped }));
32 }
33 if let Some(ref unwrapped) = self.expand {
34 r = r.json(json!({ "expand" : unwrapped }));
35 }
36 if let Some(ref unwrapped) = self.file {
37 r = r.json(json!({ "file" : unwrapped }));
38 }
39 if let Some(ref unwrapped) = self.labels {
40 r = r.json(json!({ "labels" : unwrapped }));
41 }
42 if let Some(ref unwrapped) = self.logit_bias {
43 r = r.json(json!({ "logit_bias" : unwrapped }));
44 }
45 if let Some(ref unwrapped) = self.logprobs {
46 r = r.json(json!({ "logprobs" : unwrapped }));
47 }
48 if let Some(ref unwrapped) = self.max_examples {
49 r = r.json(json!({ "max_examples" : unwrapped }));
50 }
51 r = r.json(json!({ "model" : self.model }));
52 r = r.json(json!({ "query" : self.query }));
53 if let Some(ref unwrapped) = self.return_metadata {
54 r = r.json(json!({ "return_metadata" : unwrapped }));
55 }
56 if let Some(ref unwrapped) = self.return_prompt {
57 r = r.json(json!({ "return_prompt" : unwrapped }));
58 }
59 if let Some(ref unwrapped) = self.search_model {
60 r = r.json(json!({ "search_model" : unwrapped }));
61 }
62 if let Some(ref unwrapped) = self.temperature {
63 r = r.json(json!({ "temperature" : unwrapped }));
64 }
65 if let Some(ref unwrapped) = self.user {
66 r = r.json(json!({ "user" : unwrapped }));
67 }
68 r = self.http_client.authenticate(r);
69 let res = r.send_awaiting_body().await?;
70 res.json()
71 }
72 pub fn examples(mut self, examples: &[&[&str]]) -> Self {
73 self.examples = Some(examples
74 .into_iter()
75 .map(|s| s
76 .into_iter()
77 .map(|&s| s.to_owned())
78 .collect()
79 ).collect()
80 );
81 self
82 }
83 pub fn expand(mut self, expand: Vec<serde_json::Value>) -> Self {
84 self.expand = Some(expand);
85 self
86 }
87 pub fn file(mut self, file: &str) -> Self {
88 self.file = Some(file.to_owned());
89 self
90 }
91 pub fn labels(mut self, labels: impl IntoIterator<Item = impl AsRef<str>>) -> Self {
92 self.labels = Some(labels.into_iter().map(|s| s.as_ref().to_owned()).collect());
93 self
94 }
95 pub fn logit_bias(mut self, logit_bias: serde_json::Value) -> Self {
96 self.logit_bias = Some(logit_bias);
97 self
98 }
99 pub fn logprobs(mut self, logprobs: i64) -> Self {
100 self.logprobs = Some(logprobs);
101 self
102 }
103 pub fn max_examples(mut self, max_examples: i64) -> Self {
104 self.max_examples = Some(max_examples);
105 self
106 }
107 pub fn return_metadata(mut self, return_metadata: bool) -> Self {
108 self.return_metadata = Some(return_metadata);
109 self
110 }
111 pub fn return_prompt(mut self, return_prompt: bool) -> Self {
112 self.return_prompt = Some(return_prompt);
113 self
114 }
115 pub fn search_model(mut self, search_model: &str) -> Self {
116 self.search_model = Some(search_model.to_owned());
117 self
118 }
119 pub fn temperature(mut self, temperature: f64) -> Self {
120 self.temperature = Some(temperature);
121 self
122 }
123 pub fn user(mut self, user: &str) -> Self {
124 self.user = Some(user.to_owned());
125 self
126 }
127}
128impl<'a> ::std::future::IntoFuture for CreateClassificationRequest<'a> {
129 type Output = httpclient::InMemoryResult<CreateClassificationResponse>;
130 type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
131 fn into_future(self) -> Self::IntoFuture {
132 Box::pin(self.send())
133 }
134}