fix: fix a small bug in response_schema (#1043)

* fix: fix a small bug in response_schema

* black fix
This commit is contained in:
amstrongzyf
2025-07-09 18:40:48 +08:00
committed by GitHub
parent e5260cb4ac
commit 0424cd1baf
2 changed files with 6 additions and 3 deletions
+4 -3
View File
@@ -575,12 +575,13 @@ class APIBackend(ABC):
_, all_response = match.groups() if match else ("", all_response)
# 3) format checking
if json_mode:
if json_mode or json_target_type:
parser = JSONParser()
all_response = parser.parse(all_response)
if json_target_type:
# deepseek will enter this branch
TypeAdapter(json_target_type).validate_json(all_response)
if json_target_type is not None:
TypeAdapter(json_target_type).validate_json(all_response)
if (response_format := kwargs.get("response_format")) is not None:
if not isinstance(response_format, dict) and issubclass(response_format, BaseModel):
# It may raise TypeError if initialization fails
+2
View File
@@ -95,7 +95,9 @@ class LiteLLMAPIBackend(APIBackend):
"""
if json_mode and supports_response_schema(model=LITELLM_SETTINGS.chat_model):
kwargs["response_format"] = {"type": "json_object"}
elif not supports_response_schema(model=LITELLM_SETTINGS.chat_model) and "response_format" in kwargs:
# Deepseek will enter this branch
logger.warning(
f"{LogColors.RED}Model {LITELLM_SETTINGS.chat_model} does not support response schema, ignoring response_format argument.{LogColors.END}",
tag="llm_messages",