Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAI o1 model #60

Merged
merged 9 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[package]
name = "allms"
version = "0.13.0"
version = "0.14.0"
edition = "2021"
authors = [
"Kamil Litman <[email protected]>",
"Dario Lencina <[email protected]>",
"Dario Lencina <[email protected]>",
"Nate Dubetz <[email protected]>"
]
keywords = ["openai", "anthropic", "mistral", "gemini", "assistant"]
description = "One Library to rule them aLLMs"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ Mistral:

OpenAI:
- APIs: Chat Completions, Function Calling, Assistants (v1 & v2), Files, Vector Stores, Tools (file_search)
- Models: o1 Preview, o1 Mini (Chat Completions only), GPT-4o, GPT-4, GPT-4 32k, GPT-4 Turbo, GPT-3.5 Turbo, GPT-3.5 Turbo 16k, fine-tuned models (via `Custom` variant)
- Models:
- Chat Completions only: o1, o1 Preview, o1 Mini, o3 Mini
- Chat Completions & Assistants: GPT-4o, GPT-4, GPT-4 32k, GPT-4 Turbo, GPT-3.5 Turbo, GPT-3.5 Turbo 16k, fine-tuned models (via `Custom` variant)

Perplexity:
- APIs: Chat Completions
Expand Down
2 changes: 1 addition & 1 deletion examples/use_completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async fn main() {

// Get answer using OpenAI
let openai_api_key: String = std::env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY not set");
let model = OpenAIModels::try_from_str("gpt-4o-mini").unwrap_or(OpenAIModels::Gpt4oMini); // Choose the model
let model = OpenAIModels::try_from_str("o3-mini").unwrap_or(OpenAIModels::Gpt4oMini); // Choose the model
println!("OpenAI model: {:#?}", model.as_str());

let openai_completion = Completions::new(model, &openai_api_key, None, None);
Expand Down
8 changes: 7 additions & 1 deletion src/assistants/openai/openai_assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ pub struct OpenAIAssistant {
}

impl OpenAIAssistant {
//Constructor
/// Constructor of the Assistant
/// Reasoning models are not currently supported in Assistants API. If requested defaulting to `Gpt4o`
pub fn new(model: OpenAIModels, open_ai_key: &str) -> Self {
let model = match model.assistants_support() {
false => OpenAIModels::Gpt4o,
_ => model,
};

OpenAIAssistant {
id: None,
thread_id: None,
Expand Down
44 changes: 41 additions & 3 deletions src/llm_models/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ pub enum OpenAIModels {
Gpt4o,
Gpt4o20240806,
Gpt4oMini,
// Reasoning models
O1Preview,
O1Mini,
O1,
O3Mini,
// Custom models
Custom { name: String },
}

Expand All @@ -47,6 +51,8 @@ impl LLMModel for OpenAIModels {
OpenAIModels::Gpt4oMini => "gpt-4o-mini",
OpenAIModels::O1Preview => "o1-preview",
OpenAIModels::O1Mini => "o1-mini",
OpenAIModels::O1 => "o1",
OpenAIModels::O3Mini => "o3-mini",
OpenAIModels::Custom { name } => name.as_str(),
}
}
Expand All @@ -66,6 +72,8 @@ impl LLMModel for OpenAIModels {
"gpt-4o-mini" => Some(OpenAIModels::Gpt4oMini),
"o1-preview" => Some(OpenAIModels::O1Preview),
"o1-mini" => Some(OpenAIModels::O1Mini),
"o1" => Some(OpenAIModels::O1),
"o3-mini" => Some(OpenAIModels::O3Mini),
_ => Some(OpenAIModels::Custom {
name: name.to_string(),
}),
Expand All @@ -89,6 +97,8 @@ impl LLMModel for OpenAIModels {
OpenAIModels::Gpt4oMini => 128_000,
OpenAIModels::O1Preview => 128_000,
OpenAIModels::O1Mini => 128_000,
OpenAIModels::O1 => 200_000,
OpenAIModels::O3Mini => 200_000,
OpenAIModels::Custom { .. } => 128_000,
}
}
Expand All @@ -108,6 +118,8 @@ impl LLMModel for OpenAIModels {
| OpenAIModels::Gpt4_32k
| OpenAIModels::O1Preview
| OpenAIModels::O1Mini
| OpenAIModels::O1
| OpenAIModels::O3Mini
| OpenAIModels::Custom { .. } => {
format!(
"{OPENAI_API_URL}/v1/chat/completions",
Expand Down Expand Up @@ -136,7 +148,9 @@ impl LLMModel for OpenAIModels {
| OpenAIModels::Gpt3_5Turbo
| OpenAIModels::Gpt4_32k
| OpenAIModels::O1Preview
| OpenAIModels::O1Mini => false,
| OpenAIModels::O1
| OpenAIModels::O1Mini
| OpenAIModels::O3Mini => false,
OpenAIModels::Gpt3_5Turbo0613
| OpenAIModels::Gpt3_5Turbo16k
| OpenAIModels::Gpt4
Expand Down Expand Up @@ -256,7 +270,10 @@ impl LLMModel for OpenAIModels {
// - Tools: tools, function calling, and response format parameters are not supported.
// - Other: temperature, top_p and n are fixed at 1, while presence_penalty and frequency_penalty are fixed at 0.
// - Assistants and Batch: these models are not supported in the Assistants API or Batch API.
OpenAIModels::O1Preview | OpenAIModels::O1Mini => {
OpenAIModels::O1Preview
| OpenAIModels::O1Mini
| OpenAIModels::O1
| OpenAIModels::O3Mini => {
let base_instructions = self.get_base_instructions(Some(function_call));
let system_message = json!({
"role": "user",
Expand Down Expand Up @@ -352,6 +369,8 @@ impl LLMModel for OpenAIModels {
| OpenAIModels::Gpt4_32k
| OpenAIModels::O1Preview
| OpenAIModels::O1Mini
| OpenAIModels::O1
| OpenAIModels::O3Mini
| OpenAIModels::Custom { .. } => {
//Convert API response to struct representing expected response format
let chat_response: OpenAPIChatResponse = serde_json::from_str(response_text)?;
Expand Down Expand Up @@ -425,7 +444,6 @@ impl LLMModel for OpenAIModels {
tpm: 1_000_000,
rpm: 10_000,
},
// https://help.openai.com/en/articles/9824962-openai-o1-preview-and-o1-mini-usage-limits-on-chatgpt-and-the-api
OpenAIModels::O1Preview => RateLimit {
tpm: 30_000_000,
rpm: 10_000,
Expand All @@ -434,6 +452,14 @@ impl LLMModel for OpenAIModels {
tpm: 150_000_000,
rpm: 30_000,
},
OpenAIModels::O1 => RateLimit {
tpm: 30_000_000,
rpm: 1_000,
},
OpenAIModels::O3Mini => RateLimit {
tpm: 150_000_000,
rpm: 30_000,
},
OpenAIModels::TextDavinci003 => RateLimit {
tpm: 250_000,
rpm: 3_000,
Expand Down Expand Up @@ -476,6 +502,18 @@ impl OpenAIModels {
| OpenAIModels::Custom { .. }
)
}

// This function checks if a model supports use in Assistants API
// Reasoning models are NOT currently supported
pub fn assistants_support(&self) -> bool {
!matches!(
self,
OpenAIModels::O1Preview
| OpenAIModels::O1Mini
| OpenAIModels::O1
| OpenAIModels::O3Mini
)
}
}

#[cfg(test)]
Expand Down