summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/openai.rs9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/client/openai.rs b/src/client/openai.rs
index 2a480f3..cf6cc89 100644
--- a/src/client/openai.rs
+++ b/src/client/openai.rs
@@ -9,7 +9,6 @@ use reqwest::{Client as ReqwestClient, RequestBuilder};
use reqwest_eventsource::{Error as EventSourceError, Event, RequestBuilderExt};
use serde::Deserialize;
use serde_json::{json, Value};
-use std::env;
const API_BASE: &str = "https://api.openai.com/v1";
@@ -29,6 +28,7 @@ pub const OPENAI_TOKENS_COUNT_FACTORS: TokensCountFactors = (5, 2);
pub struct OpenAIConfig {
pub name: Option<String>,
pub api_key: Option<String>,
+ pub api_base: Option<String>,
pub organization_id: Option<String>,
pub extra: Option<ExtraConfig>,
}
@@ -37,6 +37,7 @@ openai_compatible_client!(OpenAIClient);
impl OpenAIClient {
config_get_fn!(api_key, get_api_key);
+ config_get_fn!(api_base, get_api_base);
pub const PROMPTS: [PromptType<'static>; 1] =
[("api_key", "API Key:", true, PromptKind::String)];
@@ -56,14 +57,10 @@ impl OpenAIClient {
fn request_builder(&self, client: &ReqwestClient, data: SendData) -> Result<RequestBuilder> {
let api_key = self.get_api_key()?;
+ let api_base = self.get_api_base().unwrap_or_else(|_| API_BASE.to_string());
let body = openai_build_body(data, self.model.name.clone());
- let env_prefix = Self::name(&self.config).to_uppercase();
- let api_base = env::var(format!("{env_prefix}_API_BASE"))
- .ok()
- .unwrap_or_else(|| API_BASE.to_string());
-
let url = format!("{api_base}/chat/completions");
debug!("OpenAI Request: {url} {body}");