Skip to content

Commit

Permalink
Merge pull request #64 from Arend-Jan/63-adding-gpt-4o-support
Browse files Browse the repository at this point in the history
63 adding gpt-4o support
  • Loading branch information
Arend-Jan authored May 14, 2024
2 parents 0f8378f + c4fea11 commit fb2ff3e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chat-gpt-lib-rs"
version = "0.3.4"
version = "0.4.0"
edition = "2021"
description = "A Rust library for interacting with OpenAI's ChatGPT API, providing a simple interface to make API requests and handle responses."
license = "Apache-2.0"
Expand All @@ -21,7 +21,7 @@ log = "0.4"
reqwest = { version = "0.12", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.36", features = ["full"] }
tokio = { version = "1.37", features = ["full"] }

[dev-dependencies]
dotenvy = "0.15"
Expand Down
45 changes: 45 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub enum Model {
Gpt_4_32k,
#[serde(rename = "gpt-4-1106-preview")]
Gpt_4Turbo,
#[serde(rename = "gpt-4o")]
Gpt_4o,
#[serde(rename = "gpt-4-vision-preview")]
Gpt_4Turbo_Vision,
}
Expand All @@ -32,6 +34,7 @@ impl Model {
Model::Gpt3_5Turbo => 4096,
Model::Gpt_4 => 8192,
Model::Gpt_4_32k => 32768,
Model::Gpt_4o => 128000,
Model::Gpt_4Turbo => 128000,
Model::Gpt_4Turbo_Vision => 128000,
}
Expand All @@ -45,6 +48,7 @@ impl Display for Model {
Model::Gpt3_5Turbo => "gpt-3.5-turbo",
Model::Gpt_4 => "gpt-4",
Model::Gpt_4_32k => "gpt-4-32k",
Model::Gpt_4o => "gpt-4o",
Model::Gpt_4Turbo => "gpt-4-1106-preview",
Model::Gpt_4Turbo_Vision => "gpt-4-vision-preview",
};
Expand All @@ -61,6 +65,7 @@ impl FromStr for Model {
"gpt-3.5-turbo" => Ok(Model::Gpt3_5Turbo),
"gpt-4" => Ok(Model::Gpt_4),
"gpt-4-32k" => Ok(Model::Gpt_4_32k),
"gpt-4o" => Ok(Model::Gpt_4o),
"gpt-4-1106-preview" => Ok(Model::Gpt_4Turbo),
"gpt-4-vision-preview" => Ok(Model::Gpt_4Turbo_Vision),
_ => Err(()),
Expand Down Expand Up @@ -334,4 +339,44 @@ mod tests {
let model = Model::Gpt_4Turbo_Vision;
assert_eq!(model.max_tokens(), 128000);
}

// Test the conversion of a Model enum variant to its string representation for Gpt_4o.
#[test]
fn test_display_gpt_4o() {
let model = Model::Gpt_4o;
let model_str = format!("{}", model);
assert_eq!(model_str, "gpt-4o");
}

// Test the conversion of a valid model string to a Model enum variant for Gpt_4o.
#[test]
fn test_from_str_gpt_4o() {
let input = "gpt-4o";
let model: Result<Model, ()> = Model::from_str(input);
assert!(model.is_ok(), "Failed to parse the gpt-4o model name");
assert_eq!(model.unwrap(), Model::Gpt_4o);
}

// Test the serialization of a Model enum variant to JSON for Gpt_4o.
#[test]
fn test_serialize_gpt_4o() {
let model = Model::Gpt_4o;
let serialized_model = serde_json::to_string(&model).unwrap();
assert_eq!(serialized_model, "\"gpt-4o\"");
}

// Test the deserialization of a JSON string to a Model enum variant for Gpt_4o.
#[test]
fn test_deserialize_gpt_4o() {
let model_json = "\"gpt-4o\"";
let deserialized_model: Model = serde_json::from_str(model_json).unwrap();
assert_eq!(deserialized_model, Model::Gpt_4o);
}

// Test the max tokens for Gpt_4o.
#[test]
fn test_max_tokens_gpt_4o() {
let model = Model::Gpt_4o;
assert_eq!(model.max_tokens(), 128000);
}
}

0 comments on commit fb2ff3e

Please sign in to comment.