mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-04 02:31:27 +00:00
style(responses): satisfy the LIT010 type-discipline gate
The four locals in _convert_response_format_to_text_param were assigned without Final, which the gate counts as open to rebinding -- LIT010 sits at its ceiling, so four new ones tripped it. None of them is ever rebound, so Final is simply correct here and matches the rest of the file. Building `text_format_param` by mutation was also the only reason it needed to stay non-Final. Replaced with a comprehension merged into the returned literal, which reads better and drops one LIT011 in-place mutation as well. No behaviour change: the tests are untouched and still pass, and 5 of the 8 still fail without the fix commit.
This commit is contained in:
parent
46b94666d1
commit
5365c3fdcc
1 changed files with 9 additions and 8 deletions
|
|
@ -939,24 +939,25 @@ class ResponsesAPIRequestUtils:
|
|||
from litellm.llms.base_llm.base_utils import type_to_response_format_param
|
||||
|
||||
# Normalizes a Pydantic model into a response_format dict; passes a dict through.
|
||||
converted = type_to_response_format_param(response_format)
|
||||
converted: Final = type_to_response_format_param(response_format)
|
||||
if converted is None:
|
||||
return None
|
||||
|
||||
format_type = converted.get("type")
|
||||
format_type: Final = converted.get("type")
|
||||
if format_type is None:
|
||||
return None
|
||||
if format_type != "json_schema":
|
||||
return {"format": {"type": format_type}}
|
||||
|
||||
json_schema = converted.get("json_schema") or {}
|
||||
text_format_param: dict = {"type": format_type}
|
||||
json_schema: Final = converted.get("json_schema") or {}
|
||||
# `name`/`schema` are required by the API and `strict`/`description` are optional,
|
||||
# so copy whatever was supplied and let the provider reject a malformed schema.
|
||||
for key in ("name", "schema", "strict", "description"):
|
||||
if json_schema.get(key) is not None:
|
||||
text_format_param[key] = json_schema[key]
|
||||
return {"format": text_format_param}
|
||||
schema_fields: Final = {
|
||||
key: json_schema[key]
|
||||
for key in ("name", "schema", "strict", "description")
|
||||
if json_schema.get(key) is not None
|
||||
}
|
||||
return {"format": {"type": format_type, **schema_fields}}
|
||||
|
||||
@staticmethod
|
||||
def convert_text_format_to_text_param(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue