jackMort / ChatGPT.nvim

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

curl: (3) URL rejected: Bad hostname #314

Closed teto closed 10 months ago

teto commented 11 months ago

When updating to master 9f8062c7c40ec082c49f10e20818333a972b8063 I get curl: (3) URL rejected: Bad hostname with the following

 { 'jackMort/ChatGPT.nvim',
   -- due to https://github.com/jackMort/ChatGPT.nvim/issues/265
    -- commit = "24bcca7",   IF I PIN THIS ChatGPT.nvim works fine
    config = function()
     -- passing OPENAI_API_KEY in environment for this to work
     -- huge setup at https://github.com/jackMort/ChatGPT.nvim
      require("chatgpt").setup({
        api_key_cmd = "pass show chat.openai.com",
        api_host_cmd = "echo -n 'api.openai.com'"
       })
    end,
 },

One of my issues is that I dont see the host used, is there some logging I could enable ? might be worth adding some checkhealth command to help debug https://neovim.io/doc/user/pi_health.html#health-commands

sg1fan commented 10 months ago

I had this problem too. You need to remove the quotes around 'api.openai.com'; otherwise, the resulting urls will look something like https://'api.openai.com'/v1/completions. If you want to see what exactly went wrong, you could insert a statement such as logger.warn(Api.COMPLETIONS_URL) inside the loadApiHost callback inside api.lua. It isn't pretty, but it helped me solve my problem.

teto commented 10 months ago

thanks that fixed it.

insv23 commented 2 months ago

Got same error message. After some trying, I realized that api_host_cmd is not working as expected. For example, api_host_cmd = "echo -n 'api.notopenai.com'", it always returns curl: (3) URL rejected: Bad hostname. But if I run export OPENAI_API_HOST=api.notopenai.ai in terminal and not use api_host_cmd, it works fine. It's weird, did I miss some of the relevant descriptions in the README?