11import { Autowired } from '@opensumi/di'
2- import { AI_NATIVE_SETTING_GROUP_ID , localize , MaybePromise , Delayer , CommandService } from '@opensumi/ide-core-common' ;
2+ import { AI_NATIVE_SETTING_GROUP_ID , localize , MaybePromise , Delayer , CommandService , AINativeSettingSectionsId } from '@opensumi/ide-core-common' ;
33import { Domain , PreferenceContribution , PreferenceSchema , ClientAppContribution , IClientApp , PreferenceService , COMMON_COMMANDS , IPreferenceSettingsService } from '@opensumi/ide-core-browser'
44import { ISettingRegistry , SettingContribution } from '@opensumi/ide-preferences' ;
55import { AIModelServicePath , IAIModelServiceProxy , ModelSettingId } from '../common'
@@ -18,46 +18,6 @@ const aiNativePreferenceSchema: PreferenceSchema = {
1818 [ ModelSettingId . apiKey ] : {
1919 type : 'string' ,
2020 } ,
21- [ ModelSettingId . chatModelName ] : {
22- type : 'string' ,
23- } ,
24- [ ModelSettingId . chatSystemPrompt ] : {
25- type : 'string' ,
26- } ,
27- [ ModelSettingId . chatMaxTokens ] : {
28- type : 'number' ,
29- minimum : 0 ,
30- defaultValue : 1024 ,
31- description : localize ( 'preference.ai.model.maxTokens.description' ) ,
32- } ,
33- [ ModelSettingId . chatTemperature ] : {
34- type : 'string' ,
35- // minimum: 0,
36- // maximum: 1,
37- defaultValue : '0.20' ,
38- description : localize ( 'preference.ai.model.temperature.description' ) ,
39- } ,
40- [ ModelSettingId . chatPresencePenalty ] : {
41- type : 'string' ,
42- // minimum: -2.0,
43- // maximum: 2.0,
44- defaultValue : '1.0' ,
45- description : localize ( 'preference.ai.model.presencePenalty.description' ) ,
46- } ,
47- [ ModelSettingId . chatFrequencyPenalty ] : {
48- type : 'string' ,
49- // minimum: -2.0,
50- // maximum: 2.0,
51- defaultValue : '1.0' ,
52- description : localize ( 'preference.ai.model.frequencyPenalty.description' ) ,
53- } ,
54- [ ModelSettingId . chatTopP ] : {
55- type : 'string' ,
56- // minimum: 0,
57- // maximum: 1,
58- defaultValue : '1' ,
59- description : localize ( 'preference.ai.model.topP.description' ) ,
60- } ,
6121 [ ModelSettingId . codeModelName ] : {
6222 type : 'string' ,
6323 description : localize ( 'preference.ai.model.code.modelName.tooltip' )
@@ -145,11 +105,8 @@ export class AIModelContribution implements PreferenceContribution, SettingContr
145105 delayer . trigger ( ( ) => this . setModeConfig ( values ) )
146106 } )
147107 } )
148- this . checkModelConfig ( values ) . then ( ( valid ) => {
149- if ( valid ) {
150- delayer . trigger ( ( ) => this . setModeConfig ( values ) )
151- }
152- } )
108+ delayer . trigger ( ( ) => this . setModeConfig ( values ) ) ;
109+ this . checkModelConfig ( ) ;
153110 }
154111
155112 registerSetting ( registry : ISettingRegistry ) : void {
@@ -164,34 +121,6 @@ export class AIModelContribution implements PreferenceContribution, SettingContr
164121 id : ModelSettingId . apiKey ,
165122 localized : 'preference.ai.model.apiKey' ,
166123 } ,
167- {
168- id : ModelSettingId . chatModelName ,
169- localized : 'preference.ai.model.chat.modelName' ,
170- } ,
171- {
172- id : ModelSettingId . chatSystemPrompt ,
173- localized : 'preference.ai.model.chat.systemPrompt' ,
174- } ,
175- {
176- id : ModelSettingId . chatMaxTokens ,
177- localized : 'preference.ai.model.chat.maxTokens' ,
178- } ,
179- {
180- id : ModelSettingId . chatTemperature ,
181- localized : 'preference.ai.model.chat.temperature' ,
182- } ,
183- {
184- id : ModelSettingId . chatPresencePenalty ,
185- localized : 'preference.ai.model.chat.presencePenalty' ,
186- } ,
187- {
188- id : ModelSettingId . chatFrequencyPenalty ,
189- localized : 'preference.ai.model.chat.frequencyPenalty' ,
190- } ,
191- {
192- id : ModelSettingId . chatTopP ,
193- localized : 'preference.ai.model.chat.topP' ,
194- } ,
195124 {
196125 id : ModelSettingId . codeModelName ,
197126 localized : 'preference.ai.model.code.modelName' ,
@@ -228,18 +157,24 @@ export class AIModelContribution implements PreferenceContribution, SettingContr
228157 } ) ;
229158 }
230159
231- private async checkModelConfig ( values : Record < string , any > ) {
232- if ( values . baseUrl && values . chatModelName ) {
233- return true
234- }
235- const res = await this . messageService . info ( localize ( 'ai.model.noConfig' ) , [
236- localize ( 'ai.model.go' )
237- ] )
238- if ( res === localize ( 'ai.model.go' ) ) {
239- await this . commandService . executeCommand ( COMMON_COMMANDS . OPEN_PREFERENCES . id )
240- this . preferenceSettingsService . scrollToPreference ( ModelSettingId . baseUrl )
160+ private async checkModelConfig ( ) {
161+ const requirePreference = [
162+ AINativeSettingSectionsId . DeepseekApiKey ,
163+ AINativeSettingSectionsId . OpenaiApiKey ,
164+ AINativeSettingSectionsId . AnthropicApiKey ,
165+ ] ;
166+
167+ const hasRequirePreference = requirePreference . some ( preference => ! ! this . preferenceService . getValid ( preference ) ) ;
168+ if ( ! hasRequirePreference ) {
169+ this . preferenceService . has ( AINativeSettingSectionsId . DeepseekApiKey ) ;
170+ const res = await this . messageService . info ( localize ( 'ai.model.noConfig' ) , [
171+ localize ( 'ai.model.go' )
172+ ] ) ;
173+ if ( res === localize ( 'ai.model.go' ) ) {
174+ await this . commandService . executeCommand ( COMMON_COMMANDS . OPEN_PREFERENCES . id )
175+ this . preferenceSettingsService . scrollToPreference ( AINativeSettingSectionsId . LLMModelSelection ) ;
176+ }
241177 }
242- return false
243178 }
244179
245180 private setModeConfig ( values : Record < string , any > ) {
0 commit comments