diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py index 0217f7458d9..f0e3faec7ef 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 = ( @@ -198,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/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: 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 diff --git a/litellm/tests/test_alangfuse.py b/litellm/tests/test_alangfuse.py index 8f91ffa67a7..bf475ae9757 100644 --- a/litellm/tests/test_alangfuse.py +++ b/litellm/tests/test_alangfuse.py @@ -245,6 +245,49 @@ 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" + assert generations[0].output is not None + + @pytest.mark.asyncio async def test_langfuse_masked_input_output(langfuse_client): """