From 2ecf83ddaee9e169bc8775afa9d6100d20231d74 Mon Sep 17 00:00:00 2001 From: jialin Date: Sun, 23 Nov 2025 17:26:36 +0800 Subject: [PATCH] fix: warning message for gguf model --- src/locales/zh-CN/models.ts | 2 +- src/pages/llmodels/hooks/index.ts | 63 ++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/locales/zh-CN/models.ts b/src/locales/zh-CN/models.ts index 54a0919f..51069d44 100644 --- a/src/locales/zh-CN/models.ts +++ b/src/locales/zh-CN/models.ts @@ -116,7 +116,7 @@ export default { 'models.form.moreparameters': '参数说明', 'models.table.vram.allocated': '分配显存', 'models.form.backend.warning': - '当前后端不支持 GGUF 格式模型。请在“推理后端”中添加一个支持 GGUF 的后端后再继续。', + '当前后端不支持 GGUF 格式模型。请在“推理后端”中添加一个支持 GGUF 的后端。', 'models.form.backend.warning.gguf': '请确认当前使用的自定义后端已支持 GGUF 格式模型。', 'models.form.ollama.warning': '部署 Ollama 模型后端使用 llama-box。', diff --git a/src/pages/llmodels/hooks/index.ts b/src/pages/llmodels/hooks/index.ts index 7b5221b5..ddac3e59 100644 --- a/src/pages/llmodels/hooks/index.ts +++ b/src/pages/llmodels/hooks/index.ts @@ -317,6 +317,24 @@ export const useCheckCompatibility = () => { }, 300); }; + const checkIsGGUFFileOrNotSupport = (localPath: string, allValues?: any) => { + const isBlobFile = localPath?.split('/').pop()?.includes('sha256'); + const isOllamaModel = localPath?.includes('ollama'); + const isGGUFFile = localPath?.endsWith?.('.gguf'); + + const isOllamaModelFile = isBlobFile || isOllamaModel; + return ( + isGGUFFile || + isOllamaModelFile || + allValues?.huggingface_filename?.endsWith?.('.gguf') || + allValues?.model_scope_file_path?.endsWith?.('.gguf') + ); + }; + + const clearCacheFormValues = () => { + cacheFormValuesRef.current = {}; + }; + const updateShowWarning = (params: { backend: string; localPath: string; @@ -330,29 +348,17 @@ export const useCheckCompatibility = () => { }; } - const isBlobFile = localPath?.split('/').pop()?.includes('sha256'); - const isOllamaModel = localPath?.includes('ollama'); - const isGGUFFile = localPath.endsWith('.gguf'); - - const isOllamaModelFile = isBlobFile || isOllamaModel; + const isGGUFFile = checkIsGGUFFileOrNotSupport(localPath); let warningMessage = ''; - if ( - (isGGUFFile || isOllamaModelFile) && - BuiltInBackendOptions.includes(backend) - ) { + if (isGGUFFile && BuiltInBackendOptions.includes(backend)) { warningMessage = intl.formatMessage({ id: 'models.form.backend.warning' }); - } else if ( - (isGGUFFile || isOllamaModelFile) && - !BuiltInBackendOptions.includes(backend) - ) { - warningMessage = intl.formatMessage({ - id: 'models.form.backend.warning.gguf' - }); + } else if (isGGUFFile && !BuiltInBackendOptions.includes(backend)) { + warningMessage = ''; } - + clearCacheFormValues(); return { show: !!warningMessage, isHtml: true, @@ -379,10 +385,6 @@ export const useCheckCompatibility = () => { return null; }; - const clearCacheFormValues = () => { - cacheFormValuesRef.current = {}; - }; - const noLocalPathValue = (allValues: any) => { return ( allValues.source === modelSourceMap.local_path_value && @@ -396,7 +398,6 @@ export const useCheckCompatibility = () => { source: string; }) => { const { allValues, source } = params; - console.log('handleOnValuesChange', allValues); if ( _.isEqual(cacheFormValuesRef.current, allValues) || noLocalPathValue(allValues) || @@ -406,6 +407,24 @@ export const useCheckCompatibility = () => { return; } + // check gguf: for online and local path + if ( + checkIsGGUFFileOrNotSupport(allValues.local_path, allValues) && + BuiltInBackendOptions.includes(allValues.backend) + ) { + clearCacheFormValues(); + setWarningStatus({ + show: true, + type: 'warning', + isHtml: true, + message: intl.formatMessage({ + id: 'models.form.backend.warning' + }) + }); + + return; + } + cacheFormValuesRef.current = _.cloneDeep(allValues); const gpuSelector = generateGPUIds(allValues); return await handleDoEvalute({