yetone / avante.nvim

Use your Neovim like using Cursor AI IDE!
Apache License 2.0
6.66k stars 240 forks source link

bug: bad argument #1 to 'getenv' (string expected, got table) #552

Closed UN-9BOT closed 1 month ago

UN-9BOT commented 1 month ago

Describe the bug

api_key_name = { "kwallet-query", "-f", "env", "-r", "vsegpt", "kdewallet" }, ... ["Authorization"] = "Bearer " .. os.getenv(opts.api_key_name),

Loaded session "~/code/python/dbs/customer-core"

E5108: Error executing lua: /home/vim9/.config/nvim/lua/plugins.lua:113: bad argument #1 to 'getenv' (string expected, got table)
stack traceback:
    [C]: in function 'getenv'
    /home/vim9/.config/nvim/lua/plugins.lua:113: in function 'parse_curl_args'
    ...m9/.local/share/nvim/lazy/avante.nvim/lua/avante/llm.lua:98: in function 'stream'
    ...local/share/nvim/lazy/avante.nvim/lua/avante/sidebar.lua:1273: in function 'handle_submit'
    ...local/share/nvim/lazy/avante.nvim/lua/avante/sidebar.lua:1327: in function <...local/share/nvim/lazy/avante.nvim/lua/avante/sidebar.lua:1317>

To reproduce

  {
    "yetone/avante.nvim",
    event = "VeryLazy",
    lazy = false,
    version = false, -- set this if you want to always pull the latest change
    config = function()
      require("avante").setup({
        ---@alias Provider "claude" | "openai" | "azure" | "gemini" | "cohere" | "copilot" | string
        provider = "deepseek", -- Recommend using Claude
        vendors = {
          ---@type AvanteProvider
          deepseek = {
            endpoint = "https://api.vsegpt.ru/v1/chat/completions",
            model = "deepseek/deepseek-coder",
            api_key_name = { "kwallet-query", "-f", "env", "-r", "vsegpt", "kdewallet" },
            parse_curl_args = function(opts, code_opts)
              return {
                url = opts.endpoint,
                headers = {
                  ["Accept"] = "application/json",
                  ["Content-Type"] = "application/json",
                  ["Authorization"] = "Bearer " .. os.getenv(opts.api_key_name),
                },
                body = {
                  model = opts.model,
                  messages = { -- you can make your own message, but this is very advanced
                    { role = "system", content = code_opts.system_prompt },
                    { role = "user", content = require("avante.providers.openai").get_user_message(code_opts) },
                  },
                  temperature = 0,
                  max_tokens = 4096,
                  stream = true, -- this will be set by default.
                },
              }
            end,
            parse_response_data = function(data_stream, event_state, opts)
              require("avante.providers").openai.parse_response(data_stream, event_state, opts)
            end,
          },
        },
      })
    end,
    opts = {},
    -- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
    build = "make",
    -- build = "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false" -- for windows
    dependencies = {
      "stevearc/dressing.nvim",
      "nvim-lua/plenary.nvim",
      "MunifTanjim/nui.nvim",
      --- The below dependencies are optional,
      "nvim-tree/nvim-web-devicons", -- or echasnovski/mini.icons
      "zbirenbaum/copilot.lua", -- for providers='copilot'
      {
        -- support for image pasting
        "HakonHarnes/img-clip.nvim",
        event = "VeryLazy",
        opts = {
          -- recommended settings
          default = {
            embed_image_as_base64 = false,
            prompt_for_file_name = false,
            drag_and_drop = {
              insert_mode = true,
            },
            -- required for Windows users
            use_absolute_path = true,
          },
        },
      },
      {
        -- Make sure to set this up properly if you have lazy=true
        "MeanderingProgrammer/render-markdown.nvim",
        opts = {
          file_types = { "markdown", "Avante" },
        },
        ft = { "markdown", "Avante" },
      },
    },
  },

Expected behavior

successful loading of env in header

Environment

NVIM v0.10.1 Build type: Release LuaJIT 2.1.1723675123

aarnphm commented 1 month ago

well in this case the api_key_name is a table right, you will have to run the command yourself.

os.getenv expects to get the envvar as a string, not table.