Skip to content

Commit

Permalink
fix: rm obsolete api key validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Robitx committed Jul 29, 2024
1 parent 205600d commit 352b0c3
Showing 1 changed file with 6 additions and 36 deletions.
42 changes: 6 additions & 36 deletions lua/gp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,6 @@ M.setup = function(opts)
M.vault.resolve_secret("openai_api_key", image_opts.openai_api_key)
end

-- TODO: obsolete
M.valid_api_key = function()
local api_key = M.config.openai_api_key

if type(api_key) == "table" then
M.logger.error("openai_api_key is still an unresolved command: " .. vim.inspect(api_key))
return false
end

if api_key and string.match(api_key, "%S") then
return true
end

M.logger.error("config.openai_api_key is not set: " .. vim.inspect(api_key) .. " run :checkhealth gp")
return false
end

M.refresh_state = function()
local state_file = M.config.state_dir .. "/state.json"

Expand Down Expand Up @@ -507,10 +490,6 @@ M.query = function(buf, provider, payload, handler, on_exit, callback)
return
end

if not M.valid_api_key() then
return
end

local qid = M.helpers.uuid()
M.tasker.set_query(qid, {
timestamp = os.time(),
Expand Down Expand Up @@ -1392,10 +1371,6 @@ M.chat_respond = function(params)
local buf = vim.api.nvim_get_current_buf()
local win = vim.api.nvim_get_current_win()

if not M.valid_api_key() then
return
end

if M.tasker.is_busy(buf) then
return
end
Expand Down Expand Up @@ -2448,6 +2423,12 @@ M.Whisper = function(language, callback)
return
end

local bearer = M.vault.get("openai_api_key")
if not bearer then
M.logger.error("OpenAI API key not found")
return
end

local rec_file = M.config.whisper_dir .. "/rec.wav"
local rec_options = {
sox = {
Expand Down Expand Up @@ -2496,10 +2477,6 @@ M.Whisper = function(language, callback)
},
}

if not M.valid_api_key() then
return
end

local gid = M.helpers.create_augroup("GpWhisper", { clear = true })

-- create popup
Expand Down Expand Up @@ -2572,13 +2549,6 @@ M.Whisper = function(language, callback)
local curl_params = M.config.curl_params or {}
local curl = "curl" .. " " .. table.concat(curl_params, " ")

local bearer = M.vault.get("openai_api_key")

if not bearer then
M.logger.error("OpenAI API key not found")
return
end

-- transcribe the recording
local transcribe = function()
local cmd = "cd "
Expand Down

0 comments on commit 352b0c3

Please sign in to comment.