mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
fix: address Greptile review feedback
- Filter get_finish_reason_mapping() to Gemini-only keys instead of returning the full cross-provider _FINISH_REASON_MAP - Shallow-copy caller-supplied provider_specific_fields before mutating to avoid unexpected side-effects
This commit is contained in:
parent
d501c33a9d
commit
55f4c8d203
2 changed files with 15 additions and 7 deletions
|
|
@ -1230,18 +1230,26 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig):
|
|||
"IMAGE_PROHIBITED_CONTENT": "The token generation was stopped as the response was flagged for prohibited image content.",
|
||||
}
|
||||
|
||||
_GEMINI_FINISH_REASON_KEYS = frozenset({
|
||||
"STOP", "MAX_TOKENS", "SAFETY", "RECITATION", "FINISH_REASON_UNSPECIFIED",
|
||||
"MALFORMED_FUNCTION_CALL", "LANGUAGE", "OTHER", "BLOCKLIST",
|
||||
"PROHIBITED_CONTENT", "SPII", "IMAGE_SAFETY", "IMAGE_PROHIBITED_CONTENT",
|
||||
"TOO_MANY_TOOL_CALLS", "MALFORMED_RESPONSE",
|
||||
})
|
||||
|
||||
@staticmethod
|
||||
def get_finish_reason_mapping() -> Dict[str, OpenAIChatCompletionFinishReason]:
|
||||
"""
|
||||
Return Dictionary of finish reasons which indicate response was flagged
|
||||
|
||||
and what it means.
|
||||
|
||||
Delegates to the centralized _FINISH_REASON_MAP to avoid duplication.
|
||||
Return Dictionary of Gemini/Vertex AI finish reasons and their
|
||||
OpenAI-compatible mappings.
|
||||
"""
|
||||
from litellm.litellm_core_utils.core_helpers import _FINISH_REASON_MAP
|
||||
|
||||
return dict(_FINISH_REASON_MAP)
|
||||
return {
|
||||
k: v
|
||||
for k, v in _FINISH_REASON_MAP.items()
|
||||
if k in VertexGeminiConfig._GEMINI_FINISH_REASON_KEYS
|
||||
}
|
||||
|
||||
def translate_exception_str(self, exception_string: str):
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -1329,7 +1329,7 @@ class Choices(SafeAttributeModel, OpenAIObject):
|
|||
mapped = map_finish_reason(finish_reason)
|
||||
params["finish_reason"] = mapped
|
||||
if finish_reason != mapped:
|
||||
provider_specific_fields = provider_specific_fields or {}
|
||||
provider_specific_fields = dict(provider_specific_fields) if provider_specific_fields else {}
|
||||
provider_specific_fields["native_finish_reason"] = finish_reason
|
||||
else:
|
||||
params["finish_reason"] = "stop"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue