Skip to content

Commit

Permalink
feat: specific provider for auto-suggestions (yetone#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone authored Sep 12, 2024
1 parent 8184275 commit 0642905
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ _See [config.lua#L9](./lua/avante/config.lua) for the full config_
{
---@alias Provider "claude" | "openai" | "azure" | "gemini" | "cohere" | "copilot" | string
provider = "claude", -- Recommend using Claude
auto_suggestions_provider = "claude", -- 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
claude = {
endpoint = "https://api.anthropic.com",
model = "claude-3-5-sonnet-20240620",
Expand Down
1 change: 1 addition & 0 deletions lua/avante/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ M.defaults = {
debug = false,
---@alias Provider "claude" | "openai" | "azure" | "gemini" | "cohere" | "copilot" | [string]
provider = "claude", -- Only recommend using Claude
auto_suggestions_provider = "claude",
---@alias Tokenizer "tiktoken" | "hf"
-- Used for counting tokens and encoding text.
-- By default, we will use tiktoken.
Expand Down
3 changes: 2 additions & 1 deletion lua/avante/llm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ local group = api.nvim_create_augroup("avante_llm", { clear = true })
---@field bufnr integer
---@field instructions string
---@field mode LlmMode
---@field provider AvanteProviderFunctor | nil
---@field on_chunk AvanteChunkParser
---@field on_complete AvanteCompleteParser

---@param opts StreamOptions
M.stream = function(opts)
local mode = opts.mode or "planning"
---@type AvanteProviderFunctor
local Provider = P[Config.provider]
local Provider = opts.provider or P[Config.provider]

-- Check if the instructions contains an image path
local image_paths = {}
Expand Down
7 changes: 5 additions & 2 deletions lua/avante/suggestion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local Utils = require("avante.utils")
local Llm = require("avante.llm")
local Highlights = require("avante.highlights")
local Config = require("avante.config")
local Provider = require("avante.providers")
local Providers = require("avante.providers")
local api = vim.api
local fn = vim.fn

Expand Down Expand Up @@ -37,7 +37,7 @@ function Suggestion:new(id)
instance._contexts = {}
if Config.behaviour.auto_suggestions then
if not vim.g.avante_login or vim.g.avante_login == false then
api.nvim_exec_autocmds("User", { pattern = Provider.env.REQUEST_LOGIN_PATTERN })
api.nvim_exec_autocmds("User", { pattern = Providers.env.REQUEST_LOGIN_PATTERN })
vim.g.avante_login = true
end
instance:setup_autocmds()
Expand Down Expand Up @@ -65,7 +65,10 @@ function Suggestion:suggest()

local full_response = ""

local provider = Providers[Config.auto_suggestions_provider]

Llm.stream({
provider = provider,
bufnr = bufnr,
ask = true,
file_content = code_content,
Expand Down

0 comments on commit 0642905

Please sign in to comment.