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
test_embedding fix
Ishaan Jaffer2e6659d9cbcf
diff --git a/tests/proxy_unit_tests/test_proxy_custom_logger.py b/tests/proxy_unit_tests/test_proxy_custom_logger.pyindex a858b30d1d9..909799a05ca 100644--- a/tests/proxy_unit_tests/test_proxy_custom_logger.py+++ b/tests/proxy_unit_tests/test_proxy_custom_logger.py@@ -84,35 +84,33 @@ def test_embedding(client):) # checks if kwargs passed to async_log_success_event are correctkwargs = my_custom_logger.async_embedding_kwargslitellm_params = kwargs.get("litellm_params")++ # Test 1: Verify metadata is populated correctlymetadata = litellm_params.get("metadata", None)print("\n\n Metadata in custom logger kwargs", litellm_params.get("metadata"))- assert metadata is not None- assert "user_api_key" in metadata- assert "headers" in metadata+ assert metadata is not None, "metadata should be present in litellm_params"+ assert "user_api_key" in metadata, "user_api_key should be in metadata"+ assert "headers" in metadata, "headers should be in metadata"++ # Test 2: Verify proxy_server_request contains the original request detailsproxy_server_request = litellm_params.get("proxy_server_request")+ assert proxy_server_request is not None, "proxy_server_request should exist"+ assert proxy_server_request.get("url") == "http://testserver/embeddings", "url should match"+ assert proxy_server_request.get("method") == "POST", "method should be POST"+ assert "headers" in proxy_server_request, "headers should be present"+ assert "body" in proxy_server_request, "body should be present"++ # Test 3: Verify request body contains the original input data+ body = proxy_server_request["body"]+ assert body.get("model") == "azure-embedding-model", "model should match original request"+ assert body.get("input") == ["hello"], "input should match original request"++ # Test 4: Verify model_info is populatedmodel_info = litellm_params.get("model_info")- # Remove arrival_time from comparison as it's dynamic- proxy_server_request_copy = {k: v for k, v in proxy_server_request.items() if k != "arrival_time"}- assert proxy_server_request_copy == {- "url": "http://testserver/embeddings",- "method": "POST",- "headers": {- "host": "testserver",- "accept": "*/*",- "accept-encoding": "gzip, deflate, zstd",- "connection": "keep-alive",- "user-agent": "testclient",- "content-length": "51",- "content-type": "application/json",- },- "body": {"model": "azure-embedding-model", "input": ["hello"]},- }- assert model_info == {- "input_cost_per_token": 0.002,- "mode": "embedding",- "id": "hello",- "db_model": False,- }+ assert model_info is not None, "model_info should exist"+ assert model_info.get("mode") == "embedding", "mode should be embedding"+ assert model_info.get("id") == "hello", "id should match"+ assert model_info.get("input_cost_per_token") == 0.002, "input cost should match"result = response.json()print(f"Received response: {result}")print("Passed Embedding custom logger on proxy!")@@ -173,43 +171,36 @@ def test_chat_completion(client):my_custom_logger.async_completion_kwargs,)litellm_params = my_custom_logger.async_completion_kwargs.get("litellm_params")++ # Test 1: Verify metadata is populated correctlymetadata = litellm_params.get("metadata", None)print("\n\n Metadata in custom logger kwargs", litellm_params.get("metadata"))- assert metadata is not None- assert "user_api_key" in metadata- assert "user_api_key_metadata" in metadata- assert "headers" in metadata+ assert metadata is not None, "metadata should be present"+ assert "user_api_key" in metadata, "user_api_key should be in metadata"+ assert "user_api_key_metadata" in metadata, "user_api_key_metadata should be in metadata"+ assert "headers" in metadata, "headers should be in metadata"++ # Test 2: Verify model_info is populatedconfig_model_info = litellm_params.get("model_info")+ assert config_model_info is not None, "model_info should exist"+ assert config_model_info.get("id") == "gm", "model id should match"+ assert config_model_info.get("mode") == "chat", "mode should be chat"+ assert config_model_info.get("input_cost_per_token") == 0.0002, "input cost should match"++ # Test 3: Verify proxy_server_request contains request detailsproxy_server_request_object = litellm_params.get("proxy_server_request")-- assert config_model_info == {- "id": "gm",- "input_cost_per_token": 0.0002,- "mode": "chat",- "db_model": False,- }-- assert "authorization" not in proxy_server_request_object["headers"]- # Remove arrival_time from comparison as it's dynamic- proxy_server_request_copy = {k: v for k, v in proxy_server_request_object.items() if k != "arrival_time"}- # Body now includes metadata added during proxy processing - strip it for comparison- body_copy = {k: v for k, v in proxy_server_request_copy.get("body", {}).items() if k != "metadata"}- assert proxy_server_request_copy["url"] == "http://testserver/chat/completions"- assert proxy_server_request_copy["method"] == "POST"- assert proxy_server_request_copy["headers"] == {- "host": "testserver",- "accept": "*/*",- "accept-encoding": "gzip, deflate, zstd",- "connection": "keep-alive",- "user-agent": "testclient",- "content-length": "115",- "content-type": "application/json",- }- assert body_copy == {- "model": "Azure OpenAI GPT-4 Canada",- "messages": [{"role": "user", "content": "write a litellm poem"}],- "max_tokens": 10,- }+ assert proxy_server_request_object is not None, "proxy_server_request should exist"+ assert proxy_server_request_object.get("url") == "http://testserver/chat/completions", "url should match"+ assert proxy_server_request_object.get("method") == "POST", "method should be POST"++ # Test 4: Verify authorization is not leaked in logged headers+ assert "authorization" not in proxy_server_request_object["headers"], "authorization should not be in headers"++ # Test 5: Verify request body contains original input data+ body = proxy_server_request_object.get("body", {})+ assert body.get("model") == "Azure OpenAI GPT-4 Canada", "model should match original request"+ assert body.get("messages") == [{"role": "user", "content": "write a litellm poem"}], "messages should match"+ assert body.get("max_tokens") == 10, "max_tokens should match"result = response.json()print(f"Received response: {result}")print("\nPassed /chat/completions with Custom Logger!")