The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge branch 'litellm_internal_staging' into fix/nvidia-nim-ranking-image-passages-top-n
mateo-berri1d7c23a4245b
diff --cc litellm/llms/nvidia_nim/rerank/ranking_transformation.pyindex f3b7ef7d8b0,6671ba09a8a..976b5c2211c--- a/litellm/llms/nvidia_nim/rerank/ranking_transformation.py+++ b/litellm/llms/nvidia_nim/rerank/ranking_transformation.py@@@ -6,13 -6,9 +6,13 @@@ Use this by passing "nvidia_nim/rankingReference: https://build.nvidia.com/nvidia/llama-3_2-nv-rerankqa-1b-v2/deploy"""- from typing import Any, Final+ from typing import Final+import httpx++from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObjfrom litellm.llms.nvidia_nim.rerank.transformation import NvidiaNimRerankConfig+from litellm.types.rerank import RerankResponseclass NvidiaNimRankingConfig(NvidiaNimRerankConfig):@@@ -78,47 -58,6 +78,47 @@@return f"{api_base}/v1/ranking"+ def map_cohere_rerank_params(+ self,+ non_default_params: dict | None, # mutable-ok: matches BaseRerankConfig's request contract+ model: str,+ drop_params: bool,+ query: str,- documents: list[str | dict[str, Any]], # mutable-ok: matches BaseRerankConfig's document contract++ documents: list[str | dict[str, object]], # mutable-ok: matches BaseRerankConfig's document contract+ custom_llm_provider: str | None = None,+ top_n: int | None = None,+ rank_fields: list[str] | None = None, # mutable-ok: matches BaseRerankConfig's field contract+ return_documents: bool | None = True,+ max_chunks_per_doc: int | None = None,+ max_tokens_per_doc: int | None = None,+ instruction: str | None = None,+ ) -> dict: # mutable-ok: LiteLLM provider transforms return mutable request dictionaries+ """+ Keep Cohere's top_n as-is instead of mapping it to top_k.++ The native /v1/ranking endpoint rejects top_k, so top_n is applied+ client-side after the response is converted.+ """+ optional_params: Final = super().map_cohere_rerank_params(+ non_default_params=non_default_params,+ model=model,+ drop_params=drop_params,+ query=query,+ documents=documents,+ custom_llm_provider=custom_llm_provider,+ top_n=None, # do not map top_n -> top_k for /v1/ranking+ rank_fields=rank_fields,+ return_documents=return_documents,+ max_chunks_per_doc=max_chunks_per_doc,+ max_tokens_per_doc=max_tokens_per_doc,+ instruction=instruction,+ )+ # /v1/ranking rejects top_k even when passed as a provider-specific param+ optional_params.pop("top_k", None)+ if top_n is not None:+ optional_params["top_n"] = top_n+ return optional_params+def transform_rerank_request(self,model: str,