jackMort / ChatGPT.nvim

ChatGPT Neovim Plugin: Effortless Natural Language Generation with OpenAI's ChatGPT API
Apache License 2.0
3.57k stars 307 forks source link

attempt to concatenate field 'OPENAI_API_KEY' (a nil value) #299

Closed PMassicotte closed 7 months ago

PMassicotte commented 9 months ago

Looks like the last commit (aa8a969) is breaking something.

I am getting this error:

.../.local/share/nvim/lazy/ChatGPT.nvim/lua/chatgpt/api.lua:267: attempt to concatenate field 'OPENAI_API_KEY' (a nil value)  

https://github.com/jackMort/ChatGPT.nvim/blob/aa8a96901662199857e93dd9a93e262e0d36be4c/lua/chatgpt/api.lua#L267

FWIW, here is my config:

  config = function()
    local home = vim.fn.expand("$HOME")
    require("chatgpt").setup({
      api_key_cmd = "gpg --decrypt " .. home .. "/openai_api_key.txt.gpg"
    })
  end,
comiluv commented 9 months ago

Same here. This plugin is the single most fragile plugin among all neovim plugins because it breaks after every update 😆 Do people ever test their stuff before plugging it in the PR?

h0pes commented 9 months ago

Same error using bw (which is the Bitwarden command line client) in plugin custom config like this: api_key_cmd = bw get password <uniqueid> results in attempt to concatenate filed OPENAI_API_KEY (a nil value).

uniqueid is an alphanumeric string without spaces

mhuggins7278 commented 9 months ago

same here using builtin mac keychain security find-generic-password -s NVIM_CHAT_GPT_TOKEN -w

r3k2 commented 9 months ago

same here using gopass(compatible with pass)

return {
  "jackMort/ChatGPT.nvim",
  event = "VeryLazy",
  config = function()
    require("chatgpt").setup({
      api_key_cmd = "gopass show -o -f chatgpt/apikey",
    })
  end,
  dependencies = {
    "MunifTanjim/nui.nvim",
    "nvim-lua/plenary.nvim",
    "nvim-telescope/telescope.nvim",
  },
  keys = {
    { "<leader>Cc", "<cmd>ChatGPT<cr>", desc = "ChatGPT" },
  },
}
phaberest commented 9 months ago

I can confirm that https://github.com/singular0/ChatGPT.nvim/commit/3d31eacf98b00cc3fd944ef5526be6d738515649 fixed the issue

A PR has been submitted under https://github.com/jackMort/ChatGPT.nvim/pull/301

jackyu1996 commented 9 months ago

Sorry for not testing enough on the api_key_cmd option, I will try to find a workaround and test relevant options in nvim config before submitting another patch. Sorry for the inconveniences again.

Edits: