DeepSeek: Add tool calls for reasoner model Fixes #4161
| @@ -2385,8 +2385,6 @@ async function sendOpenAIRequest(type, messages, signal) { | ||
| 2385 | 2385 | delete generate_data.top_logprobs; |
| 2386 | 2386 | delete generate_data.logprobs; |
| 2387 | 2387 | delete generate_data.logit_bias; |
| 2388 | - delete generate_data.tools; | |
| 2389 | - delete generate_data.tool_choice; | |
| 2390 | 2388 | } |
| 2391 | 2389 | } |
| 2392 | 2390 | |
| @@ -34,6 +34,7 @@ import { | ||
| 34 | 34 | calculateGoogleBudgetTokens, |
| 35 | 35 | postProcessPrompt, |
| 36 | 36 | PROMPT_PROCESSING_TYPE, |
| 37 | + addAssistantPrefix, | |
| 37 | 38 | } from '../../prompt-converters.js'; |
| 38 | 39 | |
| 39 | 40 | import { readSecret, SECRET_KEYS } from '../secrets.js'; |
| @@ -869,9 +870,9 @@ async function sendDeepSeekRequest(request, response) { | ||
| 869 | 870 | } |
| 870 | 871 | |
| 871 | 872 | const postProcessType = String(request.body.model).endsWith('-reasoner') |
| 872 | 873 | ? PROMPT_PROCESSING_TYPE.DEEPSEEK_REASONERSTRICT_TOOLS |
| 873 | 874 | : PROMPT_PROCESSING_TYPE.DEEPSEEKSEMI_TOOLS; |
| 874 | 875 | const processedMessages = addAssistantPrefix(postProcessPrompt(request.body.messages, postProcessType, getPromptNames(request)), bodyParams.tools); |
| 875 | 876 | |
| 876 | 877 | const requestBody = { |
| 877 | 878 | 'messages': processedMessages, |
| @@ -23,8 +23,6 @@ export const PROMPT_PROCESSING_TYPE = { | ||
| 23 | 23 | STRICT: 'strict', |
| 24 | 24 | STRICT_TOOLS: 'strict_tools', |
| 25 | 25 | SINGLE: 'single', |
| 26 | - DEEPSEEK: 'deepseek', | |
| 27 | - DEEPSEEK_REASONER: 'deepseek-reasoner', | |
| 28 | 26 | }; |
| 29 | 27 | |
| 30 | 28 | /** |
| @@ -54,14 +52,15 @@ export function getPromptNames(request) { | ||
| 54 | 52 | /** |
| 55 | 53 | * Adds an assistant prefix to the last message. |
| 56 | 54 | * @param {any[]} prompt Prompt messages array |
| 55 | + * @param {any[]} tools Array of tool definitions | |
| 57 | 56 | * @returns {any[]} Transformed messages array |
| 58 | 57 | */ |
| 59 | 58 | export function addAssistantPrefix(prompt, tools) { |
| 60 | 59 | if (!prompt.length) { |
| 61 | 60 | return prompt; |
| 62 | 61 | } |
| 63 | 62 | const hasAnyToolMessageshasAnyTools = (Array.isArray(tools) && tools.length > 0) || prompt.some(x => x.role === 'tool'); |
| 64 | 63 | if (!hasAnyToolMessageshasAnyTools && prompt[prompt.length - 1].role === 'assistant') { |
| 65 | 64 | prompt[prompt.length - 1].prefix = true; |
| 66 | 65 | } |
| 67 | 66 | return prompt; |
| @@ -89,10 +88,6 @@ export function postProcessPrompt(messages, type, names) { | ||
| 89 | 88 | return mergeMessages(messages, names, { strict: true, placeholders: true, single: false, tools: false }); |
| 90 | 89 | case PROMPT_PROCESSING_TYPE.STRICT_TOOLS: |
| 91 | 90 | return mergeMessages(messages, names, { strict: true, placeholders: true, single: false, tools: true }); |
| 92 | - case PROMPT_PROCESSING_TYPE.DEEPSEEK: | |
| 93 | - return addAssistantPrefix(mergeMessages(messages, names, { strict: true, placeholders: false, single: false, tools: true })); | |
| 94 | - case PROMPT_PROCESSING_TYPE.DEEPSEEK_REASONER: | |
| 95 | - return addAssistantPrefix(mergeMessages(messages, names, { strict: true, placeholders: true, single: false, tools: true })); | |
| 96 | 91 | case PROMPT_PROCESSING_TYPE.SINGLE: |
| 97 | 92 | return mergeMessages(messages, names, { strict: true, placeholders: false, single: true, tools: false }); |
| 98 | 93 | default: |