4242 快速模型
4343 <tiny-tooltip
4444 effect =" light"
45- content =" 用于代码补全、话题命名等快速响应场景。推荐选择带「代码」标签的模型以获得更好的代码补全效果 。"
45+ content =" 用于代码补全、话题命名等场景。建议选择轻量模型以实现更快的响应速度,例如flash类型或8b/14b模型 。"
4646 placement =" top"
4747 >
4848 <svg-icon class =" help-link" name =" plugin-icon-plugin-help" ></svg-icon >
5151 <tiny-select
5252 clearable
5353 v-model =" state.modelSelection.quickModel"
54+ :options =" compactModelOptions"
5455 filterable
5556 placeholder =" 请选择"
5657 @change =" handleCompactModelChange"
57- popper-class =" model-select-popper"
58- >
59- <template v-for =" item in compactModelOptions " :key =" item .value " >
60- <tiny-option :label =" item.label" :value =" item.value" >
61- <span class =" left" >{{ item.label }}</span >
62- <div >
63- <tiny-tag v-if =" item.capabilities?.codeCompletion" type =" success" effect =" light" size =" small"
64- >代码</tiny-tag
65- >
66- <tiny-tag v-if =" item.capabilities?.compact" type =" info" effect =" light" size =" small"
67- >轻量</tiny-tag
68- >
69- </div >
70- </tiny-option >
71- </template >
72- </tiny-select >
58+ ></tiny-select >
7359 </tiny-form-item >
7460
7561 <div v-if =" selectedDefaultModelInfo" class =" model-info" >
@@ -186,8 +172,8 @@ const emit = defineEmits(['close'])
186172const {
187173 robotSettingState,
188174 saveRobotSettingState,
175+ getAllAvailableModels,
189176 getCompactModels,
190- getNonCodeCompletionModels,
191177 addCustomService,
192178 updateService,
193179 deleteService,
@@ -200,6 +186,15 @@ const getModelValue = (serviceId: string, modelName: string) => {
200186 return serviceId && modelName ? ` ${serviceId }::${modelName } ` : ' '
201187}
202188
189+ const parseModelValue = (value = ' ' ) => {
190+ const [serviceId = ' ' , modelName = ' ' ] = value .split (' ::' )
191+
192+ return {
193+ serviceId ,
194+ modelName
195+ }
196+ }
197+
203198const state = reactive ({
204199 activeTab: ' model-selection' ,
205200 modelSelection: {
@@ -210,9 +205,28 @@ const state = reactive({
210205 editingService: undefined as ModelService | undefined
211206})
212207
213- // 获取所有可用模型选项(排除代码补全专用模型)
208+ const syncModelSelection = () => {
209+ state .modelSelection .defaultModel = getModelValue (
210+ robotSettingState .defaultModel .serviceId ,
211+ robotSettingState .defaultModel .modelName
212+ )
213+ state .modelSelection .quickModel = getModelValue (
214+ robotSettingState .quickModel .serviceId ,
215+ robotSettingState .quickModel .modelName
216+ )
217+ }
218+
219+ const notifyMissingApiKey = (service : ModelService ) => {
220+ useNotify ({
221+ type: ' warning' ,
222+ title: ' 未配置API Key' ,
223+ message: ` 请先为 ${service .label } 配置API Key `
224+ })
225+ }
226+
227+ // 获取所有可用模型选项
214228const allModelOptions = computed (() => {
215- return getNonCodeCompletionModels ().map ((model ) => ({
229+ return getAllAvailableModels ().map ((model ) => ({
216230 label: model .displayLabel ,
217231 value: model .value ,
218232 capabilities: model .capabilities
@@ -221,14 +235,10 @@ const allModelOptions = computed(() => {
221235
222236// 获取快速模型选项
223237const compactModelOptions = computed (() => {
224- const models = getCompactModels ().map ((model ) => ({
238+ return getCompactModels ().map ((model ) => ({
225239 label: model .displayLabel ,
226- value: model .value ,
227- capabilities: model .capabilities ,
228- serviceName: model .serviceName
240+ value: model .value
229241 }))
230-
231- return models .sort ((a , b ) => a .serviceName .localeCompare (b .serviceName , ' zh-CN' ))
232242})
233243
234244// 获取当前选择的默认模型信息
@@ -249,16 +259,15 @@ const handleBack = () => {
249259}
250260
251261const handleModelChange = () => {
252- const [defaultServiceId, defaultModelName] = state .modelSelection .defaultModel .split (' ::' )
262+ const { serviceId : defaultServiceId, modelName : defaultModelName } = parseModelValue (
263+ state .modelSelection .defaultModel
264+ )
253265
254266 // 检查API Key
255267 const defaultService = getServiceById (defaultServiceId )
256268 if (defaultService && ! defaultService .apiKey && ! defaultService .allowEmptyApiKey ) {
257- useNotify ({
258- type: ' warning' ,
259- title: ' 未配置API Key' ,
260- message: ` 请先为 ${defaultService .label } 配置API Key `
261- })
269+ notifyMissingApiKey (defaultService )
270+ syncModelSelection ()
262271 state .activeTab = ' services'
263272 return
264273 }
@@ -273,7 +282,16 @@ const handleModelChange = () => {
273282}
274283
275284const handleCompactModelChange = () => {
276- const [quickServiceId = ' ' , quickModelName = ' ' ] = (state .modelSelection .quickModel || ' ' ).split (' ::' )
285+ const { serviceId : quickServiceId, modelName : quickModelName } = parseModelValue (state .modelSelection .quickModel )
286+ const quickService = getServiceById (quickServiceId )
287+
288+ if (quickService && ! quickService .apiKey && ! quickService .allowEmptyApiKey ) {
289+ notifyMissingApiKey (quickService )
290+ syncModelSelection ()
291+ state .activeTab = ' services'
292+ return
293+ }
294+
277295 const updatedState = {
278296 quickModel: {
279297 serviceId: quickServiceId ,
@@ -289,22 +307,50 @@ const addService = () => {
289307}
290308
291309const editService = (service : any ) => {
292- state .editingService = JSON .parse (JSON .stringify (service )) as ModelService
310+ state .editingService = JSON .parse (JSON .stringify (service ))
293311 state .showServiceDialog = true
294312}
295313
296314const handleDeleteService = (serviceId : string ) => {
297315 deleteService (serviceId )
316+
317+ const shouldResetDefaultModel = robotSettingState .defaultModel .serviceId === serviceId
318+ const shouldResetQuickModel = robotSettingState .quickModel .serviceId === serviceId
319+
320+ if (shouldResetDefaultModel || shouldResetQuickModel ) {
321+ saveRobotSettingState ({
322+ ... (shouldResetDefaultModel
323+ ? {
324+ defaultModel: {
325+ serviceId: ' ' ,
326+ modelName: ' '
327+ }
328+ }
329+ : {}),
330+ ... (shouldResetQuickModel
331+ ? {
332+ quickModel: {
333+ serviceId: ' ' ,
334+ modelName: ' '
335+ }
336+ }
337+ : {})
338+ })
339+ }
340+
341+ syncModelSelection ()
298342}
299343
300- const handleServiceConfirm = (serviceData : Partial <ModelService >) => {
344+ const handleServiceConfirm = async (serviceData : Partial <ModelService >) => {
301345 if (serviceData .id ) {
302346 // 更新现有服务
303- updateService (serviceData .id , serviceData )
347+ await updateService (serviceData .id , serviceData )
304348 } else {
305349 // 添加新服务
306- addCustomService (serviceData as any )
350+ await addCustomService (serviceData as any )
307351 }
352+
353+ syncModelSelection ()
308354}
309355 </script >
310356
0 commit comments