From a23195296935dfcf1b28f46d3eee80512c184980 Mon Sep 17 00:00:00 2001 From: suyao Date: Mon, 1 Dec 2025 01:59:41 +0800 Subject: [PATCH] feat: Add model exclusion logic for the Azure OpenAI provider and update the tool call model filter. --- src/renderer/src/config/models/tooluse.ts | 18 ++++++++++++++++++ src/renderer/src/config/models/utils.ts | 10 +++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/config/models/tooluse.ts b/src/renderer/src/config/models/tooluse.ts index 7f90df5f7b..db0a767346 100644 --- a/src/renderer/src/config/models/tooluse.ts +++ b/src/renderer/src/config/models/tooluse.ts @@ -1,6 +1,8 @@ +import { getProviderByModel } from '@renderer/services/AssistantService' import type { Model } from '@renderer/types' import { isSystemProviderId } from '@renderer/types' import { getLowerBaseModelName, isUserSelectedModelType } from '@renderer/utils' +import { isAzureOpenAIProvider } from '@shared/provider' import { isEmbeddingModel, isRerankModel } from './embedding' import { isDeepSeekHybridInferenceModel } from './reasoning' @@ -52,6 +54,13 @@ export const FUNCTION_CALLING_REGEX = new RegExp( 'i' ) +const AZURE_FUNCTION_CALLING_EXCLUDED_MODELS = [ + '(?:Meta-)?Llama-3(?:\\.\\d+)?-[\\w-]+', + 'Phi-[34](?:\\.[\\w-]+)?(?:-[\\w-]+)?', + 'DeepSeek-(?:R1|V3)', + 'Codestral-2501' +] + export function isFunctionCallingModel(model?: Model): boolean { if (!model || isEmbeddingModel(model) || isRerankModel(model) || isTextToImageModel(model)) { return false @@ -67,6 +76,15 @@ export function isFunctionCallingModel(model?: Model): boolean { return FUNCTION_CALLING_REGEX.test(modelId) || FUNCTION_CALLING_REGEX.test(model.name) } + const provider = getProviderByModel(model) + + if (isAzureOpenAIProvider(provider)) { + const azureExcludedRegex = new RegExp(`\\b(?:${AZURE_FUNCTION_CALLING_EXCLUDED_MODELS.join('|')})\\b`, 'i') + if (azureExcludedRegex.test(modelId)) { + return false + } + } + if (['deepseek', 'anthropic', 'kimi', 'moonshot'].includes(model.provider)) { return true } diff --git a/src/renderer/src/config/models/utils.ts b/src/renderer/src/config/models/utils.ts index bd45ed224f..129dc4abfd 100644 --- a/src/renderer/src/config/models/utils.ts +++ b/src/renderer/src/config/models/utils.ts @@ -13,6 +13,7 @@ import { isOpenAIReasoningModel } from './openai' import { isQwenMTModel } from './qwen' +import { isFunctionCallingModel } from './tooluse' import { isGenerateImageModel, isTextToImageModel, isVisionModel } from './vision' export const NOT_SUPPORTED_REGEX = /(?:^tts|whisper|speech)/i export const GEMINI_FLASH_MODEL_REGEX = new RegExp('gemini.*-flash.*$', 'i') @@ -181,8 +182,15 @@ export const isGeminiModel = (model: Model) => { // zhipu 视觉推理模型用这组 special token 标记推理结果 export const ZHIPU_RESULT_TOKENS = ['<|begin_of_box|>', '<|end_of_box|>'] as const +// TODO: 支持提示词模式的工具调用 export const agentModelFilter = (model: Model): boolean => { - return !isEmbeddingModel(model) && !isRerankModel(model) && !isTextToImageModel(model) && !isGenerateImageModel(model) + return ( + !isEmbeddingModel(model) && + !isRerankModel(model) && + !isTextToImageModel(model) && + !isGenerateImageModel(model) && + isFunctionCallingModel(model) + ) } export const isMaxTemperatureOneModel = (model: Model): boolean => {