accomendate json schema in the "schema" field, not in "json_schema" field of response_format (#9786)
This commit is contained in:
@@ -460,6 +460,38 @@ class ChatCompletionRequest(BaseModel):
|
||||
values["tool_choice"] = "auto"
|
||||
return values
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def set_json_schema(cls, values):
|
||||
response_format = values.get("response_format")
|
||||
if not response_format:
|
||||
return values
|
||||
|
||||
if response_format.get("type") != "json_schema":
|
||||
return values
|
||||
|
||||
schema = response_format.pop("schema", None)
|
||||
json_schema = response_format.get("json_schema")
|
||||
|
||||
if json_schema:
|
||||
return values
|
||||
|
||||
if schema:
|
||||
name_ = schema.get("title", "Schema")
|
||||
strict_ = False
|
||||
if "properties" in schema and "strict" in schema["properties"]:
|
||||
item = schema["properties"].pop("strict", None)
|
||||
if item and item.get("default", False):
|
||||
strict_ = True
|
||||
|
||||
response_format["json_schema"] = {
|
||||
"name": name_,
|
||||
"schema": schema,
|
||||
"strict": strict_,
|
||||
}
|
||||
|
||||
return values
|
||||
|
||||
# Extra parameters for SRT backend only and will be ignored by OpenAI models.
|
||||
top_k: int = -1
|
||||
min_p: float = 0.0
|
||||
|
||||
Reference in New Issue
Block a user