This commit is contained in:
Ritika shrestha 2026-09-22 16:42:13 +07:00 • committed by GitHub
commit 914b93d8a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 5 deletions

View file

@ -19,11 +19,12 @@ class CohereRerankV2Config(CohereRerankConfig):
optional_params: dict | None = None,
) -> str:
if api_base:
# Remove trailing slashes and ensure clean base URL
api_base = api_base.rstrip("/")
if not api_base.endswith("/v2/rerank"):
api_base = f"{api_base}/v2/rerank"
return api_base
base = api_base.rstrip("/")
if base.endswith("/v2/rerank"):
return base
if base.endswith("/v2"):
return f"{base}/rerank"
return f"{base}/v2/rerank"
return "https://api.cohere.ai/v2/rerank"
def get_supported_cohere_rerank_params(self, model: str) -> list:

View file

@ -0,0 +1,24 @@
import pytest
from litellm.llms.cohere.rerank_v2.transformation import CohereRerankV2Config
@pytest.mark.parametrize(
"api_base, expected",
[
# versioned root must not duplicate the version segment (#31167)
("https://api.cohere.ai/v2", "https://api.cohere.ai/v2/rerank"),
("https://api.cohere.ai/v2/", "https://api.cohere.ai/v2/rerank"),
# bare host gets the full v2 rerank path
("https://api.cohere.ai", "https://api.cohere.ai/v2/rerank"),
# already-complete url is left untouched
("https://api.cohere.ai/v2/rerank", "https://api.cohere.ai/v2/rerank"),
# self-hosted gateway exposing a versioned root
("https://gateway.internal/cohere/v2", "https://gateway.internal/cohere/v2/rerank"),
# no api_base falls back to the public endpoint
(None, "https://api.cohere.ai/v2/rerank"),
],
)
def test_get_complete_url_does_not_duplicate_version(api_base, expected):
config = CohereRerankV2Config()
assert config.get_complete_url(api_base=api_base, model="rerank-v3.5") == expected