jackMort / ChatGPT.nvim

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

Config `api_key_cmd` did not return a value when executed #355

Open mvpopuk opened 6 months ago

mvpopuk commented 6 months ago

I love this plugin but I can't make it work.

I use Plug to install it:

    Plug 'jackMort/ChatGPT.nvim'
    Plug 'MunifTanjim/nui.nvim'
    Plug 'nvim-lua/plenary.nvim'
    Plug 'nvim-telescope/telescope.nvim'

I have a secret.txt.gpg in my home directory that was encrypted with the following command:

gpg --encrypt --recipient [my email] secret.txt

The contents of the secret.txt are $OPENAI_API_KEY=xxxxxxxxxxxxxxxx

And I try to get the OPENAI_API_KEY like so:

local home = vim.fn.expand("$HOME")
require("chatgpt").setup({
    api_key_cmd = "gpg --decrypt " .. home .. "/secret.txt.gpg"
})

The error I'm getting is Config api_key_cmd did not return a value when executed

What am I doing wrong here ?

Thanks!

serranomorante commented 6 months ago

secret.txt should only have the plain openai api key. Try again after removing $OPENAI_API_KEY= from your secret.txt file

mvpopuk commented 6 months ago

I have tried that but I got the same error message.

psteinroe commented 6 months ago

I also have the same error. I am using the security bin from macOS to get the key from keychain.

here is how I install the plugin using packer.

  use({
      "jackMort/ChatGPT.nvim",
      config = function()
          require("chatgpt").setup({
              api_key_cmd = "security find-generic-password -w -s 'openai' -a 'neovim'"
          })
      end,
      requires = {
          "MunifTanjim/nui.nvim",
          "nvim-lua/plenary.nvim",
          "nvim-telescope/telescope.nvim"
      }
  })

The command

security find-generic-password -w -s 'openai' -a 'neovim'

prints the key in a fresh session without any further interaction required.

channingwalton commented 4 months ago

@psteinroe as a workaround, I set OPENAI_API_KEY in my zshrc:

export OPENAI_API_KEY=$(security find-generic-password -w -s openai)