Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Custom provider not recognized #1010

Open
thebrandonlucas opened this issue Dec 27, 2024 · 1 comment
Open

bug: Custom provider not recognized #1010

thebrandonlucas opened this issue Dec 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@thebrandonlucas
Copy link

Describe the bug

Hello,

I'm trying to use ppq.ai as a custom provider. I read through the Custom Provider wiki and created the config lua/plugins/avante.lua below (using lazy.nvim). The trouble is avante doesn't seem to recognize that I added a custom provider. When I do <leader>aa after starting nvim it just prompts me for ANTHROPIC_API_KEY and gives me the following error message:

Error executing vim.schedule lua callback: Vim:E5300: Expected a Number or a String
stack traceback:
	[C]: in function 'prompt_getprompt'
	...hare/nvim/lazy/avante.nvim/lua/avante/providers/init.lua:223: in function ''
	vim/_editor.lua: in function ''
	vim/_editor.lua: in function <vim/_editor.lua:0>

What am I missing here? Any help would be appreciated.

To reproduce

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
      {
        ---@alias Provider "claude" | "openai" | "azure" | "gemini" | "cohere" | "copilot" | string
        provider = "ppq",
        vendors = {
          ---@type AvanteProvider
          ["ppq"] = {
            endpoint = "https://api.ppq.ai",
            model = "claude-3.5-sonnet",
            api_key_name = "PPQ_API_KEY",
            parse_curl_args = function(opts, code_opts)
              return {
                url = opts.endpoint .. "/chat/completions",
                headers = {
                  ["Content-Type"] = "application/json",
                  ["Authorization"] = "Bearer " .. os.getenv(opts.api_key_name),
                },
                body = {
                  model = opts.model,
                  messages = require("avante.providers").copilot.parse_messages(code_opts), -- you can make your own message, but this is very advanced
                  max_tokens = 2048,
                  stream = true,
                },
              }
            end,
            parse_response_data = function(data_stream, event_state, opts)
              require("avante.providers").openai.parse_response(data_stream, event_state, opts)
            end,
          },
          dependencies = {
            "stevearc/dressing.nvim",
            "nvim-lua/plenary.nvim",
            "MunifTanjim/nui.nvim",
            --- The below dependencies are optional,
            "hrsh7th/nvim-cmp", -- autocompletion for avante commands and mentions
            "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

No response

Installation method

Use lazy.nvim:

{
  "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
  },
  -- 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 = {
    "nvim-treesitter/nvim-treesitter",
    "stevearc/dressing.nvim",
    "nvim-lua/plenary.nvim",
    "MunifTanjim/nui.nvim",
  },
}

Environment

nvim -v:

NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1734355927
Run "nvim -V1 -v" for more info

uname -a:

Darwin ip-10-131-130-186.us-west-2.compute.internal 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000 arm64

Repro

No response

@thebrandonlucas thebrandonlucas added the bug Something isn't working label Dec 27, 2024
@esezen
Copy link

esezen commented Dec 29, 2024

I'm not sure if this is the root cause but nesting in your configuration is incorrect. Can you try this and see if it helps?

  • Remove dependencies from inside opts and move it to the same level as opts
  • Remove the nesting { from the line before you define the provider (aka. move it one level up)
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
        ---@alias Provider "claude" | "openai" | "azure" | "gemini" | "cohere" | "copilot" | string
        provider = "ppq",
        vendors = {
            ---@type AvanteProvider
            ["ppq"] = {
                endpoint = "https://api.ppq.ai",
                model = "claude-3.5-sonnet",
                api_key_name = "PPQ_API_KEY",
                parse_curl_args = function(opts, code_opts)
                    return {
                        url = opts.endpoint .. "/chat/completions",
                        headers = {
                            ["Content-Type"] = "application/json",
                            ["Authorization"] = "Bearer " .. os.getenv(opts.api_key_name),
                        },
                        body = {
                            model = opts.model,
                            messages = require("avante.providers").copilot.parse_messages(code_opts), -- you can make your own message, but this is very advanced
                            max_tokens = 2048,
                            stream = true,
                        },
                    }
                end,
                parse_response_data = function(data_stream, event_state, opts)
                    require("avante.providers").openai.parse_response(data_stream, event_state, opts)
                end,
            },
        },
    },
    dependencies = {
        "stevearc/dressing.nvim",
        "nvim-lua/plenary.nvim",
        "MunifTanjim/nui.nvim",
        --- The below dependencies are optional,
        "hrsh7th/nvim-cmp", -- autocompletion for avante commands and mentions
        "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" },
        },
    },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants