Skip to content

Commit cf8b570

Browse files
committed
feat: get api base from env
1 parent 4a8d7cf commit cf8b570

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
error::ServerError,
1212
server::RustDocsServer, // Import the updated RustDocsServer
1313
};
14-
use async_openai::Client as OpenAIClient;
14+
use async_openai::{Client as OpenAIClient, config::OpenAIConfig};
1515
use bincode::config;
1616
use cargo::core::PackageIdSpec;
1717
use clap::Parser; // Import clap Parser
@@ -182,7 +182,12 @@ async fn main() -> Result<(), ServerError> {
182182
let mut documents_for_server: Vec<Document> = loaded_documents_from_cache.unwrap_or_default();
183183

184184
// --- Initialize OpenAI Client (needed for question embedding even if cache hit) ---
185-
let openai_client = OpenAIClient::new();
185+
let openai_client = if let Ok(api_base) = env::var("OPENAI_API_BASE") {
186+
let config = OpenAIConfig::new().with_api_base(api_base);
187+
OpenAIClient::with_config(config)
188+
} else {
189+
OpenAIClient::new()
190+
};
186191
OPENAI_CLIENT
187192
.set(openai_client.clone()) // Clone the client for the OnceCell
188193
.expect("Failed to set OpenAI client");

0 commit comments

Comments
 (0)