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: update key names
Krrish Dholakia9e070143fbe9
diff --git a/tests/batches_tests/test_openai_batches_and_files.py b/tests/batches_tests/test_openai_batches_and_files.pyindex 2ece740bf5a..e4e1180eb13 100644--- a/tests/batches_tests/test_openai_batches_and_files.py+++ b/tests/batches_tests/test_openai_batches_and_files.py@@ -75,8 +75,8 @@ def load_vertex_ai_credentials():service_account_key_data = {}# Update the service_account_key_data with environment variables- private_key_id = os.environ.get("GCS_PRIVATE_KEY_ID", "")- private_key = os.environ.get("GCS_PRIVATE_KEY", "")+ private_key_id = os.environ.get("VERTEX_AI_PRIVATE_KEY_ID", "")+ private_key = os.environ.get("VERTEX_AI_PRIVATE_KEY", "")private_key = private_key.replace("\\n", "\n")service_account_key_data["private_key_id"] = private_key_idservice_account_key_data["private_key"] = private_keydiff --git a/tests/local_testing/test_alangfuse.py b/tests/local_testing/test_alangfuse.pyindex 306c7749f18..7c2ec7e9f64 100644--- a/tests/local_testing/test_alangfuse.py+++ b/tests/local_testing/test_alangfuse.py@@ -599,233 +599,6 @@ def test_langfuse_logging_function_calling():# test_langfuse_logging_function_calling()[email protected](reason="Need to address this on main")-def test_aaalangfuse_existing_trace_id():- """- When existing trace id is passed, don't set trace params -> prevents overwriting the trace-- Pass 1 logging object with a trace-- Pass 2nd logging object with the trace id-- Assert no changes to the trace- """- # Test - if the logs were sent to the correct team on langfuse- import datetime-- import litellm- from litellm.integrations.langfuse.langfuse import LangFuseLogger-- langfuse_Logger = LangFuseLogger(- langfuse_public_key=os.getenv("LANGFUSE_PROJECT2_PUBLIC"),- langfuse_secret=os.getenv("LANGFUSE_PROJECT2_SECRET"),- )- litellm.success_callback = ["langfuse"]-- # langfuse_args = {'kwargs': { 'start_time': 'end_time': datetime.datetime(2024, 5, 1, 7, 31, 29, 903685), 'user_id': None, 'print_verbose': <function print_verbose at 0x109d1f420>, 'level': 'DEFAULT', 'status_message': None}- response_obj = litellm.ModelResponse(- id="chatcmpl-9K5HUAbVRqFrMZKXL0WoC295xhguY",- choices=[- litellm.Choices(- finish_reason="stop",- index=0,- message=litellm.Message(- content="I'm sorry, I am an AI assistant and do not have real-time information. I recommend checking a reliable weather website or app for the most up-to-date weather information in Boston.",- role="assistant",- ),- )- ],- created=1714573888,- model="gpt-3.5-turbo-0125",- object="chat.completion",- system_fingerprint="fp_3b956da36b",- usage=litellm.Usage(completion_tokens=37, prompt_tokens=14, total_tokens=51),- )-- ### NEW TRACE ###- message = [{"role": "user", "content": "what's the weather in boston"}]- langfuse_args = {- "response_obj": response_obj,- "kwargs": {- "model": "gpt-3.5-turbo",- "litellm_params": {- "acompletion": False,- "api_key": None,- "force_timeout": 600,- "logger_fn": None,- "verbose": False,- "custom_llm_provider": "openai",- "api_base": "https://api.openai.com/v1/",- "litellm_call_id": None,- "model_alias_map": {},- "completion_call_id": None,- "metadata": None,- "model_info": None,- "proxy_server_request": None,- "preset_cache_key": None,- "no-log": False,- "stream_response": {},- },- "messages": message,- "optional_params": {"temperature": 0.1, "extra_body": {}},- "start_time": "2024-05-01 07:31:27.986164",- "stream": False,- "user": None,- "call_type": "completion",- "litellm_call_id": None,- "completion_start_time": "2024-05-01 07:31:29.903685",- "temperature": 0.1,- "extra_body": {},- "input": [{"role": "user", "content": "what's the weather in boston"}],- "api_key": "my-api-key",- "additional_args": {- "complete_input_dict": {- "model": "gpt-3.5-turbo",- "messages": [- {"role": "user", "content": "what's the weather in boston"}- ],- "temperature": 0.1,- "extra_body": {},- }- },- "log_event_type": "successful_api_call",- "end_time": "2024-05-01 07:31:29.903685",- "cache_hit": None,- "response_cost": 6.25e-05,- },- "start_time": datetime.datetime(2024, 5, 1, 7, 31, 27, 986164),- "end_time": datetime.datetime(2024, 5, 1, 7, 31, 29, 903685),- "user_id": None,- "print_verbose": litellm.print_verbose,- "level": "DEFAULT",- "status_message": None,- }-- langfuse_response_object = langfuse_Logger.log_event(**langfuse_args)-- import langfuse-- langfuse_client = langfuse.Langfuse(- public_key=os.getenv("LANGFUSE_PROJECT2_PUBLIC"),- secret_key=os.getenv("LANGFUSE_PROJECT2_SECRET"),- )-- trace_id = langfuse_response_object["trace_id"]-- assert trace_id is not None-- langfuse_client.flush()-- time.sleep(2)-- print(langfuse_client.get_trace(id=trace_id))-- initial_langfuse_trace = langfuse_client.get_trace(id=trace_id)-- ### EXISTING TRACE ###-- new_metadata = {"existing_trace_id": trace_id}- new_messages = [{"role": "user", "content": "What do you know?"}]- new_response_obj = litellm.ModelResponse(- id="chatcmpl-9K5HUAbVRqFrMZKXL0WoC295xhguY",- choices=[- litellm.Choices(- finish_reason="stop",- index=0,- message=litellm.Message(- content="What do I know?",- role="assistant",- ),- )- ],- created=1714573888,- model="gpt-3.5-turbo-0125",- object="chat.completion",- system_fingerprint="fp_3b956da36b",- usage=litellm.Usage(completion_tokens=37, prompt_tokens=14, total_tokens=51),- )- langfuse_args = {- "response_obj": new_response_obj,- "kwargs": {- "model": "gpt-3.5-turbo",- "litellm_params": {- "acompletion": False,- "api_key": None,- "force_timeout": 600,- "logger_fn": None,- "verbose": False,- "custom_llm_provider": "openai",- "api_base": "https://api.openai.com/v1/",- "litellm_call_id": "508113a1-c6f1-48ce-a3e1-01c6cce9330e",- "model_alias_map": {},- "completion_call_id": None,- "metadata": new_metadata,- "model_info": None,- "proxy_server_request": None,- "preset_cache_key": None,- "no-log": False,- "stream_response": {},- },- "messages": new_messages,- "optional_params": {"temperature": 0.1, "extra_body": {}},- "start_time": "2024-05-01 07:31:27.986164",- "stream": False,- "user": None,- "call_type": "completion",- "litellm_call_id": "508113a1-c6f1-48ce-a3e1-01c6cce9330e",- "completion_start_time": "2024-05-01 07:31:29.903685",- "temperature": 0.1,- "extra_body": {},- "input": [{"role": "user", "content": "what's the weather in boston"}],- "api_key": "my-api-key",- "additional_args": {- "complete_input_dict": {- "model": "gpt-3.5-turbo",- "messages": [- {"role": "user", "content": "what's the weather in boston"}- ],- "temperature": 0.1,- "extra_body": {},- }- },- "log_event_type": "successful_api_call",- "end_time": "2024-05-01 07:31:29.903685",- "cache_hit": None,- "response_cost": 6.25e-05,- },- "start_time": datetime.datetime(2024, 5, 1, 7, 31, 27, 986164),- "end_time": datetime.datetime(2024, 5, 1, 7, 31, 29, 903685),- "user_id": None,- "print_verbose": litellm.print_verbose,- "level": "DEFAULT",- "status_message": None,- }-- langfuse_response_object = langfuse_Logger.log_event(**langfuse_args)-- new_trace_id = langfuse_response_object["trace_id"]-- assert new_trace_id == trace_id-- langfuse_client.flush()-- time.sleep(2)-- print(langfuse_client.get_trace(id=trace_id))-- new_langfuse_trace = langfuse_client.get_trace(id=trace_id)-- initial_langfuse_trace_dict = dict(initial_langfuse_trace)- initial_langfuse_trace_dict.pop("updatedAt")- initial_langfuse_trace_dict.pop("timestamp")-- new_langfuse_trace_dict = dict(new_langfuse_trace)- new_langfuse_trace_dict.pop("updatedAt")- new_langfuse_trace_dict.pop("timestamp")-- assert initial_langfuse_trace_dict == new_langfuse_trace_dict--@pytest.mark.skipif(condition=not os.environ.get("OPENAI_API_KEY", False),reason="Authentication missing for openai",@@ -928,42 +701,6 @@ async def test_make_request():)- reason="local only test, use this to verify if dynamic langfuse logging works as expected"-)-def test_aaalangfuse_dynamic_logging():- """- pass in langfuse credentials via completion call-- assert call is logged.-- Covers the team-logging scenario.- """- from litellm._uuid import uuid-- import langfuse-- trace_id = str(uuid.uuid4())- _ = litellm.completion(- model="gpt-3.5-turbo",- messages=[{"role": "user", "content": "Hey"}],- mock_response="Hey! how's it going?",- langfuse_public_key=os.getenv("LANGFUSE_PROJECT2_PUBLIC"),- langfuse_secret_key=os.getenv("LANGFUSE_PROJECT2_SECRET"),- metadata={"trace_id": trace_id},- success_callback=["langfuse"],- )-- time.sleep(3)-- langfuse_client = langfuse.Langfuse(- public_key=os.getenv("LANGFUSE_PROJECT2_PUBLIC"),- secret_key=os.getenv("LANGFUSE_PROJECT2_SECRET"),- )-- langfuse_client.get_trace(id=trace_id)--import datetimegeneration_params = {diff --git a/tests/local_testing/test_embedding.py b/tests/local_testing/test_embedding.pyindex 2c265d444a2..e6776e3329b 100644--- a/tests/local_testing/test_embedding.py+++ b/tests/local_testing/test_embedding.py@@ -549,7 +549,7 @@ def test_bedrock_embedding_cohere():"good morning from litellm, attempting to embed data","lets test a second string for good measure",],- aws_region_name="os.environ/AWS_REGION_NAME_2",+ aws_region_name="os.environ/AWS_REGION_NAME",)assert isinstance(response["data"][0]["embedding"], listdiff --git a/tests/local_testing/test_gcs_bucket.py b/tests/local_testing/test_gcs_bucket.pyindex e2f51eb76c7..018a79b53f0 100644--- a/tests/local_testing/test_gcs_bucket.py+++ b/tests/local_testing/test_gcs_bucket.py@@ -22,6 +22,7 @@ from litellm.integrations.gcs_bucket.gcs_bucket import ()from litellm.types.utils import StandardCallbackDynamicParamsfrom unittest.mock import patch+verbose_logger.setLevel(logging.DEBUG)@@ -52,8 +53,8 @@ def load_vertex_ai_credentials():service_account_key_data = {}# Update the service_account_key_data with environment variables- private_key_id = os.environ.get("GCS_PRIVATE_KEY_ID", "")- private_key = os.environ.get("GCS_PRIVATE_KEY", "")+ private_key_id = os.environ.get("VERTEX_AI_PRIVATE_KEY_ID", "")+ private_key = os.environ.get("VERTEX_AI_PRIVATE_KEY", "")private_key = private_key.replace("\\n", "\n")service_account_key_data["private_key_id"] = private_key_idservice_account_key_data["private_key"] = private_key@@ -686,6 +687,7 @@ async def test_basic_gcs_logger_with_folder_in_bucket_name():if old_bucket_name is not None:os.environ["GCS_BUCKET_NAME"] = old_bucket_name+@pytest.mark.skip(reason="This test is flaky on ci/cd")def test_create_file_e2e():"""@@ -696,6 +698,7 @@ def test_create_file_e2e():test_file = ("test.wav", test_file_content, "audio/wav")from litellm import create_file+response = create_file(file=test_file,purpose="user_data",@@ -704,6 +707,7 @@ def test_create_file_e2e():print("response", response)assert response is not None+@pytest.mark.skip(reason="This test is flaky on ci/cd")def test_create_file_e2e_jsonl():"""@@ -714,14 +718,41 @@ def test_create_file_e2e_jsonl():client = HTTPHandler()- example_jsonl = [{"custom_id": "request-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gemini-1.5-flash-001", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello world!"}],"max_tokens": 10}},{"custom_id": "request-2", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gemini-1.5-flash-001", "messages": [{"role": "system", "content": "You are an unhelpful assistant."},{"role": "user", "content": "Hello world!"}],"max_tokens": 10}}]-+ example_jsonl = [+ {+ "custom_id": "request-1",+ "method": "POST",+ "url": "/v1/chat/completions",+ "body": {+ "model": "gemini-1.5-flash-001",+ "messages": [+ {"role": "system", "content": "You are a helpful assistant."},+ {"role": "user", "content": "Hello world!"},+ ],+ "max_tokens": 10,+ },+ },+ {+ "custom_id": "request-2",+ "method": "POST",+ "url": "/v1/chat/completions",+ "body": {+ "model": "gemini-1.5-flash-001",+ "messages": [+ {"role": "system", "content": "You are an unhelpful assistant."},+ {"role": "user", "content": "Hello world!"},+ ],+ "max_tokens": 10,+ },+ },+ ]+# Create and write to the filefile_path = "example.jsonl"with open(file_path, "w") as f:for item in example_jsonl:f.write(json.dumps(item) + "\n")-+# Verify file contentwith open(file_path, "r") as f:content = f.read()@@ -729,10 +760,11 @@ def test_create_file_e2e_jsonl():assert len(content) > 0, "File is empty"from litellm import create_file+with patch.object(client, "post") as mock_create_file:- try:+ try:response = create_file(- file=open(file_path, "rb"),+ file=open(file_path, "rb"),purpose="user_data",custom_llm_provider="vertex_ai",client=client,@@ -744,4 +776,7 @@ def test_create_file_e2e_jsonl():print(f"kwargs: {mock_create_file.call_args.kwargs}")- assert mock_create_file.call_args.kwargs["data"] is not None and len(mock_create_file.call_args.kwargs["data"]) > 0\ No newline at end of file+ assert (+ mock_create_file.call_args.kwargs["data"] is not None+ and len(mock_create_file.call_args.kwargs["data"]) > 0+ )