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

`api_key_cmd` did not return value when executed #287

Closed DennisTheMenace780 closed 7 months ago

DennisTheMenace780 commented 9 months ago

I'm receiving the above error when trying to use my OpenAI API key. I've provided a series of steps below that emulate what I am doing in my own setup. Note that I am using the free version of the OpenAI trial key, just for purposes of experimentation before I buy a GPT4 license.

1. Set up of the plugin:

    -- ChatGPT
    use({
        "jackMort/ChatGPT.nvim",
        config = function()
            require("chatgpt").setup({
                api_key_cmd = "gpg --decrypt ~/openai_trial_key.txt.gpg",
            })
        end,
        requires = {
            "MunifTanjim/nui.nvim",
            "nvim-lua/plenary.nvim",
            "nvim-telescope/telescope.nvim",
        },
    })

2. How I have created my trial key:

cd ~
echo "apikey12345" >> openai_trial_key.txt"
gpg --encrypt --recipient my_email@gmail.com openai_trial_key.txt
gpg --decrypt ~/openai_trial_key.txt.gpg // apikey12345

So everything seems to be set up properly, but there are two things I am thinking might be a problem here:

  1. I am using a trial API key
  2. the file name actually just needs to be named secret, but that seems silly to me.
stekern commented 9 months ago

A plugin update a couple of months ago made some changes to api_key_cmd. I believe tilde expansion doesn't work anymore (https://github.com/jackMort/ChatGPT.nvim/issues/220).

Have you tried something along the lines of api_key_cmd = "gpg --decrypt " .. vim.fn.expand("$HOME") .. "/openai_trial_key.txt.gpg" instead?

DennisTheMenace780 commented 9 months ago

Interesting, i'll try this out and see what comes of it!

di3italis commented 2 months ago

A plugin update a couple of months ago made some changes to api_key_cmd. I believe tilde expansion doesn't work anymore (#220).

Have you tried something along the lines of api_key_cmd = "gpg --decrypt " .. vim.fn.expand("$HOME") .. "/openai_trial_key.txt.gpg" instead?

Thank you, @stekern , after hours of trying to get this to work, you really came through!!

for anyone using lazy.lua, this works just dropped into your init.lua:

{
  "jackMort/ChatGPT.nvim",
    event = "VeryLazy",
    config = function()
      require("chatgpt").setup({
      api_key_cmd = "gpg --quiet --batch --decrypt " .. vim.fn.expand("$HOME") .. "/yourencryptedfile.txt.gpg",
      })
    end,
    dependencies = {
      "MunifTanjim/nui.nvim",
      "nvim-lua/plenary.nvim",
      "folke/trouble.nvim",
      "nvim-telescope/telescope.nvim"
    }
  },