From b2fcf65653edc2a962d09dc893f458e65371fb73 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 29 Jul 2024 08:00:28 -0700 Subject: [PATCH 1/4] log file_size_in_mb in metadata --- litellm/proxy/common_utils/http_parsing_utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/litellm/proxy/common_utils/http_parsing_utils.py b/litellm/proxy/common_utils/http_parsing_utils.py index 8db1e879470..7164385a76e 100644 --- a/litellm/proxy/common_utils/http_parsing_utils.py +++ b/litellm/proxy/common_utils/http_parsing_utils.py @@ -56,6 +56,9 @@ def check_file_size_under_limit( file_contents_size = file.size or 0 file_content_size_in_mb = file_contents_size / (1024 * 1024) + if "metadata" not in request_data: + request_data["metadata"] = {} + request_data["metadata"]["file_size_in_mb"] = file_content_size_in_mb max_file_size_mb = None if llm_router is not None and request_data["model"] in router_model_names: From 95f063f978d7bd30ab793a3a520e720883b054a6 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 29 Jul 2024 08:03:08 -0700 Subject: [PATCH 2/4] fix default input/output values for /audio/trancription logging --- litellm/integrations/langfuse.py | 4 ++++ litellm/proxy/proxy_config.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py index 0217f7458d9..73a8ed0d94f 100644 --- a/litellm/integrations/langfuse.py +++ b/litellm/integrations/langfuse.py @@ -144,6 +144,10 @@ class LangFuseLogger: f"Langfuse Logging - Enters logging function for model {kwargs}" ) + # set default values for input/output for langfuse logging + input = None + output = None + litellm_params = kwargs.get("litellm_params", {}) litellm_call_id = kwargs.get("litellm_call_id", None) metadata = ( diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml index 7a8bd9535df..f7e5a894f01 100644 --- a/litellm/proxy/proxy_config.yaml +++ b/litellm/proxy/proxy_config.yaml @@ -34,4 +34,4 @@ general_settings: max_response_size_mb: 10 litellm_settings: - callbacks: ["otel"] \ No newline at end of file + success_callback: ["langfuse"] \ No newline at end of file From ec28e8e630e4b454a86a95bfe55e2882fd7992bb Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 29 Jul 2024 08:17:19 -0700 Subject: [PATCH 3/4] test - logging litellm-atranscription --- litellm/tests/test_alangfuse.py | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/litellm/tests/test_alangfuse.py b/litellm/tests/test_alangfuse.py index 8f91ffa67a7..097974e2f64 100644 --- a/litellm/tests/test_alangfuse.py +++ b/litellm/tests/test_alangfuse.py @@ -245,6 +245,48 @@ async def test_langfuse_logging_without_request_response(stream, langfuse_client pytest.fail(f"An exception occurred - {e}") +# Get the current directory of the file being run +pwd = os.path.dirname(os.path.realpath(__file__)) +print(pwd) + +file_path = os.path.join(pwd, "gettysburg.wav") + +audio_file = open(file_path, "rb") + + +@pytest.mark.asyncio +async def test_langfuse_logging_audio_transcriptions(langfuse_client): + """ + Test that creates a trace with masked input and output + """ + import uuid + + _unique_trace_name = f"litellm-test-{str(uuid.uuid4())}" + litellm.set_verbose = True + litellm.success_callback = ["langfuse"] + await litellm.atranscription( + model="whisper-1", + file=audio_file, + metadata={ + "trace_id": _unique_trace_name, + }, + ) + + langfuse_client.flush() + await asyncio.sleep(2) + + # get trace with _unique_trace_name + trace = langfuse_client.get_trace(id=_unique_trace_name) + generations = list( + reversed(langfuse_client.get_generations(trace_id=_unique_trace_name).data) + ) + + print("generations for given trace=", generations) + + assert len(generations) == 1 + assert generations[0].name == "litellm-atranscription" + + @pytest.mark.asyncio async def test_langfuse_masked_input_output(langfuse_client): """ From 285925e10a2147ed8d55434c6fd238c25f2a6734 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 29 Jul 2024 08:21:22 -0700 Subject: [PATCH 4/4] log output from /audio on langfuse --- litellm/integrations/langfuse.py | 5 +++++ litellm/tests/test_alangfuse.py | 1 + 2 files changed, 6 insertions(+) diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py index 73a8ed0d94f..f0e3faec7ef 100644 --- a/litellm/integrations/langfuse.py +++ b/litellm/integrations/langfuse.py @@ -202,6 +202,11 @@ class LangFuseLogger: ): input = prompt output = response_obj["data"] + elif response_obj is not None and isinstance( + response_obj, litellm.TranscriptionResponse + ): + input = prompt + output = response_obj["text"] print_verbose(f"OUTPUT IN LANGFUSE: {output}; original: {response_obj}") trace_id = None generation_id = None diff --git a/litellm/tests/test_alangfuse.py b/litellm/tests/test_alangfuse.py index 097974e2f64..bf475ae9757 100644 --- a/litellm/tests/test_alangfuse.py +++ b/litellm/tests/test_alangfuse.py @@ -285,6 +285,7 @@ async def test_langfuse_logging_audio_transcriptions(langfuse_client): assert len(generations) == 1 assert generations[0].name == "litellm-atranscription" + assert generations[0].output is not None @pytest.mark.asyncio