Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config api_key_cmd did not return a value when executed #355

Open
mvpopuk opened this issue Dec 25, 2023 · 4 comments
Open

Config api_key_cmd did not return a value when executed #355

mvpopuk opened this issue Dec 25, 2023 · 4 comments

Comments

@mvpopuk
Copy link

mvpopuk commented Dec 25, 2023

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
Copy link

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

@mvpopuk
Copy link
Author

mvpopuk commented Dec 29, 2023

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

@psteinroe
Copy link

psteinroe commented Dec 29, 2023

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
Copy link

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants