Skip to content

Commit d14c3ea

Browse files
committed
Disable model and key checks with custom API base
1 parent 0cd4d1b commit d14c3ea

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/llms/openai.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,16 @@ impl Debug for OpenAIClient {
3636

3737
impl OpenAIClient {
3838
pub(crate) fn new(settings: OpenAISettings) -> Result<Self, anyhow::Error> {
39-
let api_key = settings.api_key.unwrap_or_default();
40-
if api_key.is_empty() {
41-
bail!("No OpenAI API key found. Please provide a valid API key.");
42-
}
43-
let model = settings.model.unwrap_or_default();
44-
if model.is_empty() {
45-
bail!("No OpenAI model configured. Please choose a valid model to use.");
46-
}
47-
48-
let mut openai_config = OpenAIConfig::new().with_api_key(api_key);
49-
5039
let api_base = settings.api_base.unwrap_or_default();
51-
if !api_base.is_empty() {
52-
openai_config = openai_config.with_api_base(&api_base);
53-
}
40+
let openai_config = if api_base.is_empty() {
41+
let api_key = settings.api_key.unwrap_or_default();
42+
if api_key.is_empty() {
43+
bail!("No OpenAI API key found. Please provide a valid API key.");
44+
}
45+
OpenAIConfig::new().with_api_key(api_key)
46+
} else {
47+
OpenAIConfig::new().with_api_base(&api_base)
48+
};
5449
let mut openai_client = Client::<OpenAIConfig>::with_config(openai_config);
5550
// TODO make configurable
5651
let mut http_client = reqwest::Client::builder()
@@ -70,6 +65,10 @@ impl OpenAIClient {
7065
.http2_keep_alive_while_idle(true)
7166
.min_tls_version(tls::Version::TLS_1_2);
7267
}
68+
let model = settings.model.unwrap_or_default();
69+
if api_base.is_empty() && model.is_empty() {
70+
bail!("No OpenAI model configured. Please choose a valid model to use.");
71+
}
7372

7473
if let Some(proxy) = settings.proxy {
7574
if !proxy.is_empty() {

0 commit comments

Comments
 (0)