Robitx / gp.nvim

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

Gp: OpenAI query response is empty #118

Closed nitaicharan closed 2 months ago

nitaicharan commented 6 months ago

Hello guys, I'm finding an issue when I submit my question using GpChatNew. It was working like a charm but know it is outputting the following message:

Gp: OpenAI query response is empty: 
"{
    "error": {
        "message": "We could not parse the JSON body of your quest. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)",
        "type": "invalid_request_error",
        "param": null,
        "code": null
    }
}"

Following the GpInspectPlugin:

  _queries = {
    ["548ec979_c813_4989_993e_c272c99ae06a"] = {
      buf = 597,
      first_line = -1,
      handler = <function 29>,
      last_line = -1,
      on_exit = <function 30>,
      payload = {
        messages = <1>{ {
            content = "You are a general AI ...",
            role = "system"
          }, {
            content = "how can i test it?",
            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-1106",
        stream = true,
        temperature = 1.1,
        top_p = 1
      },
      raw_response = "{\n    \"error\": {\n        \"message\": \"We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)\",\n        \"type\": \"invalid_request_error\",\n        \"param\": null,\n        \"code\": null\n    }\n}\n",
      response = "",
      timestamp = 1710716802
    },
    ["574fc242_86d5_439a_8709_826e4ab7c05f"] = {
      first_line = -1,
      handler = <function 31>,
      last_line = -1,
      on_exit = <function 32>,
      payload = {
        messages = <table 1>,
        model = "gpt-3.5-turbo-16k",
        stream = true
      },
      raw_response = "{\n    \"error\": {\n        \"message\": \"We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)\",\n        \"type\": \"invalid_request_error\",\n        \"param\": null,\n        \"code\": null\n    }\n}\n",
      response = "",
      timestamp = 1710716802
    },
  },

Following checkhealth:

gp: require("gp.health").check()

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
- OK no deprecated config options
oflisback commented 4 months ago

For what it's worth: I ran into this error too, in my case it was because the string for openai_api_key provided via an external program contained a trailing newline.

koffeeking commented 4 months ago

I'm also having this issue, and I've double checked my api key. Could it have to do with an incompatibility with openai's move to project-based api keys?

gonzaloserrano commented 3 months ago

I made it work by:

nitaicharan commented 2 months ago

This issue does not seem to be related to the plugin. As a result, I will be closing this issue.

Robitx commented 2 months ago

Just adding to it in case someone hits the same issue, the latest version supports sensitive logging

    -- log file location 
    log_file = vim.fn.stdpath("log"):gsub("/$", "") .. "/gp.nvim.log", 
    -- write sensitive data to log file for debugging purposes (like api keys) 
    log_sensitive = false, 

when enabled, the :GpInspectLog will show log full curl commands run against providers, such as:

[2024-07-30.08-24-30.212] [284dedb7] DEBUG: [SENSITIVE DATA] vault get_secret openai_api_key:   "sk-..."
[2024-07-30.08-24-30.212] [284dedb7] DEBUG: [SENSITIVE DATA] run command: curl --no-buffer -s https://api.openai.com/v1/chat/completions -H Content-Type: application/json -d {"model":"gpt-4o","top_p":1,"temperature":1.1,"messages":[{"content":"You are a general AI assistant.\n\nThe user provided the additional info about how they would like you to respond:\n\n- If you're unsure don't guess and say you don't know instead.\n- Ask question if you need clarification to provide better answer.\n- Think deeply and carefully from first principles step by step.\n- Zoom out first to see the big picture and then zoom in to details.\n- Use Socratic method to improve your thinking and coding skills.\n- Don't elide any code from your output if the answer requires coding.\n- Take a deep breath; You've got this!","role":"system"},{"content":"Hello there.","role":"user"}],"stream":true} -H Authorization: Bearer sk-... -H api-key: sk-...
[2024-07-30.08-24-30.216] [284dedb7] DEBUG: [SENSITIVE DATA] curl command started with pid: 2636159
[2024-07-30.08-24-37.711] [284dedb7] DEBUG: [SENSITIVE DATA] vault get_secret openai_api_key:   "sk-..."
[2024-07-30.08-24-37.711] [284dedb7] DEBUG: [SENSITIVE DATA] run command: curl --no-buffer -s https://api.openai.com/v1/chat/completions -H Content-Type: application/json -d {"model":"gpt-4o","top_p":1,"temperature":1.1,"messages":[{"content":"You are a general AI assistant.\n\nThe user provided the additional info about how they would like you to respond:\n\n- If you're unsure don't guess and say you don't know instead.\n- Ask question if you need clarification to provide better answer.\n- Think deeply and carefully from first principles step by step.\n- Zoom out first to see the big picture and then zoom in to details.\n- Use Socratic method to improve your thinking and coding skills.\n- Don't elide any code from your output if the answer requires coding.\n- Take a deep breath; You've got this!","role":"system"},{"content":"Hello there.","role":"user"},{"content":"Hello! How can I assist you today? Is there something specific you're working on or something you'd like to know more about?","role":"assistant"},{"content":"Summarize the topic of our conversation above in two or three words. Respond only with those words.","role":"user"}],"stream":true} -H Authorization: Bearer sk-... -H api-key: sk-...

(Just be careful not posting your secret keys, I've redacted them manually in the example).