yetone / avante.nvim

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

bug: using gemini provider with GEMINI_API_KEY environment defaults to claude #577

Open k8s-1 opened 2 months ago

k8s-1 commented 2 months ago

Describe the bug

To reproduce

lazyvim config:

return {
  "yetone/avante.nvim",
  event = "VeryLazy",
  lazy = false,
  version = false, -- set this if you want to always pull the latest change
  opts = {
    -- add any opts here
  },
  provider = "gemini",
  behaviour = {
    auto_suggestions = false, -- Experimental stage
  },
  -- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
  build = "make",
  dependencies = {
    "stevearc/dressing.nvim",
    "nvim-lua/plenary.nvim",
    "MunifTanjim/nui.nvim",
    {
      -- 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

Environment

~  $ nvim -v
NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1725453128
Run "nvim -V1 -v" for more info
~  $ cat /etc/os-release
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
...
~  $ uname -m; uname -r
x86_64
6.10.8-arch1-1

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    {
      "yetone/avante.nvim",
       event = "VeryLazy",
       lazy = false,
       version = false, -- set this if you want to always pull the latest change
       opts = {
       -- add any opts here
       },
       provider = "gemini",
       behaviour = {
         auto_suggestions = false, -- Experimental stage
       },
       -- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
       build = "make",
       dependencies = {
         "stevearc/dressing.nvim",
         "nvim-lua/plenary.nvim",
         "MunifTanjim/nui.nvim",
         {
           -- Make sure to set this up properly if you have lazy=true
          'MeanderingProgrammer/render-markdown.nvim',
          opts = {
            file_types = { "markdown", "Avante" },
          },
          ft = { "markdown", "Avante" },
        },
      },
    }
  },
})
k8s-1 commented 2 months ago

Currently working around it by adding this to config:

  -- Custom hack to force gemini to load instead of claude
  -- 2024-09-13
  init = function()
    vim.api.nvim_create_autocmd("VimEnter", {
      callback = function()
        -- Ensure Avante.nvim has been loaded before switching providers
        if vim.fn.exists(":AvanteSwitchProvider") == 2 then
          vim.cmd("AvanteSwitchProvider gemini")
        end
      end,
    })
  end,
jeffcap1 commented 2 months ago

@k8s-1 I am using gemini as my LLM and was able to get it working with the following settings. I think you need to add a gemini section to your config and select the model to make it work.

gemini = {
    -- @see https://ai.google.dev/gemini-api/docs/models/gemini
    model = "gemini-1.5-pro-exp-0827",
    -- model = "gemini-1.5-flash",
    temperature = 0,
    max_tokens = 4096,
  },

This is my whole setup for Avante in case it helps.

local M = {
  "yetone/avante.nvim",
  event = "VeryLazy",
  lazy = false,
  version = false, -- set this if you want to always pull the latest change
  -- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
  build = "make",
  dependencies = {
    "stevearc/dressing.nvim",
    "nvim-lua/plenary.nvim",
    "MunifTanjim/nui.nvim",
    --- The below dependencies are optional,
    "echasnovski/mini.icons", -- or "nvim-tree/nvim-web-devicons"
    {
      -- 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" },
    },
  },
}

M.opts = {
  provider = "gemini", -- Recommend using Claude
  -- auto_suggestions_provider = "copilot", -- Since auto-suggestions are a high-frequency operation and therefore expensive, it is recommended to specify an inexpensive provider or even a free provider: copilot
  behaviour = {
    auto_suggestions = false, -- Experimental stage
    auto_set_highlight_group = true,
    auto_set_keymaps = true,
    auto_apply_diff_after_generation = false,
    support_paste_from_clipboard = false,
  },
  gemini = {
    -- @see https://ai.google.dev/gemini-api/docs/models/gemini
    model = "gemini-1.5-pro-exp-0827",
    -- model = "gemini-1.5-flash",
    temperature = 0,
    max_tokens = 4096,
  },
}

return M