Skip to content

Commit 62b57b5

Browse files
authored
Merge pull request #37 from chaitin/develop/jw
fix: 修复API地址验证逻辑并优化错误处理
2 parents 8be26b4 + 4b25556 commit 62b57b5

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

ui/ModelModal/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@yokowu/modelkit-ui",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "A reusable AI model configuration modal component for React applications",
55
"private": false,
66
"type": "module",

ui/ModelModal/src/ModelModal.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ export const ModelModal: React.FC<ModelModalProps> = ({
507507
value: true,
508508
message: 'URL 不能为空',
509509
},
510+
validate: (value) => {
511+
if (!value) return true; // 空值由required规则处理
512+
const hasScheme = /^https?:\/\//i.test(value);
513+
return hasScheme || 'API地址必须包含协议(http://或https://)';
514+
},
510515
}}
511516
render={({ field }) => (
512517
<TextField
@@ -682,7 +687,6 @@ export const ModelModal: React.FC<ModelModalProps> = ({
682687
</Box>
683688
</>
684689
) : modelUserList.length === 0 ? (
685-
<>
686690
<Button
687691
fullWidth
688692
variant='outlined'
@@ -699,12 +703,6 @@ export const ModelModal: React.FC<ModelModalProps> = ({
699703
>
700704
获取模型列表
701705
</Button>
702-
{addModelError && (
703-
<Box sx={{ fontSize: 12, color: 'error.main', mt: 1 }}>
704-
{addModelError}
705-
</Box>
706-
)}
707-
</>
708706
) : (
709707
<>
710708
<Box sx={{ fontSize: 14, lineHeight: '32px', mt: 2 }}>

usecase/modelkit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,12 @@ func generateBaseURLFixSuggestion(errContent string, baseURL string) string {
446446
hasPath = true
447447
}
448448

449-
errType := consts.AddModelBaseURLErrTypeHost
449+
var errType consts.AddModelBaseURLErrType
450450
// 404 且是本地地址,建议使用宿主机主机名
451451
if is404 && isLocal {
452452
errType = consts.AddModelBaseURLErrTypeHost
453-
} else if !isLocal && !hasPath && !is404 {
454-
// 不是本地地址,且没有path,且不是404,建议在API地址末尾添加/v1
453+
} else if !isLocal && !hasPath {
454+
// 不是本地地址,且没有path,建议在API地址末尾添加/v1
455455
errType = consts.AddModelBaseURLErrTypeV1Path
456456
} else {
457457
return ""

0 commit comments

Comments
 (0)