From 64fd1f7d21525d3006b1a9da467f2f47ae2a1f25 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Thu, 8 Feb 2024 16:46:04 -0800 Subject: [PATCH] fix(langfuse.py): langfuse success logging fix --- litellm/integrations/langfuse.py | 33 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/litellm/integrations/langfuse.py b/litellm/integrations/langfuse.py index bed3d32591ad..19714b763967 100644 --- a/litellm/integrations/langfuse.py +++ b/litellm/integrations/langfuse.py @@ -275,19 +275,24 @@ def _log_langfuse_v2( "completion_tokens": response_obj["usage"]["completion_tokens"], "total_cost": cost if supports_costs else None, } - trace.generation( - name=generation_name, - id=metadata.get("generation_id", generation_id), - startTime=start_time, - endTime=end_time, - model=kwargs["model"], - modelParameters=optional_params, - input=input, - output=output, - usage=usage, - metadata=metadata, - level=level, - status_message=output, - ) + + generation_params = { + "name": generation_name, + "id": metadata.get("generation_id", generation_id), + "startTime": start_time, + "endTime": end_time, + "model": kwargs["model"], + "modelParameters": optional_params, + "input": input, + "output": output, + "usage": usage, + "metadata": metadata, + "level": level, + } + + if output is not None and isinstance(output, str) and level == "ERROR": + generation_params["statusMessage"] = output + + trace.generation(**generation_params) except Exception as e: print(f"Langfuse Layer Error - {traceback.format_exc()}")