Skip to content

Commit

Permalink
Automated update of model definitions
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub Workflow <noreply@github.com>
  • Loading branch information
web-flow authored and Sett17 committed Feb 3, 2024
1 parent 0032fd2 commit 511d0bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "turbocommit"
version = "0.15.1"
version = "0.15.2"
edition = "2021"
authors = [ "Sett",]
description = "A CLI tool to create commit messages with OpenAI GPT models"
Expand Down
30 changes: 30 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use serde::{Serialize, Deserialize};

#[derive(Debug, Copy, Clone, Default, PartialEq)]
pub enum Model {
Gpt40125Preview,
Gpt4TurboPreview,
Gpt41106Preview,
Gpt4VisionPreview,
Gpt4,
Expand All @@ -12,14 +14,19 @@ pub enum Model {
#[default]
Gpt35Turbo,
Gpt35Turbo16k,
Gpt35Turbo0301,
Gpt35Turbo0613,
Gpt35Turbo1106,
Gpt35Turbo16k0613,
}

impl FromStr for Model {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"gpt-4-0125-preview" => Ok(Self::Gpt40125Preview),
"gpt-4-turbo-preview" => Ok(Self::Gpt4TurboPreview),
"gpt-4-1106-preview" => Ok(Self::Gpt41106Preview),
"gpt-4-vision-preview" => Ok(Self::Gpt4VisionPreview),
"gpt-4" => Ok(Self::Gpt4),
Expand All @@ -28,7 +35,10 @@ impl FromStr for Model {
"gpt-4-32k-0613" => Ok(Self::Gpt432k0613),
"gpt-3.5-turbo" => Ok(Self::Gpt35Turbo),
"gpt-3.5-turbo-16k" => Ok(Self::Gpt35Turbo16k),
"gpt-3.5-turbo-0301" => Ok(Self::Gpt35Turbo0301),
"gpt-3.5-turbo-0613" => Ok(Self::Gpt35Turbo0613),
"gpt-3.5-turbo-1106" => Ok(Self::Gpt35Turbo1106),
"gpt-3.5-turbo-16k-0613" => Ok(Self::Gpt35Turbo16k0613),
_ => Err(format!("{} is not a valid model", s)),
}
}
Expand All @@ -38,6 +48,8 @@ impl FromStr for Model {
impl ToString for Model {
fn to_string(&self) -> String {
match self {
Self::Gpt40125Preview { .. } => String::from("gpt-4-0125-preview"),
Self::Gpt4TurboPreview { .. } => String::from("gpt-4-turbo-preview"),
Self::Gpt41106Preview { .. } => String::from("gpt-4-1106-preview"),
Self::Gpt4VisionPreview { .. } => String::from("gpt-4-vision-preview"),
Self::Gpt4 { .. } => String::from("gpt-4"),
Expand All @@ -46,7 +58,10 @@ impl ToString for Model {
Self::Gpt432k0613 { .. } => String::from("gpt-4-32k-0613"),
Self::Gpt35Turbo { .. } => String::from("gpt-3.5-turbo"),
Self::Gpt35Turbo16k { .. } => String::from("gpt-3.5-turbo-16k"),
Self::Gpt35Turbo0301 { .. } => String::from("gpt-3.5-turbo-0301"),
Self::Gpt35Turbo0613 { .. } => String::from("gpt-3.5-turbo-0613"),
Self::Gpt35Turbo1106 { .. } => String::from("gpt-3.5-turbo-1106"),
Self::Gpt35Turbo16k0613 { .. } => String::from("gpt-3.5-turbo-16k-0613"),
}
}
}
Expand All @@ -73,6 +88,8 @@ impl<'de> Deserialize<'de> for Model {
impl Model {
pub fn all() -> Vec<Self> {
vec![
Self::Gpt40125Preview,
Self::Gpt4TurboPreview,
Self::Gpt41106Preview,
Self::Gpt4VisionPreview,
Self::Gpt4,
Expand All @@ -81,12 +98,17 @@ impl Model {
Self::Gpt432k0613,
Self::Gpt35Turbo,
Self::Gpt35Turbo16k,
Self::Gpt35Turbo0301,
Self::Gpt35Turbo0613,
Self::Gpt35Turbo1106,
Self::Gpt35Turbo16k0613,
]
}

pub fn cost(&self, prompt_tokens: usize, completion_tokens: usize) -> f64 {
let (prompt_cost, completion_cost) = match self {
Self::Gpt40125Preview => (0.01, 0.03),
Self::Gpt4TurboPreview => (0.01, 0.03),
Self::Gpt41106Preview => (0.01, 0.03),
Self::Gpt4VisionPreview => (0.01, 0.03),
Self::Gpt4 => (0.01, 0.03),
Expand All @@ -95,7 +117,10 @@ impl Model {
Self::Gpt432k0613 => (0.06, 0.12),
Self::Gpt35Turbo => (0.0015, 0.002),
Self::Gpt35Turbo16k => (0.0015, 0.002),
Self::Gpt35Turbo0301 => (0.0015, 0.002),
Self::Gpt35Turbo0613 => (0.0015, 0.002),
Self::Gpt35Turbo1106 => (0.001, 0.002),
Self::Gpt35Turbo16k0613 => (0.0015, 0.002),
};
(prompt_tokens as f64).mul_add(
prompt_cost / 1000.0,
Expand All @@ -105,6 +130,8 @@ impl Model {

pub const fn context_size(&self) -> usize {
match self {
Self::Gpt40125Preview => 128000,
Self::Gpt4TurboPreview => 128000,
Self::Gpt41106Preview => 128000,
Self::Gpt4VisionPreview => 128000,
Self::Gpt4 => 8192,
Expand All @@ -113,7 +140,10 @@ impl Model {
Self::Gpt432k0613 => 32768,
Self::Gpt35Turbo => 4096,
Self::Gpt35Turbo16k => 16385,
Self::Gpt35Turbo0301 => 4096,
Self::Gpt35Turbo0613 => 4096,
Self::Gpt35Turbo1106 => 16385,
Self::Gpt35Turbo16k0613 => 16385,
}
}
}

0 comments on commit 511d0bc

Please sign in to comment.