Skip to content

Disable model and key checks with custom API base #189

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

Merged
merged 1 commit into from
Jul 5, 2023
Merged
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
27 changes: 13 additions & 14 deletions src/llms/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,16 @@ impl Debug for OpenAIClient {

impl OpenAIClient {
pub(crate) fn new(settings: OpenAISettings) -> Result<Self, anyhow::Error> {
let api_key = settings.api_key.unwrap_or_default();
if api_key.is_empty() {
bail!("No OpenAI API key found. Please provide a valid API key.");
}
let model = settings.model.unwrap_or_default();
if model.is_empty() {
bail!("No OpenAI model configured. Please choose a valid model to use.");
}

let mut openai_config = OpenAIConfig::new().with_api_key(api_key);

let api_base = settings.api_base.unwrap_or_default();
if !api_base.is_empty() {
openai_config = openai_config.with_api_base(&api_base);
}
let openai_config = if api_base.is_empty() {
let api_key = settings.api_key.unwrap_or_default();
if api_key.is_empty() {
bail!("No OpenAI API key found. Please provide a valid API key.");
}
OpenAIConfig::new().with_api_key(api_key)
} else {
OpenAIConfig::new().with_api_base(&api_base)
};
let mut openai_client = Client::<OpenAIConfig>::with_config(openai_config);
// TODO make configurable
let mut http_client = reqwest::Client::builder()
Expand All @@ -70,6 +65,10 @@ impl OpenAIClient {
.http2_keep_alive_while_idle(true)
.min_tls_version(tls::Version::TLS_1_2);
}
let model = settings.model.unwrap_or_default();
if api_base.is_empty() && model.is_empty() {
bail!("No OpenAI model configured. Please choose a valid model to use.");
}

if let Some(proxy) = settings.proxy {
if !proxy.is_empty() {
Expand Down