Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/buzz-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ hex = { workspace = true }
serde = { workspace = true }
sha2 = { workspace = true }
tempfile = "3"
temp-env = "0.3"
67 changes: 66 additions & 1 deletion crates/buzz-agent/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,9 @@ impl Config {
env("OPENAI_COMPAT_MODEL").as_deref(),
)
.ok_or_else(|| "config: OPENAI_COMPAT_MODEL required".to_string())?,
env_or("OPENAI_COMPAT_BASE_URL", "https://api.openai.com/v1"),
env("OPENAI_COMPAT_BASE_URL")
.or_else(|| env("OPENAI_BASE_URL"))
.unwrap_or_else(|| "https://api.openai.com/v1".into()),
parse_openai_api(env("OPENAI_COMPAT_API").as_deref())?,
),
Provider::Databricks | Provider::DatabricksV2 => (
Expand Down Expand Up @@ -2751,4 +2753,67 @@ mod tests {
let err = resolve_provider(Some("openrouter"), None, None, None).unwrap_err();
assert!(err.contains("OPENROUTER_API_KEY"));
}

#[test]
fn base_url_prefers_compat_over_generic() {
temp_env::with_vars(
[
("BUZZ_AGENT_PROVIDER", Some("openai")),
("OPENAI_COMPAT_API_KEY", Some("sk-test")),
("OPENAI_COMPAT_MODEL", Some("gpt-4")),
("OPENAI_COMPAT_BASE_URL", Some("https://custom-openai.local/v1")),
("OPENAI_BASE_URL", Some("https://generic-openai.local/v1")),
],
|| {
let config = Config::from_env().unwrap();
assert_eq!(
config.base_url,
"https://custom-openai.local/v1",
"specific OPENAI_COMPAT_BASE_URL should win over generic OPENAI_BASE_URL"
);
},
);
}

#[test]
fn base_url_falls_back_to_generic_when_compat_unset() {
temp_env::with_vars(
[
("BUZZ_AGENT_PROVIDER", Some("openai")),
("OPENAI_COMPAT_API_KEY", Some("sk-test")),
("OPENAI_COMPAT_MODEL", Some("gpt-4")),
("OPENAI_COMPAT_BASE_URL", None),
("OPENAI_BASE_URL", Some("https://generic-openai.local/v1")),
],
|| {
let config = Config::from_env().unwrap();
assert_eq!(
config.base_url,
"https://generic-openai.local/v1",
"OPENAI_BASE_URL should be used when OPENAI_COMPAT_BASE_URL is unset"
);
},
);
}

#[test]
fn base_url_defaults_when_none_set() {
temp_env::with_vars(
[
("BUZZ_AGENT_PROVIDER", Some("openai")),
("OPENAI_COMPAT_API_KEY", Some("sk-test")),
("OPENAI_COMPAT_MODEL", Some("gpt-4")),
("OPENAI_COMPAT_BASE_URL", None),
("OPENAI_BASE_URL", None),
],
|| {
let config = Config::from_env().unwrap();
assert_eq!(
config.base_url,
"https://api.openai.com/v1",
"should default when neither env var is set"
);
},
);
}
}