pub struct OpenAIConfig {
pub api_key: Option<String>,
pub base_url: String,
pub default_model: String,
pub max_context_tokens: usize,
pub retry_policy: RetryPolicy,
}Expand description
Configuration for OpenAI GPT models.
Supports GPT-4, GPT-3.5, and other OpenAI models. Also works with OpenAI-compatible APIs by changing the base URL.
§Example
use multi_llm::OpenAIConfig;
let config = OpenAIConfig {
api_key: Some("sk-...".to_string()),
default_model: "gpt-4-turbo-preview".to_string(),
..Default::default()
};§Environment Variables
OPENAI_API_KEY: API key (required)OPENAI_BASE_URL: Custom base URL (optional)
§Models
gpt-4-turbo-preview: Latest GPT-4 Turbo (128K context)gpt-4: Standard GPT-4 (8K context)gpt-3.5-turbo: Fast and affordable (16K context)
Fields§
§api_key: Option<String>OpenAI API key (starts with “sk-”).
base_url: StringBase URL for API requests (default: https://api.openai.com).
default_model: StringDefault model to use for requests.
max_context_tokens: usizeMaximum context window size in tokens.
retry_policy: RetryPolicyRetry policy for transient failures.
Trait Implementations§
Source§impl Clone for OpenAIConfig
impl Clone for OpenAIConfig
Source§fn clone(&self) -> OpenAIConfig
fn clone(&self) -> OpenAIConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for OpenAIConfig
impl Debug for OpenAIConfig
Source§impl Default for OpenAIConfig
impl Default for OpenAIConfig
Source§impl<'de> Deserialize<'de> for OpenAIConfig
impl<'de> Deserialize<'de> for OpenAIConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl ProviderConfig for OpenAIConfig
impl ProviderConfig for OpenAIConfig
Source§fn provider_name(&self) -> &'static str
fn provider_name(&self) -> &'static str
Get the provider identifier (e.g., “openai”, “anthropic”).
Source§fn max_context_tokens(&self) -> usize
fn max_context_tokens(&self) -> usize
Get the maximum context window size in tokens.
Source§fn validate(&self) -> LlmResult<()>
fn validate(&self) -> LlmResult<()>
Validate that the configuration is complete and valid. Read more
Source§fn default_model(&self) -> &str
fn default_model(&self) -> &str
Get the default model name for this provider.
Source§fn retry_policy(&self) -> &RetryPolicy
fn retry_policy(&self) -> &RetryPolicy
Get the retry policy for transient failures.
Auto Trait Implementations§
impl Freeze for OpenAIConfig
impl RefUnwindSafe for OpenAIConfig
impl Send for OpenAIConfig
impl Sync for OpenAIConfig
impl Unpin for OpenAIConfig
impl UnwindSafe for OpenAIConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more