@@ -14,6 +14,7 @@ import { useTranslation } from "react-i18next";
1414import { useQuery } from "react-query" ;
1515import { useModel } from ".." ;
1616import { ModelManagement } from "@/pages/BuildPage/bench/ModelManagement" ;
17+ import { hasValidWorkbenchEmbeddingModelId } from "./workbenchModelValidation" ;
1718
1819export const ModelSelect = ( { required = false , close = false , label, tooltipText = '' , value, options, onChange, placeholder = '' } ) => {
1920 const defaultValue = useMemo ( ( ) => {
@@ -87,20 +88,8 @@ export default function WorkbenchModel({ onBack }) {
8788 return '' ;
8889 } ;
8990
90- const handleSave = async ( ) => {
91+ const submitConfig = async ( ) => {
9192 const { linsightDefaultModelId, sourceModelId, asrModelId, ttsModelId, chatTitleLlmId, models } = form ;
92- const errors = [ ] ;
93- if ( ! models . length ) {
94- errors . push ( '请至少配置一个对话模型' ) ;
95- }
96- // Reject blank rows: a model without an id serializes to `{ id: '' }`,
97- // which reaches the client model picker as <SelectItem value="">
98- // (empty string) and crashes the whole page in Radix. Force the admin
99- // to pick a model or remove the empty row before saving.
100- if ( models . some ( ( m ) => ! m . id ) ) {
101- errors . push ( '存在未选择模型的对话模型行,请选择模型或删除该行' ) ;
102- }
103- if ( errors . length ) return message ( { variant : 'error' , description : errors } ) ;
10493 setSaveLoad ( true ) ;
10594 try {
10695 const data = {
@@ -159,7 +148,26 @@ export default function WorkbenchModel({ onBack }) {
159148 return lastEmbeddingId !== currentEmbeddingId ;
160149 } ;
161150
162- const handleSaveWithConfirm = ( ) => {
151+ const handleSave = ( ) => {
152+ const errors = [ ] ;
153+ if ( ! form . models . length ) {
154+ errors . push ( '请至少配置一个对话模型' ) ;
155+ }
156+ // Reject blank rows: a model without an id serializes to `{ id: '' }`,
157+ // which reaches the client model picker as <SelectItem value="">
158+ // (empty string) and crashes the whole page in Radix. Force the admin
159+ // to pick a model or remove the empty row before saving.
160+ if ( form . models . some ( ( model ) => ! model . id ) ) {
161+ errors . push ( '存在未选择模型的对话模型行,请选择模型或删除该行' ) ;
162+ }
163+ if ( ! hasValidWorkbenchEmbeddingModelId ( form . sourceModelId ) ) {
164+ errors . push ( t ( 'model.workVectorModel' ) + t ( 'bs:required' ) ) ;
165+ }
166+ if ( errors . length ) {
167+ message ( { variant : 'error' , description : errors } ) ;
168+ return ;
169+ }
170+
163171 if ( checkEmbeddingModified ( ) ) {
164172 bsConfirm ( {
165173 title : t ( 'model.tip' ) ,
@@ -168,12 +176,12 @@ export default function WorkbenchModel({ onBack }) {
168176 okTxt : t ( 'model.confirm' ) ,
169177 canelTxt : t ( 'model.cancel' ) ,
170178 onOk ( next ) {
171- handleSave ( ) . then ( next ) ;
179+ submitConfig ( ) . then ( next ) ;
172180 } ,
173181 onCancel ( ) { }
174182 } ) ;
175183 } else {
176- handleSave ( ) ;
184+ submitConfig ( ) ;
177185 }
178186 } ;
179187
@@ -308,7 +316,7 @@ export default function WorkbenchModel({ onBack }) {
308316 < Button
309317 className = "px-10"
310318 disabled = { saveload }
311- onClick = { handleSaveWithConfirm }
319+ onClick = { handleSave }
312320 >
313321 { saveload && < LoadIcon className = "mr-2" /> }
314322 { t ( 'model.save' ) }
0 commit comments