DeepSeek: Add tool calling for -chat model
| @@ -1934,7 +1934,7 @@ | ||
| 1934 | 1934 | </span> |
| 1935 | 1935 | </div> |
| 1936 | 1936 | </div> |
| 1937 | 1937 | <div class="range-block" data-source="openai,cohere,mistralai,custom,claude,openrouter,groq,deepseek"> |
| 1938 | 1938 | <label for="openai_function_calling" class="checkbox_label flexWrap widthFreeExpand"> |
| 1939 | 1939 | <input id="openai_function_calling" type="checkbox" /> |
| 1940 | 1940 | <span data-i18n="Enable function calling">Enable function calling</span> |
| @@ -1917,6 +1917,10 @@ async function sendOpenAIRequest(type, messages, signal) { | ||
| 1917 | 1917 | 'reasoning_effort': String(oai_settings.reasoning_effort), |
| 1918 | 1918 | }; |
| 1919 | 1919 | |
| 1920 | + if (!canMultiSwipe && ToolManager.canPerformToolCalls(type)) { | |
| 1921 | + await ToolManager.registerFunctionToolsOpenAI(generate_data); | |
| 1922 | + } | |
| 1923 | + | |
| 1920 | 1924 | // Empty array will produce a validation error |
| 1921 | 1925 | if (!Array.isArray(generate_data.stop) || !generate_data.stop.length) { |
| 1922 | 1926 | delete generate_data.stop; |
| @@ -2040,6 +2044,8 @@ async function sendOpenAIRequest(type, messages, signal) { | ||
| 2040 | 2044 | delete generate_data.top_logprobs; |
| 2041 | 2045 | delete generate_data.logprobs; |
| 2042 | 2046 | delete generate_data.logit_bias; |
| 2047 | + delete generate_data.tools; | |
| 2048 | + delete generate_data.tool_choice; | |
| 2043 | 2049 | } |
| 2044 | 2050 | } |
| 2045 | 2051 | |
| @@ -2047,10 +2053,6 @@ async function sendOpenAIRequest(type, messages, signal) { | ||
| 2047 | 2053 | generate_data['seed'] = oai_settings.seed; |
| 2048 | 2054 | } |
| 2049 | 2055 | |
| 2050 | - if (!canMultiSwipe && ToolManager.canPerformToolCalls(type)) { | |
| 2051 | - await ToolManager.registerFunctionToolsOpenAI(generate_data); | |
| 2052 | - } | |
| 2053 | - | |
| 2054 | 2056 | if (isOAI && (oai_settings.openai_model.startsWith('o1') || oai_settings.openai_model.startsWith('o3'))) { |
| 2055 | 2057 | generate_data.messages.forEach((msg) => { |
| 2056 | 2058 | if (msg.role === 'system') { |
| @@ -563,6 +563,7 @@ export class ToolManager { | ||
| 563 | 563 | chat_completion_sources.OPENROUTER, |
| 564 | 564 | chat_completion_sources.GROQ, |
| 565 | 565 | chat_completion_sources.COHERE, |
| 566 | + chat_completion_sources.DEEPSEEK, | |
| 566 | 567 | ]; |
| 567 | 568 | return supportedSources.includes(oai_settings.chat_completion_source); |
| 568 | 569 | } |
| @@ -679,6 +679,11 @@ async function sendDeepSeekRequest(request, response) { | ||
| 679 | 679 | bodyParams['logprobs'] = true; |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | + if (Array.isArray(request.body.tools) && request.body.tools.length > 0) { | |
| 683 | + bodyParams['tools'] = request.body.tools; | |
| 684 | + bodyParams['tool_choice'] = request.body.tool_choice; | |
| 685 | + } | |
| 686 | + | |
| 682 | 687 | const postProcessType = String(request.body.model).endsWith('-reasoner') ? 'deepseek-reasoner' : 'deepseek'; |
| 683 | 688 | const processedMessages = postProcessPrompt(request.body.messages, postProcessType, getPromptNames(request)); |
| 684 | 689 | |