ChatGPT.nvim icon indicating copy to clipboard operation
ChatGPT.nvim copied to clipboard

crash on function_call null

Open nbossard opened this issue 1 year ago • 1 comments

Here is the response from my openAI API :

{
  "id":"chatcmpl-c3113b31-5c09-4b50-a891-14a460fb6c0d",
  "created":1739033926,
  "model":"claude-3-5-sonnet-v2",
  "object":"chat.completion",
  "system_fingerprint":null,
  "choices":[
    {
      "finish_ reason":"stop",
      "index":0,
      "message":{
        "content":"Here's a simple code with three lines of ""hello world"" variations:\n\n\nHello, World!\nGreetings, Universe!\nHi there, Everyone !\n",
        "role":"assistant",
        "tool_calls":null,
        "function_call":null
      }
    }
  ],
  "usage":{
    "completion_tokens":41,
    "prompt_tokens":19,
    "total_tokens":60,
    "completion_tokens_details":null,
    "prompt_ tokens_details":{
      "audio_tokens":null,
      "cached_tokens":0
    },
    "cache_creation_input_tokens":0,
    "cache_read_input_tokens":0
  }
}

Note that "function_call":null

This will lead to following crash :

Press ENTER or type command to continue Error executing vim.schedule lua callback: .../.local/share/nvim/lazy/ChatGPT.nvim/lua/chatgpt/api.lua:170: attempt to index field 'function_call' (a userdata value) stack traceback: .../.local/share/nvim/lazy/ChatGPT.nvim/lua/chatgpt/api.lua:170: in function '' vim/_editor.lua: in function <vim/_editor.lua:0>

suggestion is to replace in file : ChatGPT.nvim/lua/chatgpt/api.lua

      if first_message.function_call
        message_response = vim.fn.json_decode(first_message.function_call.arguments)
      else

by

      if first_message.function_call and first_message.function_call ~= vim.NIL then
        message_response = vim.fn.json_decode(first_message.function_call.arguments)
      else

nbossard avatar Feb 08 '25 17:02 nbossard

And by the way, thanks for your useful plugin :-)

nbossard avatar Feb 08 '25 17:02 nbossard