Skip to content

Commit

Permalink
fix(langfuse.py): langfuse success logging fix
Browse files Browse the repository at this point in the history
  • Loading branch information
krrishdholakia committed Feb 9, 2024
1 parent bc23a92 commit 64fd1f7
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions litellm/integrations/langfuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}")

0 comments on commit 64fd1f7

Please sign in to comment.