@@ -216,15 +216,13 @@ end
216216--- @class CopilotChat.client.Client : Class
217217--- @field private providers table<string , CopilotChat.config.providers.Provider>
218218--- @field private provider_cache table<string , table>
219- --- @field private models table<string, CopilotChat.client.Model> ?
219+ --- @field private model_cache table<string, CopilotChat.client.Model> ?
220220--- @field private current_job string ?
221- --- @field private headers table<string , string> ?
222221local Client = class (function (self )
223222 self .providers = {}
224223 self .provider_cache = {}
225- self .models = nil
224+ self .model_cache = nil
226225 self .current_job = nil
227- self .headers = nil
228226end )
229227
230228--- Authenticate with GitHub and get the required headers
246244
247245--- Fetch models from the Copilot API
248246--- @return table<string , CopilotChat.client.Model>
249- function Client :fetch_models ()
250- if self .models then
251- return self .models
247+ function Client :models ()
248+ if self .model_cache then
249+ return self .model_cache
252250 end
253251
254252 local models = {}
@@ -282,8 +280,8 @@ function Client:fetch_models()
282280 end
283281
284282 log .debug (' Fetched models:' , # vim .tbl_keys (models ))
285- self .models = models
286- return self .models
283+ self .model_cache = models
284+ return self .model_cache
287285end
288286
289287--- Ask a question to Copilot
@@ -299,7 +297,7 @@ function Client:ask(prompt, opts)
299297 log .debug (' Resources:' , # opts .resources )
300298 log .debug (' History:' , # opts .history )
301299
302- local models = self :fetch_models ()
300+ local models = self :models ()
303301 local model_config = models [opts .model ]
304302 if not model_config then
305303 error (' Model not found: ' .. opts .model )
@@ -573,26 +571,6 @@ function Client:ask(prompt, opts)
573571 }
574572end
575573
576- --- List available models
577- --- @return table<string , table>
578- function Client :list_models ()
579- local models = self :fetch_models ()
580- local result = vim .tbl_keys (models )
581-
582- table.sort (result , function (a , b )
583- a = models [a ]
584- b = models [b ]
585- if a .provider ~= b .provider then
586- return a .provider < b .provider
587- end
588- return a .id < b .id
589- end )
590-
591- return vim .tbl_map (function (id )
592- return models [id ]
593- end , result )
594- end
595-
596574--- Generate embeddings for the given inputs
597575--- @param inputs table<CopilotChat.client.Resource> : The inputs to embed
598576--- @param model string
@@ -603,7 +581,7 @@ function Client:embed(inputs, model)
603581 return inputs
604582 end
605583
606- local models = self :fetch_models ()
584+ local models = self :models ()
607585 local ok , provider_name , embed = pcall (resolve_provider_function , ' embed' , model , models , self .providers )
608586 if not ok then
609587 --- @diagnostic disable-next-line : return-type-mismatch
0 commit comments