1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//! Manage fine-tuning jobs to tailor a model to your specific training data.
//!
//! Related guide: [Fine-tune models](https://platform.openai.com/docs/guides/fine-tuning)
use crate::client::OpenAI;
use crate::interfaces::fine_tunes;
use crate::shared::response_wrapper::{OpenAIError, OpenAIResponse};
use futures::Stream;
use std::pin::Pin;
pub struct FineTunes<'a> {
openai: &'a OpenAI,
}
impl<'a> FineTunes<'a> {
pub fn new(openai: &'a OpenAI) -> Self {
Self { openai }
}
/// Creates a job that fine-tunes a specified model from a given dataset.
///
/// OpenAIResponse includes details of the enqueued job including job status and the name of the fine-tuned models once complete.
///
/// [Learn more about Fine-tuning](https://platform.openai.com/docs/guides/fine-tuning)
pub async fn create(
&self,
req: &fine_tunes::CreateFineTuneRequest,
) -> OpenAIResponse<fine_tunes::FineTuneResponse> {
self.openai.post("/fine-tunes", req).await
}
/// Gets info about the fine-tune job.
///
/// # Path parameters
///
/// - `fine_tune_id` - The ID of the fine-tune job
///
/// [Learn more about Fine-tuning](https://platform.openai.com/docs/guides/fine-tuning)
pub async fn retrieve(
&self,
fine_tune_id: &str,
) -> OpenAIResponse<fine_tunes::FineTuneResponse> {
self.openai
.get(&format!("/fine-tunes/{fine_tune_id}"), &())
.await
}
/// Immediately cancel a fine-tune job.
///
/// # Path parameters
///
/// - `fine_tune_id` - The ID of the fine-tune job to cancel
pub async fn cancel(&self, fine_tune_id: &str) -> OpenAIResponse<fine_tunes::FineTuneResponse> {
self.openai
.post(&format!("/fine-tunes/{fine_tune_id}/cancel"), &())
.await
}
/// List your organization's fine-tuning jobs
pub async fn list(&self) -> OpenAIResponse<fine_tunes::FineTuneListResponse> {
self.openai.get("/fine-tunes", &()).await
}
/// Get fine-grained status updates for a fine-tune job.
///
/// Only events generated so far will be returned.
///
/// # Path parameters
///
/// - `fine_tune_id` - The ID of the fine-tune job to get events for.
///
/// TODO: Since free accounts cannot read fine-tune event content, I have to verify this api until purchase a Plus.
pub async fn retrieve_content(
&self,
fine_tune_id: &str,
) -> OpenAIResponse<fine_tunes::EventListResponse> {
self.openai
.get(&format!("/fine-tunes/{fine_tune_id}/events"), &())
.await
}
/// Get fine-grained status updates for a fine-tune job by stream.
///
/// Events will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) as they become available.
/// The stream will terminate with a `data: [DONE]` message when the job is finished (succeeded, cancelled, or failed).
///
/// # Path parameters
///
/// - `fine_tune_id` - The ID of the fine-tune job to get events for.
///
/// TODO: Since free accounts cannot read fine-tune event content, I have to verify this api until purchase a Plus.
pub async fn retrieve_content_stream(
&self,
fine_tune_id: &str,
) -> Result<
Pin<Box<dyn Stream<Item = OpenAIResponse<fine_tunes::EventListResponse>> + Send>>,
OpenAIError,
> {
Ok(self
.openai
.get_stream(
&format!("/fine-tunes/{fine_tune_id}/events"),
&("stream", true),
)
.await)
}
/// Delete a fine-tuned model. You must have the Owner role in your organization.
///
/// # Path parameters
///
/// - `model` - The model to delete
pub async fn delete_model(
&self,
model: &str,
) -> OpenAIResponse<fine_tunes::DeleteFileResponse> {
self.openai.delete(&format!("/models/{model}"), &()).await
}
}