Spring AI大模型工具调用错误解决
摘要:Spring AI调用大模型时出现HTTP 400错误,提示需要启用--enable-auto-tool-choice和--tool-call-parser参数。该错误源于服务端未配置自动工具选择功能,而客户端尝试使用tool_choice: "auto"参数。解决方案包括:调整客户端配置避免自动工具选择、服务端添加必要启动参数(仅适用于自托管模型),或改用支持功能调用的
·
Spring AI大模型工具调用时出现错误
Retry error. Retry count: 1, Exception: HTTP 400 - {"error":{"message":"\"auto\" tool choice requires --enable-auto-tool-choice and --tool-call-parser to be set","type":"bad_response_status_code","param":"","code":"bad_response_status_code"}}org.springframework.ai.retry.NonTransientAiException: HTTP 400 - {"error":{"message":"\"auto\" tool choice requires --enable-auto-tool-choice and --tool-call-parser to be set","type":"bad_response_status_code","param":"","code":"bad_response_status_code"}} at org.springframework.ai.retry.autoconfigure.SpringAiRetryAutoConfiguration$2.handleError(SpringAiRetryAutoConfiguration.java:109) ~[spring-ai-autoconfigure-retry-1.0.3.jar:1.0.3] at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:58) ~[spring-web-6.2.12.jar:6.2.12] at org.springframework.web.client.StatusHandler.lambda$fromErrorHandler$1(StatusHandler.java:71) ~[spring-web-6.2.12.jar:6.2.12] at org.springframework.web.client.StatusHandler.handle(StatusHandler.java:146) ~[spring-web-6.2.12.jar:6.2.12] at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.applyStatusHandlers
错误原因分析
HTTP 400错误表明请求格式不符合服务器要求,具体报错信息指出"auto" tool choice功能需要服务端启用--enable-auto-tool-choice和--tool-call-parser参数才能正常工作。该错误表明服务端在部署大模型时,
服务端未配置自动工具选择功能时,客户端却尝试通过tool_choice: "auto"参数调用工具增强的AI模型(OpenAI的Function Calling功能)。
解决方案
部分博客建议客户端配置调整
检查Spring AI或相关SDK的调用代码,确保未强制设置tool_choice: "auto"。若需使用工具调用功能,可改为显式指定工具名称或设置为none。该方案未解决,设置为none,指定工具后,大模型也不会调用工具。
部分博客建议服务端配置
若服务端为自托管模型(如通过vLLM或TGI部署),启动时需添加以下参数:
--enable-auto-tool-choice --tool-call-parser
该方案需要是自己部署的私有大模型,否则无法修改启动配置。
替代方案
直接使用阿里云百炼平台提供的大模型,例如:qwen3-max
这里的function calling就表示该模型支持工具调用
更多推荐
所有评论(0)