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
basic cohere rerank logging
Ishaan Jaff1852e1cd9a4e
diff --git a/litellm/rerank_api/main.py b/litellm/rerank_api/main.pyindex 41de82ab660..462208cfcd8 100644--- a/litellm/rerank_api/main.py+++ b/litellm/rerank_api/main.py@@ -9,7 +9,7 @@ from litellm.llms.cohere.rerank import CohereRerankfrom litellm.llms.togetherai.rerank import TogetherAIRerankfrom litellm.secret_managers.main import get_secretfrom litellm.types.router import *-from litellm.utils import supports_httpx_timeout+from litellm.utils import client, supports_httpx_timeoutfrom .types import RerankRequest, RerankResponse@@ -20,6 +20,7 @@ together_rerank = TogetherAIRerank()#################################################+@clientasync def arerank(model: str,query: str,@@ -64,6 +65,7 @@ async def arerank(raise e+@clientdef rerank(model: str,query: str,diff --git a/litellm/tests/test_rerank.py b/litellm/tests/test_rerank.pyindex 4e70424bc3c..c3d6faed42e 100644--- a/litellm/tests/test_rerank.py+++ b/litellm/tests/test_rerank.py@@ -20,6 +20,7 @@ import pytestimport litellmfrom litellm import RateLimitError, Timeout, completion, completion_cost, embedding+from litellm.integrations.custom_logger import CustomLoggerfrom litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler@@ -177,3 +178,30 @@ async def test_rerank_custom_api_base():assert response.results is not Noneassert_response_shape(response, custom_llm_provider="cohere")+++class TestLogger(CustomLogger):++ def __init__(self):+ self.kwargs = None+ super().__init__()++ async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):+ print("in success event for rerank, kwargs = ", kwargs)+ self.kwargs = kwargs+++async def test_rerank_custom_callbacks():+ custom_logger = TestLogger()+ litellm.callbacks = [custom_logger]+ response = await litellm.arerank(+ model="cohere/rerank-english-v3.0",+ query="hello",+ documents=["hello", "world"],+ top_n=3,+ )++ assert self.kwargs is not None++ print("async re rank response: ", response)diff --git a/litellm/utils.py b/litellm/utils.pyindex c362a7b5a06..aecf2de4c84 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -745,6 +745,7 @@ def client(original_function):or kwargs.get("amoderation", False) == Trueor kwargs.get("atext_completion", False) == Trueor kwargs.get("atranscription", False) == True+ or kwargs.get("arerank", False) == True):# [OPTIONAL] CHECK MAX RETRIES / REQUESTif litellm.num_retries_per_request is not None: