Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/ModelModal/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 0 additions & 5 deletions ui/ModelModal/src/ModelModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,6 @@ export const ModelModal: React.FC<ModelModalProps> = ({
/>
)}
/>
{providerBrand === 'Other' && (
<Box sx={{ fontSize: 12, color: 'error.main', mt: 1 }}>
模型供应商必须支持与 OpenAI 兼容的 API 格式
</Box>
)}
<Stack
direction={'row'}
alignItems={'center'}
Expand Down
8 changes: 4 additions & 4 deletions ui/ModelModal/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export const isValidURL = (url: string, isOllama: boolean): string => {
}

// 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 {
Expand Down
12 changes: 6 additions & 6 deletions usecase/modelkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down