Merge pull request #4939 from BerriAI/litellm_log_transcription_resp_langfuse

[Feat-Proxy] - Langfuse log /audio/transcription on langfuse
This commit is contained in:
Ishaan Jaff 2024-07-29 08:58:40 -07:00 committed by GitHub
commit a2939c2f08
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 56 additions and 1 deletions

View file

@ -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

View file

@ -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:

View file

@ -34,4 +34,4 @@ general_settings:
max_response_size_mb: 10
litellm_settings:
callbacks: ["otel"]
success_callback: ["langfuse"]

View file

@ -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):
"""