fix: Disable DeepSeek thinking mode to avoid reasoning_content errors

DeepSeek models (deepseek-v4-flash/pro) enable thinking mode by default,
which returns reasoning_content that must be passed back to the API in
subsequent requests. This causes 400 errors in multi-turn conversations
when the reasoning_content is not properly handled.

This commit disables thinking mode by passing extra_body={"thinking": {"type": "disabled"}}
as an explicit parameter to DeepSeek models, preventing the reasoning_content
field from being generated.

Modified:
- create_base_model(): Add extra_body parameter with thinking mode disabled
- create_title_model(): Add extra_body parameter with thinking mode disabled

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
YueGuobin 2026-05-09 22:31:50 +08:00
parent 8b3d136a84
commit 156072118f
No known key found for this signature in database

View File

@ -110,15 +110,26 @@ def create_base_model(
raise ValueError("LLM configuration requires 'provider' field")
try:
model = init_chat_model(
config_vars["model_name"],
model_provider=config_vars["model_provider"],
api_key=config_vars["api_key"],
base_url=config_vars["base_url"],
temperature=config_vars["temperature"],
configurable_fields="any",
config_prefix="foo",
)
# Prepare parameters for init_chat_model
init_params = {
"model": config_vars["model_name"],
"model_provider": config_vars["model_provider"],
"api_key": config_vars["api_key"],
"base_url": config_vars["base_url"],
"temperature": config_vars["temperature"],
"configurable_fields": "any",
"config_prefix": "foo",
}
# Disable DeepSeek thinking mode to avoid reasoning_content handling issues
# DeepSeek models enable thinking mode by default, which returns reasoning_content
# that must be passed back to the API in subsequent requests. To simplify
# message handling and avoid 400 errors, we disable it here.
if config_vars["model_provider"] == "deepseek":
init_params["extra_body"] = {"thinking": {"type": "disabled"}}
logger.info("DeepSeek thinking mode disabled")
model = init_chat_model(**init_params)
logger.info("Base model created successfully")
return model
@ -167,15 +178,26 @@ def create_title_model(
raise ValueError("LLM configuration requires 'provider' field")
try:
model = init_chat_model(
config_vars["model_name"],
model_provider=config_vars["model_provider"],
api_key=config_vars["api_key"],
base_url=config_vars["base_url"],
temperature="1.0", # Higher temperature for more creative titles
configurable_fields="any",
config_prefix="foo",
)
# Prepare parameters for init_chat_model
init_params = {
"model": config_vars["model_name"],
"model_provider": config_vars["model_provider"],
"api_key": config_vars["api_key"],
"base_url": config_vars["base_url"],
"temperature": "1.0", # Higher temperature for more creative titles
"configurable_fields": "any",
"config_prefix": "foo",
}
# Disable DeepSeek thinking mode to avoid reasoning_content handling issues
# DeepSeek models enable thinking mode by default, which returns reasoning_content
# that must be passed back to the API in subsequent requests. To simplify
# message handling and avoid 400 errors, we disable it here.
if config_vars["model_provider"] == "deepseek":
init_params["extra_body"] = {"thinking": {"type": "disabled"}}
logger.info("DeepSeek thinking mode disabled for title model")
model = init_chat_model(**init_params)
logger.info("Title model created successfully")
return model