@@ -63,6 +63,7 @@ local class = require('CopilotChat.utils.class')
6363local files = require (' CopilotChat.utils.files' )
6464local orderedmap = require (' CopilotChat.utils.orderedmap' )
6565local stringbuffer = require (' CopilotChat.utils.stringbuffer' )
66+ local model = require (' fidget.notification.model' )
6667
6768--- Constants
6869local RESOURCE_SHORT_FORMAT = ' # %s\n ```%s start_line=% end_line=%s\n %s\n ```'
@@ -299,28 +300,6 @@ function Client:ask(opts)
299300 opts = opts or {}
300301 local job_id = utils .uuid ()
301302
302- -- handle auto model selection
303- if opts .model == ' auto' then
304- notify .publish (notify .STATUS , ' Auto-selecting model...' )
305- local provider_name = ' copilot'
306- local provider = self :get_providers ():get (provider_name )
307-
308- if provider and provider .route_model then
309- local headers = self :authenticate (provider_name )
310- local selected_model , err = provider .route_model (headers , { ' auto' })
311-
312- if selected_model then
313- opts .model = selected_model
314- else
315- log .warn (' Auto mode failed, falling back to gpt-4o. Error: ' .. tostring (err ))
316- opts .model = ' gpt-4o'
317- end
318- else
319- log .warn (' Auto mode not supported, falling back to gpt-4o' )
320- opts .model = ' gpt-4o'
321- end
322- end
323-
324303 log .debug (' Model:' , opts .model )
325304 log .debug (' Tools:' , # opts .tools )
326305 log .debug (' Resources:' , # opts .resources )
@@ -341,6 +320,24 @@ function Client:ask(opts)
341320 error (' Provider not found: ' .. provider_name )
342321 end
343322
323+ if provider .route_model then
324+ if not opts .headless then
325+ notify .publish (notify .STATUS , ' Routing model...' )
326+ end
327+
328+ local headers = self :authenticate (provider_name )
329+ local resolved_model = provider .route_model (headers , opts )
330+
331+ if resolved_model and resolved_model ~= opts .model then
332+ opts .model = resolved_model
333+
334+ model_config = models [opts .model ]
335+ if not model_config then
336+ error (' Routed model not found: ' .. opts .model )
337+ end
338+ end
339+ end
340+
344341 local options = {
345342 model = vim .tbl_extend (' force' , model_config , {
346343 id = opts .model :gsub (' :' .. provider_name .. ' $' , ' ' ),
0 commit comments