From aafb528c176283a050e7b86c45de91365ddebb2c Mon Sep 17 00:00:00 2001 From: jiangwel Date: Mon, 1 Sep 2025 00:26:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A6=81=E6=AD=A2=E9=9D=9Eopenai=20bas?= =?UTF-8?q?eurl=E8=BE=93=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/ModelModal/package.json | 2 +- ui/ModelModal/src/ModelModal.tsx | 5 ----- ui/ModelModal/src/utils/index.ts | 8 ++++---- usecase/modelkit.go | 12 ++++++------ 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/ui/ModelModal/package.json b/ui/ModelModal/package.json index c9608d3..68a16ff 100644 --- a/ui/ModelModal/package.json +++ b/ui/ModelModal/package.json @@ -1,6 +1,6 @@ { "name": "@yokowu/modelkit-ui", - "version": "0.7.5", + "version": "0.7.6", "description": "A reusable AI model configuration modal component for React applications", "private": false, "type": "module", diff --git a/ui/ModelModal/src/ModelModal.tsx b/ui/ModelModal/src/ModelModal.tsx index 81511fd..9e88ceb 100644 --- a/ui/ModelModal/src/ModelModal.tsx +++ b/ui/ModelModal/src/ModelModal.tsx @@ -533,11 +533,6 @@ export const ModelModal: React.FC = ({ /> )} /> - {providerBrand === 'Other' && ( - - 模型供应商必须支持与 OpenAI 兼容的 API 格式 - - )} { } // 3. 检查是否以 /v+数字 结尾 或者 包含/v+数字/ - // const pathPattern = /\/v\d+(\/.*)?$/; - // if (!isOllama && !pathPattern.test(urlObj.pathname)) { - // return "模型供应商必须支持与 OpenAI 兼容的 API 格式"; - // } + const pathPattern = /\/v\d+(\/.*)?$/; + if (!isOllama && !pathPattern.test(urlObj.pathname)) { + return "模型供应商必须支持与 OpenAI 兼容的 API 格式"; + } return ""; } catch { diff --git a/usecase/modelkit.go b/usecase/modelkit.go index 190d9f6..14abf70 100644 --- a/usecase/modelkit.go +++ b/usecase/modelkit.go @@ -59,7 +59,7 @@ func ModelList(ctx context.Context, req *domain.ModelListReq) (*domain.ModelList resp, err := ollamaListModel(req.BaseURL, httpClient, req.APIHeader) // ollama list发生错误, 尝试修复url if err != nil { - msg := generateBaseURLFixSuggestion(err.Error(), req.BaseURL) + msg := generateBaseURLFixSuggestion(err.Error(), req.BaseURL, provider) if msg == "" { return &domain.ModelListResp{ Error: err.Error(), @@ -206,7 +206,7 @@ func CheckModel(ctx context.Context, req *domain.CheckModelReq) (*domain.CheckMo resp, err := getChatModelGenerateChat(ctx, provider, modelType, req.BaseURL, req) // 其他模型供应商,尝试修复baseURL if err != nil && provider == consts.ModelProviderOther { - msg := generateBaseURLFixSuggestion(err.Error(), req.BaseURL) + msg := generateBaseURLFixSuggestion(err.Error(), req.BaseURL, provider) if msg == "" { checkResp.Error = err.Error() } else { @@ -429,8 +429,8 @@ func reqModelListApi[T domain.ModelResponseParser](req *domain.ModelListReq, htt return (*resp).ParseModels(), nil } -func generateBaseURLFixSuggestion(errContent string, baseURL string) string { - var is404, isLocal, hasPath bool +func generateBaseURLFixSuggestion(errContent string, baseURL string, provider consts.ModelProvider) string { + var is404, isLocal, hasPath , isOther bool if strings.Contains(errContent, "404") || strings.Contains(errContent, "connection refused") { is404 = true } @@ -441,16 +441,16 @@ func generateBaseURLFixSuggestion(errContent string, baseURL string) string { if strings.Contains(parsedURL.Host, consts.LocalHost) || strings.Contains(parsedURL.Host, consts.LocalIP) { isLocal = true } - if parsedURL.Path != "" { hasPath = true } + isOther = provider == consts.ModelProviderOther var errType consts.AddModelBaseURLErrType // 404 且是本地地址,建议使用宿主机主机名 if is404 && isLocal { errType = consts.AddModelBaseURLErrTypeHost - } else if !isLocal && !hasPath { + } else if !isLocal && !hasPath && isOther { // 不是本地地址,且没有path,建议在API地址末尾添加/v1 errType = consts.AddModelBaseURLErrTypeV1Path } else {