fix(provider): require exact chat endpoint suffix match (#277)

This commit is contained in:
Chummy 2026-02-16 14:57:48 +08:00 committed by GitHub
parent 9428d3ab74
commit 13f6ed7871
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -48,8 +48,19 @@ impl OpenAiCompatibleProvider {
/// This allows custom providers with non-standard endpoints (e.g., VolcEngine ARK uses
/// `/api/coding/v3/chat/completions` instead of `/v1/chat/completions`).
fn chat_completions_url(&self) -> String {
// If base_url already contains "chat/completions", use it as-is
if self.base_url.contains("chat/completions") {
let has_full_endpoint = reqwest::Url::parse(&self.base_url)
.map(|url| {
url.path()
.trim_end_matches('/')
.ends_with("/chat/completions")
})
.unwrap_or_else(|_| {
self.base_url
.trim_end_matches('/')
.ends_with("/chat/completions")
});
if has_full_endpoint {
self.base_url.clone()
} else {
format!("{}/chat/completions", self.base_url)
@ -618,6 +629,19 @@ mod tests {
);
}
#[test]
fn chat_completions_url_requires_exact_suffix_match() {
let p = make_provider(
"custom",
"https://my-api.example.com/v2/llm/chat/completions-proxy",
None,
);
assert_eq!(
p.chat_completions_url(),
"https://my-api.example.com/v2/llm/chat/completions-proxy/chat/completions"
);
}
#[test]
fn responses_url_standard() {
// Standard providers get /v1/responses appended