From 220cfc40e86f6e82e283cabdf2a0ad8bfb7c2fe7 Mon Sep 17 00:00:00 2001 From: wudimenghuan Date: Wed, 8 Apr 2026 17:43:50 +0800 Subject: [PATCH] fix: omit response_format from API request when it is None When api.llm_support_json is False, response_format was set to None but still included in the request body as "response_format": null. Some OpenAI-compatible API providers try to parse this field and access null.type, causing a 400 error: "Cannot read properties of null (reading 'type')" Now response_format is only included in params when it is not None. --- core/utils/ask_gpt.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/utils/ask_gpt.py b/core/utils/ask_gpt.py index 972bd20c..8fdf637d 100644 --- a/core/utils/ask_gpt.py +++ b/core/utils/ask_gpt.py @@ -64,9 +64,10 @@ def ask_gpt(prompt, resp_type=None, valid_def=None, log_title="default"): params = dict( model=model, messages=messages, - response_format=response_format, timeout=300 ) + if response_format is not None: + params["response_format"] = response_format resp_raw = client.chat.completions.create(**params) # process and return full result