Skip to content

Commit

Permalink
feat: update examples for fine_tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
YanceyOfficial committed Oct 22, 2024
1 parent 0f6e052 commit 662d50e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 76 deletions.
61 changes: 0 additions & 61 deletions examples/fine_tunes/src/main.rs

This file was deleted.

File renamed without changes.
47 changes: 47 additions & 0 deletions examples/fine_tuning/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use dotenvy::dotenv;
use futures::StreamExt;
use rs_openai::{fine_tuning::CreateFineTuningRequestBuilder, OpenAI};
use std::env::var;
use std::io::{stdout, Write};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
let api_key = var("OPENAI_API_KEY").unwrap();

let client = OpenAI::new(&OpenAI {
api_key,
org_id: None,
});

// create
let req = CreateFineTuningRequestBuilder::default()
.training_file("YOUR_FINE_TUNE_FILE")
.model("davinci")
.build()?;

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

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

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

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

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

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

Ok(())
}
30 changes: 15 additions & 15 deletions rs_openai/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,21 @@ impl OpenAI {
Self::resolve_response(request).await
}

pub(crate) async fn get_stream<T, F>(
&self,
route: &str,
query: &F,
) -> Pin<Box<dyn Stream<Item = OpenAIResponse<T>> + Send>>
where
T: DeserializeOwned + Debug + Send + 'static,
F: Serialize,
{
let event_source = self
.openai_request(Method::GET, route, |request| request.query(query))
.eventsource()
.unwrap();
Self::stream_sse(event_source).await
}
// pub(crate) async fn get_stream<T, F>(
// &self,
// route: &str,
// query: &F,
// ) -> Pin<Box<dyn Stream<Item = OpenAIResponse<T>> + Send>>
// where
// T: DeserializeOwned + Debug + Send + 'static,
// F: Serialize,
// {
// let event_source = self
// .openai_request(Method::GET, route, |request| request.query(query))
// .eventsource()
// .unwrap();
// Self::stream_sse(event_source).await
// }

pub(crate) async fn post<T, F>(&self, route: &str, json: &F) -> OpenAIResponse<T>
where
Expand Down

0 comments on commit 662d50e

Please sign in to comment.