Skip to content

Commit 624cf5c

Browse files
author
Mihamina RKTMB
committed
fix(provider): Fix #1442 - Comply to code review
1 parent 62e8b5b commit 624cf5c

1 file changed

Lines changed: 14 additions & 25 deletions

File tree

lua/CopilotChat/config/providers.lua

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,10 @@ M.copilot = {
338338
return model.capabilities.type == 'chat' and model.model_picker_enabled
339339
end)
340340
:map(function(model)
341-
local supported_endpoints = model.supported_endpoints
341+
local supported_endpoints = model.supported_endpoints or {}
342+
-- Pre-compute whether this model uses the Responses API
343+
local use_responses = vim.tbl_contains(supported_endpoints, '/responses')
344+
342345
return {
343346
id = model.id,
344347
name = model.name,
@@ -349,7 +352,7 @@ M.copilot = {
349352
tools = model.capabilities.supports.tool_calls,
350353
policy = not model['policy'] or model['policy']['state'] == 'enabled',
351354
version = model.version,
352-
supported_endpoints = supported_endpoints,
355+
use_responses = use_responses,
353356
}
354357
end)
355358
:totable()
@@ -379,12 +382,8 @@ M.copilot = {
379382
prepare_input = function(inputs, opts)
380383
local is_o1 = vim.startswith(opts.model.id, 'o1')
381384

382-
-- Check if this model supports only the /responses endpoint
383-
local use_responses_api = opts.model.supported_endpoints
384-
and #opts.model.supported_endpoints == 1
385-
and opts.model.supported_endpoints[1] == '/responses'
386-
387-
if use_responses_api then
385+
-- Check if this model uses the Responses API
386+
if opts.model.use_responses then
388387
-- Prepare input for Responses API
389388
local instructions = nil
390389
local input_messages = {}
@@ -490,14 +489,8 @@ M.copilot = {
490489
end,
491490

492491
prepare_output = function(output, opts)
493-
-- Check if this is a Responses API response
494-
local use_responses_api = opts
495-
and opts.model
496-
and opts.model.supported_endpoints
497-
and #opts.model.supported_endpoints == 1
498-
and opts.model.supported_endpoints[1] == '/responses'
499-
500-
if use_responses_api then
492+
-- Check if this model uses the Responses API
493+
if opts and opts.model and opts.model.use_responses then
501494
-- Handle Responses API output format
502495
local content = ''
503496
local reasoning = ''
@@ -609,7 +602,7 @@ M.copilot = {
609602
if response.output and #response.output > 0 then
610603
for _, msg in ipairs(response.output) do
611604
if msg.content and #msg.content > 0 then
612-
content = content + extract_text_from_parts(msg.content)
605+
content = content .. extract_text_from_parts(msg.content)
613606
end
614607
end
615608
end
@@ -682,14 +675,8 @@ M.copilot = {
682675
end,
683676

684677
get_url = function(opts)
685-
-- Check if this model supports only the /responses endpoint
686-
local use_responses_api = opts
687-
and opts.model
688-
and opts.model.supported_endpoints
689-
and #opts.model.supported_endpoints == 1
690-
and opts.model.supported_endpoints[1] == '/responses'
691-
692-
if use_responses_api then
678+
-- Check if this model uses the Responses API
679+
if opts and opts.model and opts.model.use_responses then
693680
return 'https://api.githubcopilot.com/responses'
694681
end
695682

@@ -732,6 +719,7 @@ M.github_models = {
732719
tools = vim.tbl_contains(model.capabilities, 'tool-calling'),
733720
reasoning = vim.tbl_contains(model.capabilities, 'reasoning'),
734721
version = model.version,
722+
use_responses = false, -- GitHub Models don't use Responses API
735723
}
736724
end)
737725
:totable()
@@ -746,3 +734,4 @@ M.github_models = {
746734
}
747735

748736
return M
737+

0 commit comments

Comments
 (0)