Skip to content

Commit

Permalink
feat: migrate from fine_tunes to fine_tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
YanceyOfficial committed Oct 22, 2024
1 parent 26a1872 commit 0f6e052
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 296 deletions.
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ members = [
"embeddings",
"engines",
"files",
"fine_tunes",
"fine_tuning",
"images",
"models",
"moderations",
Expand Down
2 changes: 1 addition & 1 deletion examples/fine_tunes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "fine_tunes"
name = "fine_tuning"
version = "0.1.0"
edition = "2021"
publish = false
Expand Down
14 changes: 7 additions & 7 deletions examples/fine_tunes/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dotenvy::dotenv;
use futures::StreamExt;
use rs_openai::{fine_tunes::CreateFineTuneRequestBuilder, OpenAI};
use rs_openai::{fine_tuning::CreateFineTuneRequestBuilder, OpenAI};
use std::env::var;
use std::io::{stdout, Write};

Expand All @@ -24,29 +24,29 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.prompt_loss_weight(0.01)
.build()?;

let res = client.fine_tunes().create(&req).await?;
let res = client.fine_tuning().create(&req).await?;
println!("{:?}", res);

// list
let res = client.fine_tunes().list().await?;
let res = client.fine_tuning().list().await?;
println!("{:?}", res);

// retrieve
let res = client.fine_tunes().retrieve("").await?;
let res = client.fine_tuning().retrieve("").await?;
println!("{:?}", res);

// cancel
let res = client.fine_tunes().cancel("").await?;
let res = client.fine_tuning().cancel("").await?;
println!("{:?}", res);

// retrieve_content
// TODO: Since free accounts cannot read fine-tune event content, I have to verify this api until purchase a Plus.
let res = client.fine_tunes().retrieve_content("").await?;
let res = client.fine_tuning().retrieve_content("").await?;
println!("{:?}", res);

// retrieve_content_stream
// TODO: Since free accounts cannot read fine-tune event content, I have to verify this api until purchase a Plus.
let mut stream = client.fine_tunes().retrieve_content_stream("").await?;
let mut stream = client.fine_tuning().retrieve_content_stream("").await?;

let mut lock = stdout().lock();
while let Some(response) = stream.next().await {
Expand Down
119 changes: 0 additions & 119 deletions rs_openai/src/apis/fine_tunes.rs

This file was deleted.

93 changes: 93 additions & 0 deletions rs_openai/src/apis/fine_tuning.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//! 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_tuning;
use crate::shared::response_wrapper::OpenAIResponse;

pub struct FineTuning<'a> {
openai: &'a OpenAI,
}

impl<'a> FineTuning<'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_tuning::CreateFineTuningRequest,
) -> OpenAIResponse<fine_tuning::FineTuningResponse> {
self.openai.post("/fine-tuning/jobs", req).await
}

/// List your organization's fine-tuning jobs
pub async fn list(
&self,
req: &fine_tuning::ListFineTuningRequest,
) -> OpenAIResponse<fine_tuning::FineTuningEventResponse> {
self.openai.get("/fine-tuning/jobs", req).await
}

/// Get status updates for a fine-tuning job.
pub async fn list_events(
&self,
fine_tuning_job_id: &str, // The ID of the fine-tuning job to get events for.
req: &fine_tuning::ListFineTuningRequest,
) -> OpenAIResponse<fine_tuning::FineTuningEventResponse> {
self.openai
.get(
&format!("/fine-tuning/jobs/{fine_tuning_job_id}/events"),
req,
)
.await
}

/// Get status updates for a fine-tuning job.
pub async fn list_checkpoints(
&self,
fine_tuning_job_id: &str, // The ID of the fine-tuning job to get checkpoints for.
req: &fine_tuning::ListFineTuningRequest,
) -> OpenAIResponse<fine_tuning::FineTuningCheckpointResponse> {
self.openai
.get(
&format!("/fine-tuning/jobs/{fine_tuning_job_id}/checkpoints"),
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_tuning_job_id: &str,
) -> OpenAIResponse<fine_tuning::FineTuningResponse> {
self.openai
.get(&format!("/fine-tuning/jobs/{fine_tuning_job_id}"), &())
.await
}

/// Immediately cancel a fine-tune job.
///
/// # Path parameters
///
/// - `fine_tune_job_id` - The ID of the fine-tune job to cancel
pub async fn cancel(
&self,
fine_tune_job_id: &str,
) -> OpenAIResponse<fine_tuning::FineTuningResponse> {
self.openai
.post(&format!("/fine-tuning/jobs/{fine_tune_job_id}/cancel"), &())
.await
}
}
2 changes: 1 addition & 1 deletion rs_openai/src/apis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod edits;
pub mod embeddings;
pub mod engines;
pub mod files;
pub mod fine_tunes;
pub mod fine_tuning;
pub mod images;
pub mod models;
pub mod moderations;
Expand Down
6 changes: 3 additions & 3 deletions rs_openai/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::apis::{
audio, chat, completions, edits, embeddings, engines, files, fine_tunes, images, models,
audio, chat, completions, edits, embeddings, engines, files, fine_tuning, images, models,
moderations,
};
use crate::shared::response_wrapper::{ApiErrorResponse, OpenAIError, OpenAIResponse};
Expand Down Expand Up @@ -273,8 +273,8 @@ impl OpenAI {
files::Files::new(self)
}

pub fn fine_tunes(&self) -> fine_tunes::FineTunes {
fine_tunes::FineTunes::new(self)
pub fn fine_tuning(&self) -> fine_tuning::FineTuning {
fine_tuning::FineTuning::new(self)
}

pub fn images(&self) -> images::Images {
Expand Down
Loading

0 comments on commit 0f6e052

Please sign in to comment.