forked from phoenix/litellm-mirror
fix - log langfuse prompt
This commit is contained in:
parent
d880fb2619
commit
a26a023ff8
2 changed files with 35 additions and 0 deletions
30
litellm/litellm_core_utils/llm_request_utils.py
Normal file
30
litellm/litellm_core_utils/llm_request_utils.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from typing import Dict, Optional
|
||||
|
||||
from langfuse.model import TextPromptClient
|
||||
|
||||
|
||||
def _ensure_extra_body_is_safe(extra_body: Optional[Dict]) -> Optional[Dict]:
|
||||
"""
|
||||
Ensure that the extra_body sent in the request is safe, otherwise users will see this error
|
||||
|
||||
"Object of type TextPromptClient is not JSON serializable
|
||||
|
||||
|
||||
Relevant Issue: https://github.com/BerriAI/litellm/issues/4140
|
||||
"""
|
||||
if extra_body is None:
|
||||
return None
|
||||
|
||||
if not isinstance(extra_body, dict):
|
||||
return extra_body
|
||||
|
||||
if "metadata" in extra_body and isinstance(extra_body["metadata"], dict):
|
||||
if "prompt" in extra_body["metadata"]:
|
||||
_prompt = extra_body["metadata"].get("prompt")
|
||||
|
||||
# users can send Langfuse TextPromptClient objects, so we need to convert them to dicts
|
||||
# Langfuse TextPromptClients have .__dict__ attribute
|
||||
if _prompt is not None and hasattr(_prompt, "__dict__"):
|
||||
extra_body["metadata"]["prompt"] = _prompt.__dict__
|
||||
|
||||
return extra_body
|
Loading…
Add table
Add a link
Reference in a new issue