@@ -7,7 +7,7 @@ import icon_delete from '@/assets/svg/icon_delete.svg'
77import icon_add_outlined from ' @/assets/svg/icon_add_outlined.svg'
88import ParamsForm from ' ./ParamsForm.vue'
99import { modelTypeOptions } from ' @/entity/CommonEntity.ts'
10- import { base_model_options } from ' @/entity/supplier'
10+ import { base_model_options , get_supplier } from ' @/entity/supplier'
1111import { useI18n } from ' vue-i18n'
1212
1313withDefaults (
@@ -44,8 +44,18 @@ const modelRef = ref()
4444const paramsFormRef = ref ()
4545const advancedSetting = ref ([] as ParamsFormData [])
4646const paramsFormDrawer = ref (false )
47- const configExpand = ref (false )
47+ const configExpand = ref (true )
48+ let tempConfigMap = new Map <string , Array <any >>()
4849
50+ const modelSelected = computed (() => {
51+ return !! modelForm .base_model
52+ })
53+ const currentSupplier = computed (() => {
54+ if (! modelForm .supplier ) {
55+ return null
56+ }
57+ return get_supplier (modelForm .supplier )
58+ })
4959const modelList = computed (() => {
5060 if (! modelForm .supplier ) {
5161 return []
@@ -133,6 +143,7 @@ const duplicateName = async (item: any) => {
133143 if (isCreate .value ) {
134144 advancedSetting .value .push ({ ... item , id: + new Date () })
135145 beforeClose ()
146+ tempConfigMap .set (` ${modelForm .supplier }-${modelForm .base_model } ` , [... advancedSetting .value ])
136147 return
137148 }
138149 for (const key in advancedSetting .value ) {
@@ -141,7 +152,7 @@ const duplicateName = async (item: any) => {
141152 Object .assign (element , { ... item })
142153 }
143154 }
144-
155+ tempConfigMap . set ( ` ${ modelForm . supplier }-${ modelForm . base_model } ` , [ ... advancedSetting . value ])
145156 beforeClose ()
146157}
147158
@@ -158,11 +169,13 @@ const supplierChang = (supplier: any) => {
158169 const config = supplier .model_config [modelForm .model_type || 0 ]
159170 modelForm .api_domain = config .api_domain
160171 modelForm .base_model = ' '
172+ advancedSetting .value = []
161173}
162174let curId = + new Date ()
163175const initForm = (item ? : any ) => {
164176 modelForm .id = ' '
165177 modelRef .value .clearValidate ()
178+ tempConfigMap = new Map <string , Array <any >>()
166179 if (item ) {
167180 Object .assign (modelForm , { ... item })
168181 if (item ?.config_list ?.length ) {
@@ -176,16 +189,70 @@ const initForm = (item?: any) => {
176189 } else {
177190 advancedSetting .value = []
178191 }
192+ tempConfigMap .set (` ${modelForm .supplier }-${modelForm .base_model } ` , [... advancedSetting .value ])
193+ }
194+ }
195+ const formatAdvancedSetting = (list : Array <any >) => {
196+ const setting_list = [
197+ ... list .map ((item ) => {
198+ return { id: ++ curId , name: item .name , key: item .key , val: item .val } as any
199+ }),
200+ ]
201+ advancedSetting .value = setting_list
202+ }
203+ const baseModelChange = (val : string ) => {
204+ if (! val || ! modelForm .supplier || ! modelList .value ?.length ) {
205+ return
206+ }
207+ const current_model = modelList .value ?.find ((model : any ) => model .name == val )
208+ if (current_model ) {
209+ modelForm .api_domain = current_model .api_domain || getSupplierDomain () || ' '
210+ }
211+ const current_config_list = tempConfigMap .get (` ${modelForm .supplier }-${modelForm .base_model } ` )
212+ if (current_config_list ) {
213+ formatAdvancedSetting (current_config_list )
214+ return
215+ }
216+ const defaultArgs = getModelDefaultArgs ()
217+ if (defaultArgs ?.size ) {
218+ const defaultArgsList = [... defaultArgs .values ()]
219+ formatAdvancedSetting (defaultArgsList )
220+ tempConfigMap .set (` ${modelForm .supplier }-${modelForm .base_model } ` , [... advancedSetting .value ])
179221 }
180222}
223+ const getSupplierDomain = () => {
224+ return currentSupplier .value ?.model_config [modelForm .model_type || 0 ].api_domain
225+ }
226+ const getModelDefaultArgs = () => {
227+ if (! modelForm .supplier || ! modelForm .base_model ) {
228+ return null
229+ }
230+ const model_config = currentSupplier .value ?.model_config [modelForm .model_type || 0 ]
231+ const common_args = model_config ?.common_args || []
232+ const current_model = modelList .value ?.find ((model : any ) => model .name == modelForm .base_model )
233+
234+ if (current_model ?.args ?.length ) {
235+ const modelArgs = current_model .args
236+ common_args .push (... modelArgs )
237+ }
238+ const argMap = common_args .reduce ((acc : any , item : any ) => {
239+ acc .set (item .key , { ... item , name: item .key })
240+ return acc
241+ }, new Map ())
242+ return argMap
243+ }
181244const emits = defineEmits ([' submit' ])
182245
183246const submitModel = () => {
184247 modelRef .value .validate ((res : any ) => {
185248 if (res ) {
186249 emits (' submit' , {
187250 ... modelForm ,
188- config_list: [... advancedSetting .value ],
251+ config_list: [
252+ ... advancedSetting .value .map ((item ) => {
253+ return { key: item .key , name: item .name , val: item .val }
254+ }),
255+ ],
189256 })
190257 }
191258 })
@@ -249,11 +316,17 @@ defineExpose({
249316 allow-create
250317 default-first-option
251318 :reserve-keyword =" false"
319+ @change =" baseModelChange"
252320 >
253- <el-option v-for =" item in modelList" :key =" item" :label =" item" :value =" item" />
321+ <el-option
322+ v-for =" item in modelList"
323+ :key =" item.name"
324+ :label =" item.name"
325+ :value =" item.name"
326+ />
254327 </el-select >
255328 </el-form-item >
256- <el-form-item prop =" api_domain" :label =" t('model.api_domain_name')" >
329+ <el-form-item v-if = " modelSelected " prop =" api_domain" :label =" t('model.api_domain_name')" >
257330 <el-input
258331 v-model =" modelForm.api_domain"
259332 clearable
@@ -262,7 +335,7 @@ defineExpose({
262335 "
263336 />
264337 </el-form-item >
265- <el-form-item prop =" api_key" label =" API Key" >
338+ <el-form-item v-if = " modelSelected " prop =" api_key" label =" API Key" >
266339 <el-input
267340 v-model =" modelForm.api_key"
268341 clearable
@@ -273,6 +346,7 @@ defineExpose({
273346 </el-form-item >
274347 </el-form >
275348 <div
349+ v-if =" modelSelected"
276350 class =" advance-setting"
277351 :class =" configExpand && 'expand'"
278352 @click =" configExpand = !configExpand"
@@ -282,7 +356,7 @@ defineExpose({
282356 <arrow _down ></arrow _down >
283357 </el-icon >
284358 </div >
285- <div v-if =" configExpand" class =" model-params" >
359+ <div v-if =" modelSelected && configExpand" class =" model-params" >
286360 {{ t('model.model_parameters') }}
287361 <span class =" add" @click =" handleParamsCreate" >
288362 <el-icon size =" 16" >
@@ -293,7 +367,7 @@ defineExpose({
293367 </div >
294368
295369 <div
296- v-if =" configExpand"
370+ v-if =" modelSelected && configExpand"
297371 class =" params-table"
298372 :class =" !advancedSettingPagination.length && 'bottom-border'"
299373 >
@@ -322,7 +396,10 @@ defineExpose({
322396 </el-table-column >
323397 </el-table >
324398 </div >
325- <div v-if =" advancedSetting.length > 5 && configExpand" class =" params-table_pagination" >
399+ <div
400+ v-if =" modelSelected && advancedSetting.length > 5 && configExpand"
401+ class =" params-table_pagination"
402+ >
326403 <el-pagination
327404 :default-page-size =" 5"
328405 layout =" prev, pager, next"
0 commit comments