diff options
Diffstat (limited to 'src/client/openai.rs')
| -rw-r--r-- | src/client/openai.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/client/openai.rs b/src/client/openai.rs index 4ccb1b7..e0d321d 100644 --- a/src/client/openai.rs +++ b/src/client/openai.rs @@ -14,7 +14,7 @@ use serde_json::{json, Value}; use std::env; use std::time::Duration; -const API_URL: &str = "https://api.openai.com/v1/chat/completions"; +const API_BASE: &str = "https://api.openai.com/v1"; #[derive(Debug)] pub struct OpenAIClient { @@ -161,7 +161,12 @@ impl OpenAIClient { .with_context(|| "Failed to build client")? }; - let mut builder = client.post(API_URL).bearer_auth(api_key).json(&body); + let api_base = env::var("OPENAI_API_BASE") + .ok() + .unwrap_or_else(|| API_BASE.to_string()); + let url = format!("{api_base}/chat/completions"); + + let mut builder = client.post(url).bearer_auth(api_key).json(&body); if let Some(organization_id) = &self.local_config.organization_id { builder = builder.header("OpenAI-Organization", organization_id); |
