Skip to content

Commit d8db28a

Browse files
committed
Fix: openai models not appearing
Turns out openai just added many new models, and now curl chunks the output, which has to be manually handled since I'm not using an http library here. This commit fixes that in a quasi-satisfactory way, in that now the openai models are replaced every time the modal opens. This stinks and should be fixed, and will when I have time. Closes #7
1 parent 70c38df commit d8db28a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lua/gptmodels/providers/openai.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ local Provider = {
199199
--| jq -r '.data[].id'
200200

201201
fetch_models = function(cb)
202+
local response_aggregate = ""
202203
local job = cmd.exec({
203204
cmd = "curl",
204205
args = {
@@ -213,11 +214,15 @@ local Provider = {
213214
if err then return cb(err) end
214215
if not json_response then return end
215216

217+
json_response = response_aggregate .. json_response
218+
216219
---@type boolean, nil | { data: nil | { id: string }[], error: nil | { message: string } }
217220
local status_ok, response = pcall(vim.fn.json_decode, json_response)
218221

219222
-- Failed fetches
220-
if not status_ok or not response then
223+
if not response or not status_ok then
224+
-- TODO Test this bit
225+
response_aggregate = response_aggregate .. json_response
221226
return cb("error retrieving openai models")
222227
end
223228

@@ -231,11 +236,17 @@ local Provider = {
231236

232237
for _, model in ipairs(response.data) do
233238
-- Many models are offered, only gpt* or chatgpt* models are chat bots, which is what this plugin uses.
234-
if model.id:sub(1, 3) == "gpt" or model.id:sub(1, 7) == "chatgpt" then
239+
if
240+
model.id:sub(1, 3) == "gpt"
241+
or model.id:sub(1, 7) == "chatgpt"
242+
or model.id:sub(1, 2) == "o1"
243+
or model.id:sub(1, 2) == "o3"
244+
then
235245
table.insert(models, model.id)
236246
end
237247
end
238248

249+
response_aggregate = ""
239250
return cb(nil, models)
240251
end)
241252
})

0 commit comments

Comments
 (0)