Skip to content

Commit

Permalink
feat(provider): add gemini online model support
Browse files Browse the repository at this point in the history
- credits to dvoidus (main...dvoidus:parrot.nvim:main)
  • Loading branch information
frankroeder committed Sep 3, 2024
1 parent 11eb2ff commit be975ee
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lua/parrot/provider/gemini.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local logger = require("parrot.logger")
local utils = require("parrot.utils")
local Job = require("plenary.job")

---@class Gemini
---@field endpoint string
Expand Down Expand Up @@ -142,12 +143,32 @@ end

---Returns the list of available models
---@return string[]
function Gemini:get_available_models()
return {
function Gemini:get_available_models(online)
local ids = {
"gemini-1.5-flash",
"gemini-1.5-pro",
"gemini-1.0-pro",
}
if online and self:verify() then
local job = Job:new({
command = "curl",
args = { "https://generativelanguage.googleapis.com/v1beta/models?key=" .. self.api_key },
on_exit = function(job)
local parsed_response = utils.parse_raw_response(job:result())
self:process_onexit(parsed_response)
ids = {}
local success, decoded = pcall(vim.json.decode, parsed_response)
if success and decoded.models then
for _, item in ipairs(decoded.models) do
table.insert(ids, string.sub(item.name, 8))
end
end
end,
})
job:start()
job:wait()
end
return ids
end

return Gemini

0 comments on commit be975ee

Please sign in to comment.