Robitx / gp.nvim

Gp.nvim (GPT prompt) Neovim AI plugin: ChatGPT sessions & Instructable text/code operations & Speech to text [OpenAI, Ollama, Anthropic, ..]
MIT License
766 stars 66 forks source link

No output: response sequence happens but output is empty #31

Closed fnune closed 11 months ago

fnune commented 11 months ago

https://github.com/Robitx/gp.nvim/assets/16181067/dc4004bb-c225-4b13-b1ec-194289187915

I have set up my OpenAI API key and double-checked that it's correct. gp.nvim shows me no errors and I couldn't find log files from it in ~/.local/{share,state}/nvim.

Here's my config:

  {
    "robitx/gp.nvim",
    tag = "v1.3.8",
    config = function()
      require("gp").setup()
    end,
  },

(using Lazy).

Have I done something wrong?

Robitx commented 11 months ago

@fnune Hey, what do :checkhealth gp and :GpInspectPlugin (ideally run after :GpChatRespond) show?

fnune commented 11 months ago

:checkhealth gp:

gp.nvim checks ~
- OK require('gp') succeeded
- OK require('gp').setup() has been called
- OK config.openai_api_key is set
- OK curl is installed
- OK grep is installed
- OK ln is installed
- WARNING sox is not installed

sox is optional so I didn't add it.

Output of :GpInspectPlugin (:warning: to others doing this: this includes your OpenAI API key):


Plugin structure:
{
  Prompt = <function 1>,
  Target = {
    append = 1,
    enew = <function 2>,
    popup = 3,
    prepend = 2,
    rewrite = 0
  },
  Whisper = <function 3>,
  _H = {
    autocmd = <function 4>,
    create_popup = <function 5>,
    cursor_to_line = <function 6>,
    delete_buffer = <function 7>,
    feedkeys = <function 8>,
    get_buffer = <function 9>,
    get_filetype = <function 10>,
    grep_directory = <function 11>,
    last_content_line = <function 12>,
    once = <function 13>,
    process = <function 14>,
    set_keymap = <function 15>,
    template_render = <function 16>,
    template_replace = <function 17>
  },
  _Name = "Gp (GPT prompt)",
  _chat_popup = {},
  _chat_popup_close = <function 18>,
  _first_line = -1,
  _last_line = -1,
  _payload = {
    messages = { {
        content = "You are a general AI assistant.",
        role = "system"
      }, {
        content = "Hi there!",
        role = "user"
      }, {
        content = "",
        role = "assistant"
      }, {
        content = "Summarize the topic of our conversation above in two or three words. Respond only with those words.",
        role = "user"
      } },
    model = "gpt-3.5-turbo-16k",
    stream = true
  },
  _response = "",
  _setup_called = true,
  call_hook = <function 19>,
  chat_template = "# topic: ?\n\n- model: %s\n- file: %s\n- role: %s\n\nWrite your queries after %s. Use `%s` or :%sChatRespond to generate a response.\nChats are saved automatically. To delete this chat, use `%s`
 or :%sChatDelete.\nBe cautious of very long chats. Start a fresh chat by using `%s` or :%sChatNew.\n\n---\n\n%s",
  cmd = {
    Append = <function 20>,
    ChatDelete = <function 21>,
    ChatFinder = <function 22>,
    ChatNew = <function 23>,
    ChatRespond = <function 24>,
    ChatToggle = <function 25>,
    Enew = <function 26>,
    Popup = <function 27>,
    Prepend = <function 28>,
    Rewrite = <function 29>,
    Stop = <function 30>,
    Whisper = <function 31>,
    WhisperAppend = <function 32>,
    WhisperEnew = <function 33>,
    WhisperPopup = <function 34>,
    WhisperPrepend = <function 35>,
    WhisperRewrite = <function 36>
  },
  cmd_hooks = {
    Implement = <function 37>,
    InspectPlugin = <function 38>
  },
  config = {
    command_prompt_prefix = "🤖 ~ ",
    command_system_prompt = "You are an AI that strictly generates just the formated final code.",
    openai_api_endpoint = "https://api.openai.com/v1/chat/completions",
    openai_api_key = "<REDACTED-BUT-VALID>",
    template_command = "{{command}}",
    template_rewrite = "I have the following code from {{filename}}:\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}\n\nRespond just with the snippet of code that should be inserted.",
    template_selection = "I have the following code from {{filename}}:\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}",
    whisper_dir = "/tmp/gp_whisper",
    whisper_max_time = "05:00",
    whisper_silence = "1.75",
    whisper_tempo = "1.75"
  },
  create_handler = <function 39>,
  delete_chat = <function 40>,
  error = <function 41>,
  open_chat = <function 42>,
  prepare_commands = <function 43>,
  prepare_payload = <function 44>,
  query = <function 45>,
  repo_instructions = <function 46>,
  setup = <function 47>,
  template_render = <function 48>
}
Command params:
{
  args = "",
  bang = false,
  count = -1,
  fargs = {},
  line1 = 20,
  line2 = 20,
  mods = "",
  name = "GpInspectPlugin",
  range = 0,
  reg = "",
  smods = {
    browse = false,
    confirm = false,
    emsg_silent = false,
    hide = false,
    horizontal = false,
    keepalt = false,
    keepjumps = false,
    keepmarks = false,
    keeppatterns = false,
    lockmarks = false,
    noautocmd = false,
    noswapfile = false,
    sandbox = false,
    silent = false,
    split = "",
    tab = -1,
    unsilent = false,
    verbose = -1,
    vertical = false
  }
}
fnune commented 11 months ago

Huh, I added some logging:

  local on_exit = _H.once(vim.schedule_wrap(function(code, signal)
    stdout:read_stop()
    stderr:read_stop()
    stdout:close()
    stderr:close()
    if handle and not handle:is_closing() then
      handle:close()
    end
    vim.api.nvim_out_write(string.format("code: %s", code))
    vim.api.nvim_out_write(string.format("stdout_data: %s", stdout_data))
    vim.api.nvim_out_write(string.format("stderr_data: %s", stderr_data))
    if callback then
      callback(code, signal, stdout_data, stderr_data)
    end
    M._handle = nil
    M._pid = nil
  end))

And got this:

stderr_data: code: 0stdout_data: {
    "error": {
        "message": "You exceeded your current quota, please check your plan and billing details.",
        "type": "insufficient_quota",
        "param": null,
        "code": "insufficient_quota"
    }
}

That is strange, because I'm on the Plus plan.

fnune commented 11 months ago

My API key says "never used": image

fnune commented 11 months ago

I tried another API key just to test for minor blunders, but the key is correct.

fnune commented 11 months ago

Oh... this is so silly. ChatGPT and the OpenAI API are two different services!?

fnune commented 11 months ago

:grimacing: https://help.openai.com/en/articles/7039783-how-can-i-access-the-chatgpt-api

Sorry to have wasted your time... although surfacing this error message to the user would be awesome :smile:

Robitx commented 11 months ago

@fnune You haven't wasted my time, you've helped to save time to people who may hit the same pitfall in the future. :slightly_smiling_face:

I'll keep this open so I don't forget to propagate these errors.

EvanDaley commented 6 months ago

fnune

Which file did you add the logging in? I'm facing a similar issue, but I don't think its the token because the same token works when I use it in another similar plugin.

justrajdeep commented 5 months ago

@EvanDaley did you find the issue?