openai/request/
create_fine_tune.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 CreateFineTuneRequest<'a> {
9    pub(crate) http_client: &'a OpenAiClient,
10    pub batch_size: Option<i64>,
11    pub classification_betas: Option<Vec<f64>>,
12    pub classification_n_classes: Option<i64>,
13    pub classification_positive_class: Option<String>,
14    pub compute_classification_metrics: Option<bool>,
15    pub learning_rate_multiplier: Option<f64>,
16    pub model: Option<String>,
17    pub n_epochs: Option<i64>,
18    pub prompt_loss_weight: Option<f64>,
19    pub suffix: Option<String>,
20    pub training_file: String,
21    pub validation_file: Option<String>,
22}
23impl<'a> CreateFineTuneRequest<'a> {
24    pub async fn send(self) -> ::httpclient::InMemoryResult<FineTune> {
25        let mut r = self.http_client.client.post("/fine-tunes");
26        if let Some(ref unwrapped) = self.batch_size {
27            r = r.json(json!({ "batch_size" : unwrapped }));
28        }
29        if let Some(ref unwrapped) = self.classification_betas {
30            r = r.json(json!({ "classification_betas" : unwrapped }));
31        }
32        if let Some(ref unwrapped) = self.classification_n_classes {
33            r = r.json(json!({ "classification_n_classes" : unwrapped }));
34        }
35        if let Some(ref unwrapped) = self.classification_positive_class {
36            r = r.json(json!({ "classification_positive_class" : unwrapped }));
37        }
38        if let Some(ref unwrapped) = self.compute_classification_metrics {
39            r = r.json(json!({ "compute_classification_metrics" : unwrapped }));
40        }
41        if let Some(ref unwrapped) = self.learning_rate_multiplier {
42            r = r.json(json!({ "learning_rate_multiplier" : unwrapped }));
43        }
44        if let Some(ref unwrapped) = self.model {
45            r = r.json(json!({ "model" : unwrapped }));
46        }
47        if let Some(ref unwrapped) = self.n_epochs {
48            r = r.json(json!({ "n_epochs" : unwrapped }));
49        }
50        if let Some(ref unwrapped) = self.prompt_loss_weight {
51            r = r.json(json!({ "prompt_loss_weight" : unwrapped }));
52        }
53        if let Some(ref unwrapped) = self.suffix {
54            r = r.json(json!({ "suffix" : unwrapped }));
55        }
56        r = r.json(json!({ "training_file" : self.training_file }));
57        if let Some(ref unwrapped) = self.validation_file {
58            r = r.json(json!({ "validation_file" : unwrapped }));
59        }
60        r = self.http_client.authenticate(r);
61        let res = r.send_awaiting_body().await?;
62        res.json()
63    }
64    pub fn batch_size(mut self, batch_size: i64) -> Self {
65        self.batch_size = Some(batch_size);
66        self
67    }
68    pub fn classification_betas(mut self, classification_betas: Vec<f64>) -> Self {
69        self.classification_betas = Some(classification_betas);
70        self
71    }
72    pub fn classification_n_classes(mut self, classification_n_classes: i64) -> Self {
73        self.classification_n_classes = Some(classification_n_classes);
74        self
75    }
76    pub fn classification_positive_class(
77        mut self,
78        classification_positive_class: &str,
79    ) -> Self {
80        self
81            .classification_positive_class = Some(
82            classification_positive_class.to_owned(),
83        );
84        self
85    }
86    pub fn compute_classification_metrics(
87        mut self,
88        compute_classification_metrics: bool,
89    ) -> Self {
90        self.compute_classification_metrics = Some(compute_classification_metrics);
91        self
92    }
93    pub fn learning_rate_multiplier(mut self, learning_rate_multiplier: f64) -> Self {
94        self.learning_rate_multiplier = Some(learning_rate_multiplier);
95        self
96    }
97    pub fn model(mut self, model: &str) -> Self {
98        self.model = Some(model.to_owned());
99        self
100    }
101    pub fn n_epochs(mut self, n_epochs: i64) -> Self {
102        self.n_epochs = Some(n_epochs);
103        self
104    }
105    pub fn prompt_loss_weight(mut self, prompt_loss_weight: f64) -> Self {
106        self.prompt_loss_weight = Some(prompt_loss_weight);
107        self
108    }
109    pub fn suffix(mut self, suffix: &str) -> Self {
110        self.suffix = Some(suffix.to_owned());
111        self
112    }
113    pub fn validation_file(mut self, validation_file: &str) -> Self {
114        self.validation_file = Some(validation_file.to_owned());
115        self
116    }
117}
118impl<'a> ::std::future::IntoFuture for CreateFineTuneRequest<'a> {
119    type Output = httpclient::InMemoryResult<FineTune>;
120    type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
121    fn into_future(self) -> Self::IntoFuture {
122        Box::pin(self.send())
123    }
124}