1use crate::{
2 config::Config,
3 error::OpenAIError,
4 types::finetuning::{
5 CreateFineTuningCheckpointPermissionRequest, CreateFineTuningJobRequest,
6 DeleteFineTuningCheckpointPermissionResponse, FineTuningJob,
7 ListFineTuningCheckpointPermissionResponse, ListFineTuningJobCheckpointsResponse,
8 ListFineTuningJobEventsResponse, ListPaginatedFineTuningJobsResponse,
9 },
10 Client, RequestOptions,
11};
12
13pub struct FineTuning<'c, C: Config> {
17 client: &'c Client<C>,
18 pub(crate) request_options: RequestOptions,
19}
20
21impl<'c, C: Config> FineTuning<'c, C> {
22 pub fn new(client: &'c Client<C>) -> Self {
23 Self {
24 client,
25 request_options: RequestOptions::new(),
26 }
27 }
28
29 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
36 pub async fn create(
37 &self,
38 request: CreateFineTuningJobRequest,
39 ) -> Result<FineTuningJob, OpenAIError> {
40 self.client
41 .post("/fine_tuning/jobs", request, &self.request_options)
42 .await
43 }
44
45 #[crate::byot(R = serde::de::DeserializeOwned)]
47 pub async fn list_paginated(&self) -> Result<ListPaginatedFineTuningJobsResponse, OpenAIError> {
48 self.client
49 .get("/fine_tuning/jobs", &self.request_options)
50 .await
51 }
52
53 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
57 pub async fn retrieve(&self, fine_tuning_job_id: &str) -> Result<FineTuningJob, OpenAIError> {
58 self.client
59 .get(
60 format!("/fine_tuning/jobs/{fine_tuning_job_id}").as_str(),
61 &self.request_options,
62 )
63 .await
64 }
65
66 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
68 pub async fn cancel(&self, fine_tuning_job_id: &str) -> Result<FineTuningJob, OpenAIError> {
69 self.client
70 .post(
71 format!("/fine_tuning/jobs/{fine_tuning_job_id}/cancel").as_str(),
72 (),
73 &self.request_options,
74 )
75 .await
76 }
77
78 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
80 pub async fn pause(&self, fine_tuning_job_id: &str) -> Result<FineTuningJob, OpenAIError> {
81 self.client
82 .post(
83 format!("/fine_tuning/jobs/{fine_tuning_job_id}/pause").as_str(),
84 (),
85 &self.request_options,
86 )
87 .await
88 }
89
90 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
92 pub async fn resume(&self, fine_tuning_job_id: &str) -> Result<FineTuningJob, OpenAIError> {
93 self.client
94 .post(
95 format!("/fine_tuning/jobs/{fine_tuning_job_id}/resume").as_str(),
96 (),
97 &self.request_options,
98 )
99 .await
100 }
101
102 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
104 pub async fn list_events(
105 &self,
106 fine_tuning_job_id: &str,
107 ) -> Result<ListFineTuningJobEventsResponse, OpenAIError> {
108 self.client
109 .get(
110 format!("/fine_tuning/jobs/{fine_tuning_job_id}/events").as_str(),
111 &self.request_options,
112 )
113 .await
114 }
115
116 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
118 pub async fn list_checkpoints(
119 &self,
120 fine_tuning_job_id: &str,
121 ) -> Result<ListFineTuningJobCheckpointsResponse, OpenAIError> {
122 self.client
123 .get(
124 format!("/fine_tuning/jobs/{fine_tuning_job_id}/checkpoints").as_str(),
125 &self.request_options,
126 )
127 .await
128 }
129
130 #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
131 pub async fn create_checkpoint_permissions(
132 &self,
133 fine_tuned_model_checkpoint: &str,
134 request: CreateFineTuningCheckpointPermissionRequest,
135 ) -> Result<ListFineTuningCheckpointPermissionResponse, OpenAIError> {
136 self.client
137 .post(
138 format!("/fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions")
139 .as_str(),
140 request,
141 &self.request_options,
142 )
143 .await
144 }
145
146 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
147 pub async fn list_checkpoint_permissions(
148 &self,
149 fine_tuned_model_checkpoint: &str,
150 ) -> Result<ListFineTuningCheckpointPermissionResponse, OpenAIError> {
151 self.client
152 .get(
153 format!("/fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions")
154 .as_str(),
155 &self.request_options,
156 )
157 .await
158 }
159
160 #[crate::byot(T0 = std::fmt::Display, T1 = std::fmt::Display, R = serde::de::DeserializeOwned)]
161 pub async fn delete_checkpoint_permissions(
162 &self,
163 fine_tuned_model_checkpoint: &str,
164 permission_id: &str,
165 ) -> Result<DeleteFineTuningCheckpointPermissionResponse, OpenAIError> {
166 self.client
167 .delete(
168 format!("/fine_tuning/checkpoints/{fine_tuned_model_checkpoint}/permissions/{permission_id}")
169 .as_str(),
170 &self.request_options,
171 )
172 .await
173 }
174}