fix(provider): require exact chat endpoint suffix match (#277)
This commit is contained in:
parent
9428d3ab74
commit
13f6ed7871
1 changed files with 26 additions and 2 deletions
|
|
@ -48,8 +48,19 @@ impl OpenAiCompatibleProvider {
|
||||||
/// This allows custom providers with non-standard endpoints (e.g., VolcEngine ARK uses
|
/// This allows custom providers with non-standard endpoints (e.g., VolcEngine ARK uses
|
||||||
/// `/api/coding/v3/chat/completions` instead of `/v1/chat/completions`).
|
/// `/api/coding/v3/chat/completions` instead of `/v1/chat/completions`).
|
||||||
fn chat_completions_url(&self) -> String {
|
fn chat_completions_url(&self) -> String {
|
||||||
// If base_url already contains "chat/completions", use it as-is
|
let has_full_endpoint = reqwest::Url::parse(&self.base_url)
|
||||||
if self.base_url.contains("chat/completions") {
|
.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()
|
self.base_url.clone()
|
||||||
} else {
|
} else {
|
||||||
format!("{}/chat/completions", self.base_url)
|
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]
|
#[test]
|
||||||
fn responses_url_standard() {
|
fn responses_url_standard() {
|
||||||
// Standard providers get /v1/responses appended
|
// Standard providers get /v1/responses appended
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue