feat: support OPENAI_API_BASE (#186)

pull/187/head
sigoden 8 months ago committed by GitHub
parent 36380475d5
commit 84004fd576
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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);

Loading…
Cancel
Save