@@ -11,13 +11,14 @@ import { ApiHandler, buildApiHandler } from "../../api"
1111import { ProviderSettingsManager } from "../../core/config/ProviderSettingsManager"
1212import { OpenRouterHandler } from "../../api/providers"
1313import { ApiStreamChunk } from "../../api/transform/stream"
14- import { ILLM , LLMOptions , TabAutocompleteOptions } from "../continuedev/core/index.js"
14+ import { ILLM , LLMOptions } from "../continuedev/core/index.js"
1515import { DEFAULT_AUTOCOMPLETE_OPTS } from "../continuedev/core/util/parameters.js"
1616import Mistral from "../continuedev/core/llm/llms/Mistral"
1717import { OpenAI } from "../continuedev/core/llm/llms/OpenAI"
1818
1919export class AutocompleteModel {
2020 private apiHandler : ApiHandler | null = null
21+ private profile : ProviderSettings | null = null
2122 public loaded = false
2223
2324 constructor ( apiHandler : ApiHandler | null = null ) {
@@ -28,6 +29,7 @@ export class AutocompleteModel {
2829 }
2930 private cleanup ( ) : void {
3031 this . apiHandler = null
32+ this . profile = null
3133 this . loaded = false
3234 }
3335
@@ -63,12 +65,12 @@ export class AutocompleteModel {
6365 selectedProfile : ProviderSettingsEntry ,
6466 provider : keyof typeof AUTOCOMPLETE_PROVIDER_MODELS ,
6567 ) : Promise < void > {
66- const profile = await providerSettingsManager . getProfile ( {
68+ this . profile = await providerSettingsManager . getProfile ( {
6769 id : selectedProfile . id ,
6870 } )
6971
7072 this . apiHandler = buildApiHandler ( {
71- ...profile ,
73+ ...this . profile ,
7274 [ modelIdKeysByProvider [ provider ] ] : AUTOCOMPLETE_PROVIDER_MODELS [ provider ] ,
7375 } )
7476
@@ -80,91 +82,94 @@ export class AutocompleteModel {
8082 /**
8183 * Creates an ILLM-compatible instance from provider settings for autocomplete.
8284 * Supports mistral, kilocode, openrouter, and bedrock providers.
85+ * Uses the current profile loaded in this.profile.
8386 *
84- * @param profile - The provider settings profile
85- * @param provider - The autocomplete provider key
8687 * @returns ILLM instance or null if configuration is invalid
8788 */
88- public createILLMFromProfile ( profile : ProviderSettings , provider : AutocompleteProviderKey ) : ILLM | null {
89- const model = "codestral-latest"
90- const apiKey = 'TODO_FILL_THIS_IN'
91- const apiBase = 'https://api.mistral.ai/v1'
92- const overrideProvider = 'mistral'
89+ public getILLM ( ) : ILLM | null {
90+ if ( ! this . profile ?. apiProvider ) {
91+ console . warn ( "[AutocompleteModel] No profile loaded" )
92+ return null
93+ }
94+
95+ const provider = this . profile . apiProvider as AutocompleteProviderKey
9396
9497 try {
9598 // Extract provider-specific configuration
96- const config = this . extractProviderConfig ( profile , provider )
99+ const config = this . extractProviderConfig ( )
97100 if ( ! config ) {
98101 console . warn ( `[AutocompleteModel] Failed to extract config for provider: ${ provider } ` )
99102 return null
100103 }
101104
102105 // Build LLM options
103106 const llmOptions : LLMOptions = {
104- model : model || config . model ,
105- apiKey : apiKey || config . apiKey ,
106- apiBase : apiBase || config . apiBase ,
107+ model : config . model ,
108+ apiKey : config . apiKey ,
109+ apiBase : config . apiBase ,
107110 contextLength : 32000 , // Default for Codestral models
108111 completionOptions : {
109- model : model || config . model ,
112+ model : config . model ,
110113 temperature : 0.2 , // Lower temperature for more deterministic autocomplete
111114 maxTokens : 256 , // Reasonable limit for code completions
112115 } ,
113116 autocompleteOptions : {
114117 ...DEFAULT_AUTOCOMPLETE_OPTS ,
115118 useCache : false , // Disable caching for autocomplete
116119 } ,
117- uniqueId : `autocomplete-${ overrideProvider || provider } -${ Date . now ( ) } ` ,
120+ uniqueId : `autocomplete-${ provider } -${ Date . now ( ) } ` ,
118121 }
119122
120123 // Create appropriate LLM instance based on provider
121- return this . createLLMInstance ( overrideProvider || provider , llmOptions )
124+ return this . createLLMInstance ( provider , llmOptions )
122125 } catch ( error ) {
123- console . error ( `[AutocompleteModel] Error creating ILLM for provider ${ overrideProvider || provider } :` , error )
126+ console . error ( `[AutocompleteModel] Error creating ILLM for provider ${ provider } :` , error )
124127 return null
125128 }
126129 }
127130
128131 /**
129- * Extracts provider-specific configuration (API key, base URL, model)
132+ * Extracts provider-specific configuration (API key, base URL, model) from this.profile
130133 */
131- private extractProviderConfig (
132- profile : ProviderSettings ,
133- provider : AutocompleteProviderKey ,
134- ) : { apiKey : string ; apiBase : string ; model : string } | null {
134+ private extractProviderConfig ( ) : { apiKey : string ; apiBase : string ; model : string } | null {
135+ if ( ! this . profile ?. apiProvider ) {
136+ return null
137+ }
138+
139+ const provider = this . profile . apiProvider as AutocompleteProviderKey
135140 const model = AUTOCOMPLETE_PROVIDER_MODELS [ provider ]
136141
137142 switch ( provider ) {
138143 case "mistral" :
139- if ( ! profile . mistralApiKey ) {
144+ if ( ! this . profile . mistralApiKey ) {
140145 console . warn ( "[AutocompleteModel] Missing Mistral API key" )
141146 return null
142147 }
143148 return {
144- apiKey : profile . mistralApiKey ,
145- apiBase : profile . mistralCodestralUrl || "https://codestral.mistral.ai/v1/" ,
149+ apiKey : this . profile . mistralApiKey ,
150+ apiBase : this . profile . mistralCodestralUrl || "https://codestral.mistral.ai/v1/" ,
146151 model,
147152 }
148153
149154 case "kilocode" :
150- if ( ! profile . kilocodeToken ) {
155+ if ( ! this . profile . kilocodeToken ) {
151156 console . warn ( "[AutocompleteModel] Missing Kilocode token" )
152157 return null
153158 }
154159 return {
155- apiKey : profile . kilocodeToken ,
156- apiBase : `${ getKiloBaseUriFromToken ( profile . kilocodeToken ) } /openrouter/api/v1` ,
160+ apiKey : this . profile . kilocodeToken ,
161+ apiBase : `${ getKiloBaseUriFromToken ( this . profile . kilocodeToken ) } /openrouter/api/v1` ,
157162 model,
158163 }
159164
160165 case "openrouter" :
161- if ( ! profile . openRouterApiKey ) {
166+ if ( ! this . profile . openRouterApiKey ) {
162167 console . warn ( "[AutocompleteModel] Missing OpenRouter API key" )
163168 return null
164169 }
165170 return {
166- apiKey : profile . openRouterApiKey ,
167- apiBase : profile . openRouterBaseUrl || "https://openrouter.ai/api/v1" ,
171+ apiKey : this . profile . openRouterApiKey ,
172+ apiBase : this . profile . openRouterBaseUrl || "https://openrouter.ai/api/v1" ,
168173 model,
169174 }
170175
0 commit comments