| 798 | 798 | if (Array.isArray(request.body.tools) && request.body.tools.length > 0) { |
| 799 | 799 | bodyParams['tools'] = request.body.tools; |
| 800 | 800 | bodyParams['tool_choice'] = request.body.tool_choice; |
| 801 | + |
| 802 | + // DeepSeek doesn't permit empty required arrays |
| 803 | + bodyParams.tools.forEach(tool => { |
| 804 | + const required = tool?.function?.parameters?.required; |
| 805 | + if (Array.isArray(required) && required.length === 0) { |
| 806 | + delete tool.function.parameters.required; |
| 807 | + } |
| 808 | + }); |
| 801 | 809 | } |
| 802 | 810 | |
| 803 | 811 | const postProcessType = String(request.body.model).endsWith('-reasoner') ? 'deepseek-reasoner' : 'deepseek'; |