forked from phoenix/litellm-mirror
feat(vertex_httpx.py): support logging vertex ai safety results to langfuse
Closes https://github.com/BerriAI/litellm/issues/3230
This commit is contained in:
parent
a7f964b869
commit
fe7f78fbf6
2 changed files with 27 additions and 0 deletions
|
@ -529,6 +529,7 @@ class Logging:
|
||||||
or isinstance(result, TextCompletionResponse)
|
or isinstance(result, TextCompletionResponse)
|
||||||
or isinstance(result, HttpxBinaryResponseContent) # tts
|
or isinstance(result, HttpxBinaryResponseContent) # tts
|
||||||
):
|
):
|
||||||
|
## RESPONSE COST ##
|
||||||
custom_pricing = use_custom_pricing_for_model(
|
custom_pricing = use_custom_pricing_for_model(
|
||||||
litellm_params=self.litellm_params
|
litellm_params=self.litellm_params
|
||||||
)
|
)
|
||||||
|
@ -548,6 +549,25 @@ class Logging:
|
||||||
custom_pricing=custom_pricing,
|
custom_pricing=custom_pricing,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
## HIDDEN PARAMS ##
|
||||||
|
if hasattr(result, "_hidden_params"):
|
||||||
|
# add to metadata for logging
|
||||||
|
if self.model_call_details.get("litellm_params") is not None:
|
||||||
|
self.model_call_details["litellm_params"].setdefault(
|
||||||
|
"metadata", {}
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
self.model_call_details["litellm_params"]["metadata"]
|
||||||
|
is None
|
||||||
|
):
|
||||||
|
self.model_call_details["litellm_params"][
|
||||||
|
"metadata"
|
||||||
|
] = {}
|
||||||
|
|
||||||
|
self.model_call_details["litellm_params"]["metadata"][
|
||||||
|
"hidden_params"
|
||||||
|
] = result._hidden_params
|
||||||
else: # streaming chunks + image gen.
|
else: # streaming chunks + image gen.
|
||||||
self.model_call_details["response_cost"] = None
|
self.model_call_details["response_cost"] = None
|
||||||
|
|
||||||
|
|
|
@ -688,6 +688,7 @@ class VertexLLM(BaseLLM):
|
||||||
try:
|
try:
|
||||||
## CHECK IF GROUNDING METADATA IN REQUEST
|
## CHECK IF GROUNDING METADATA IN REQUEST
|
||||||
grounding_metadata: List[dict] = []
|
grounding_metadata: List[dict] = []
|
||||||
|
safety_ratings: List = []
|
||||||
## GET TEXT ##
|
## GET TEXT ##
|
||||||
chat_completion_message = {"role": "assistant"}
|
chat_completion_message = {"role": "assistant"}
|
||||||
content_str = ""
|
content_str = ""
|
||||||
|
@ -699,6 +700,8 @@ class VertexLLM(BaseLLM):
|
||||||
if "groundingMetadata" in candidate:
|
if "groundingMetadata" in candidate:
|
||||||
grounding_metadata.append(candidate["groundingMetadata"])
|
grounding_metadata.append(candidate["groundingMetadata"])
|
||||||
|
|
||||||
|
if "safetyRatings" in candidate:
|
||||||
|
safety_ratings.append(candidate["safetyRatings"])
|
||||||
if "text" in candidate["content"]["parts"][0]:
|
if "text" in candidate["content"]["parts"][0]:
|
||||||
content_str = candidate["content"]["parts"][0]["text"]
|
content_str = candidate["content"]["parts"][0]["text"]
|
||||||
|
|
||||||
|
@ -749,6 +752,10 @@ class VertexLLM(BaseLLM):
|
||||||
model_response._hidden_params["vertex_ai_grounding_metadata"] = (
|
model_response._hidden_params["vertex_ai_grounding_metadata"] = (
|
||||||
grounding_metadata
|
grounding_metadata
|
||||||
)
|
)
|
||||||
|
|
||||||
|
## ADD SAFETY RATINGS ##
|
||||||
|
model_response._hidden_params["vertex_ai_safety_results"] = safety_ratings
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise VertexAIError(
|
raise VertexAIError(
|
||||||
message="Received={}, Error converting to valid response block={}. File an issue if litellm error - https://github.com/BerriAI/litellm/issues".format(
|
message="Received={}, Error converting to valid response block={}. File an issue if litellm error - https://github.com/BerriAI/litellm/issues".format(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue