2024-08-17 15:14:30 +08:00
---NOTE: user will be merged with defaults and
---we add a default var_accessor for this table to config values.
2024-08-28 14:43:14 -04:00
2025-02-06 20:10:55 +08:00
---@alias WebSearchEngineProviderResponseBodyFormatter fun(body: table): (string, string?)
2024-09-03 05:12:07 -04:00
local Utils = require ( " avante.utils " )
2024-08-28 14:43:14 -04:00
2025-02-11 13:49:00 +08:00
---@class avante.file_selector.IParams
---@field public title string
---@field public filepaths string[]
---@field public handler fun(filepaths: string[]|nil): nil
2024-08-17 15:14:30 +08:00
---@class avante.CoreConfig: avante.Config
2024-08-15 17:45:46 +08:00
local M = { }
2024-08-17 15:14:30 +08:00
---@class avante.Config
2025-01-05 18:27:23 +08:00
M._defaults = {
2024-08-19 05:40:57 -04:00
debug = false ,
2025-02-11 02:01:49 +08:00
---@alias Provider "claude" | "openai" | "azure" | "gemini" | "vertex" | "cohere" | "copilot" | string
2024-08-28 20:51:20 +08:00
provider = " claude " , -- Only recommend using Claude
2025-01-23 21:34:56 -06:00
-- WARNING: Since auto-suggestions are a high-frequency operation and therefore expensive,
-- currently designating it as `copilot` provider is dangerous because: https://github.com/yetone/avante.nvim/issues/1048
-- Of course, you can reduce the request frequency by increasing `suggestion.debounce`.
2024-09-12 14:23:00 +08:00
auto_suggestions_provider = " claude " ,
2024-08-30 19:07:52 -04:00
---@alias Tokenizer "tiktoken" | "hf"
-- Used for counting tokens and encoding text.
-- By default, we will use tiktoken.
-- For most providers that we support we will determine this automatically.
-- If you wish to use a given implementation, then you can override it here.
tokenizer = " tiktoken " ,
2025-02-05 22:39:54 +08:00
web_search_engine = {
provider = " tavily " ,
2025-02-06 20:10:55 +08:00
providers = {
tavily = {
api_key_name = " TAVILY_API_KEY " ,
extra_request_body = {
include_answer = " basic " ,
} ,
---@type WebSearchEngineProviderResponseBodyFormatter
2025-02-17 04:53:15 +00:00
format_response_body = function ( body ) return body.answer , nil end ,
2025-02-06 20:10:55 +08:00
} ,
serpapi = {
api_key_name = " SERPAPI_API_KEY " ,
extra_request_body = {
engine = " google " ,
google_domain = " google.com " ,
} ,
---@type WebSearchEngineProviderResponseBodyFormatter
format_response_body = function ( body )
if body.answer_box ~= nil then return body.answer_box . result , nil end
if body.organic_results ~= nil then
local jsn = vim
. iter ( body.organic_results )
: map (
function ( result )
return {
title = result.title ,
link = result.link ,
snippet = result.snippet ,
2025-02-17 00:36:00 +08:00
date = result.date ,
2025-02-06 20:10:55 +08:00
}
end
)
2025-02-17 00:36:00 +08:00
: take ( 10 )
: totable ( )
return vim.json . encode ( jsn ) , nil
end
return " " , nil
end ,
} ,
searchapi = {
api_key_name = " SEARCHAPI_API_KEY " ,
extra_request_body = {
engine = " google " ,
} ,
---@type WebSearchEngineProviderResponseBodyFormatter
format_response_body = function ( body )
if body.answer_box ~= nil then return body.answer_box . result , nil end
if body.organic_results ~= nil then
local jsn = vim
. iter ( body.organic_results )
: map (
function ( result )
return {
title = result.title ,
link = result.link ,
snippet = result.snippet ,
date = result.date ,
}
end
)
: take ( 10 )
2025-02-10 00:21:55 -05:00
: totable ( )
return vim.json . encode ( jsn ) , nil
end
return " " , nil
end ,
} ,
google = {
api_key_name = " GOOGLE_SEARCH_API_KEY " ,
engine_id_name = " GOOGLE_SEARCH_ENGINE_ID " ,
extra_request_body = { } ,
---@type WebSearchEngineProviderResponseBodyFormatter
format_response_body = function ( body )
if body.items ~= nil then
local jsn = vim
. iter ( body.items )
2025-02-06 20:10:55 +08:00
: map (
function ( result )
return {
title = result.title ,
link = result.link ,
snippet = result.snippet ,
}
end
)
2025-02-17 00:36:00 +08:00
: take ( 10 )
2025-02-06 20:10:55 +08:00
: totable ( )
return vim.json . encode ( jsn ) , nil
end
return " " , nil
end ,
} ,
2025-02-05 22:39:54 +08:00
} ,
} ,
2024-08-19 08:35:36 -04:00
---@type AvanteSupportedProvider
2024-08-15 17:45:46 +08:00
openai = {
2024-08-25 00:32:16 +08:00
endpoint = " https://api.openai.com/v1 " ,
2024-08-15 17:45:46 +08:00
model = " gpt-4o " ,
2024-08-24 17:52:38 -04:00
timeout = 30000 , -- Timeout in milliseconds
2024-08-15 17:45:46 +08:00
temperature = 0 ,
max_tokens = 4096 ,
} ,
2024-08-29 23:36:39 -04:00
---@type AvanteSupportedProvider
copilot = {
endpoint = " https://api.githubcopilot.com " ,
2024-11-19 06:25:17 +08:00
model = " gpt-4o-2024-08-06 " ,
2024-08-29 23:36:39 -04:00
proxy = nil , -- [protocol://]host[:port] Use this proxy
allow_insecure = false , -- Allow insecure server connections
timeout = 30000 , -- Timeout in milliseconds
temperature = 0 ,
max_tokens = 4096 ,
} ,
2024-08-19 08:35:36 -04:00
---@type AvanteAzureProvider
2024-08-15 17:45:46 +08:00
azure = {
endpoint = " " , -- example: "https://<your-resource-name>.openai.azure.com"
deployment = " " , -- Azure deployment name (e.g., "gpt-4o", "my-gpt-4o-deployment")
api_version = " 2024-06-01 " ,
2024-08-24 17:52:38 -04:00
timeout = 30000 , -- Timeout in milliseconds
2024-08-15 17:45:46 +08:00
temperature = 0 ,
max_tokens = 4096 ,
} ,
2024-08-19 08:35:36 -04:00
---@type AvanteSupportedProvider
2024-08-15 17:45:46 +08:00
claude = {
endpoint = " https://api.anthropic.com " ,
2024-10-22 14:05:52 -04:00
model = " claude-3-5-sonnet-20241022 " ,
2024-08-24 17:52:38 -04:00
timeout = 30000 , -- Timeout in milliseconds
2024-08-15 17:45:46 +08:00
temperature = 0 ,
2024-08-30 18:53:49 +08:00
max_tokens = 8000 ,
2024-08-15 17:45:46 +08:00
} ,
2024-08-24 17:52:38 -04:00
---@type AvanteSupportedProvider
2025-02-03 23:33:25 +09:00
bedrock = {
model = " anthropic.claude-3-5-sonnet-20240620-v1:0 " ,
timeout = 30000 , -- Timeout in milliseconds
temperature = 0 ,
max_tokens = 8000 ,
} ,
---@type AvanteSupportedProvider
2024-08-21 17:52:25 +01:00
gemini = {
2024-08-22 01:48:40 -04:00
endpoint = " https://generativelanguage.googleapis.com/v1beta/models " ,
2024-08-27 18:05:47 -04:00
model = " gemini-1.5-flash-latest " ,
2024-08-24 17:52:38 -04:00
timeout = 30000 , -- Timeout in milliseconds
2024-08-23 09:36:40 -04:00
temperature = 0 ,
max_tokens = 4096 ,
2024-11-14 16:34:58 +00:00
} ,
---@type AvanteSupportedProvider
vertex = {
endpoint = " https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models " ,
model = " gemini-1.5-flash-latest " ,
timeout = 30000 , -- Timeout in milliseconds
temperature = 0 ,
max_tokens = 4096 ,
2024-08-23 09:36:40 -04:00
} ,
2024-08-25 14:26:42 +08:00
---@type AvanteSupportedProvider
2024-08-23 09:36:40 -04:00
cohere = {
2024-10-27 02:17:35 -04:00
endpoint = " https://api.cohere.com/v2 " ,
2024-08-30 13:39:36 -04:00
model = " command-r-plus-08-2024 " ,
2024-08-24 17:52:38 -04:00
timeout = 30000 , -- Timeout in milliseconds
2024-08-23 09:36:40 -04:00
temperature = 0 ,
2024-08-30 13:39:36 -04:00
max_tokens = 4096 ,
2024-08-21 17:52:25 +01:00
} ,
2024-08-19 05:40:57 -04:00
---To add support for custom provider, follow the format below
2024-10-30 19:43:57 +09:00
---See https://github.com/yetone/avante.nvim/wiki#custom-providers for more details
2024-08-19 08:35:36 -04:00
---@type {[string]: AvanteProvider}
2024-11-04 20:54:33 -05:00
vendors = {
---@type AvanteSupportedProvider
[ " claude-haiku " ] = {
2024-11-16 02:09:14 +08:00
__inherited_from = " claude " ,
2024-11-04 20:54:33 -05:00
model = " claude-3-5-haiku-20241022 " ,
timeout = 30000 , -- Timeout in milliseconds
temperature = 0 ,
max_tokens = 8000 ,
} ,
2025-02-13 11:12:02 +08:00
2025-02-12 22:38:55 +08:00
---@type AvanteSupportedProvider
2024-11-04 20:54:33 -05:00
[ " claude-opus " ] = {
2024-11-16 02:09:14 +08:00
__inherited_from = " claude " ,
2024-11-04 20:54:33 -05:00
model = " claude-3-opus-20240229 " ,
timeout = 30000 , -- Timeout in milliseconds
temperature = 0 ,
max_tokens = 8000 ,
} ,
} ,
2024-11-17 00:54:01 -07:00
---Specify the special dual_boost mode
---1. enabled: Whether to enable dual_boost mode. Default to false.
---2. first_provider: The first provider to generate response. Default to "openai".
---3. second_provider: The second provider to generate response. Default to "claude".
---4. prompt: The prompt to generate response based on the two reference outputs.
---5. timeout: Timeout in milliseconds. Default to 60000.
2024-11-17 11:56:20 -07:00
---How it works:
2024-11-17 00:54:01 -07:00
--- When dual_boost is enabled, avante will generate two responses from the first_provider and second_provider respectively. Then use the response from the first_provider as provider1_output and the response from the second_provider as provider2_output. Finally, avante will generate a response based on the prompt and the two reference outputs, with the default Provider as normal.
---Note: This is an experimental feature and may not work as expected.
dual_boost = {
enabled = false ,
first_provider = " openai " ,
second_provider = " claude " ,
prompt = " Based on the two reference outputs below, generate a response that incorporates elements from both but reflects your own judgment and unique perspective. Do not provide any explanation, just give the response directly. Reference Output 1: [{{provider1_output}}], Reference Output 2: [{{provider2_output}}] " ,
timeout = 60000 , -- Timeout in milliseconds
} ,
2024-08-19 05:40:57 -04:00
---Specify the behaviour of avante.nvim
2025-01-21 00:04:48 +08:00
---1. auto_focus_sidebar : Whether to automatically focus the sidebar when opening avante.nvim. Default to true.
---2. auto_suggestions = false, -- Whether to enable auto suggestions. Default to false.
---3. auto_apply_diff_after_generation: Whether to automatically apply diff after LLM response.
2024-08-19 05:40:57 -04:00
--- This would simulate similar behaviour to cursor. Default to false.
2025-01-21 00:04:48 +08:00
---4. auto_set_keymaps : Whether to automatically set the keymap for the current line. Default to true.
2024-08-29 01:09:26 -04:00
--- Note that avante will safely set these keymap. See https://github.com/yetone/avante.nvim/wiki#keymaps-and-api-i-guess for more details.
2025-01-21 00:04:48 +08:00
---5. auto_set_highlight_group : Whether to automatically set the highlight group for the current line. Default to true.
2025-02-04 16:06:56 +07:00
---6. jump_result_buffer_on_finish = false, -- Whether to automatically jump to the result buffer after generation
2025-01-21 00:04:48 +08:00
---7. support_paste_from_clipboard : Whether to support pasting image from clipboard. This will be determined automatically based whether img-clip is available or not.
---8. minimize_diff : Whether to remove unchanged lines when applying a code block
2025-02-02 01:27:12 +08:00
---9. enable_token_counting : Whether to enable token counting. Default to true.
2024-08-17 16:31:24 -04:00
behaviour = {
2025-01-08 18:40:19 +01:00
auto_focus_sidebar = true ,
2024-09-03 14:03:59 +08:00
auto_suggestions = false , -- Experimental stage
2025-01-11 15:00:19 +00:00
auto_suggestions_respect_ignore = false ,
2024-08-24 20:15:45 -04:00
auto_set_highlight_group = true ,
2024-08-29 01:09:26 -04:00
auto_set_keymaps = true ,
2024-08-19 05:40:57 -04:00
auto_apply_diff_after_generation = false ,
2025-01-21 00:04:48 +08:00
jump_result_buffer_on_finish = false ,
2024-08-27 06:57:29 -04:00
support_paste_from_clipboard = false ,
2024-11-21 08:16:32 +00:00
minimize_diff = true ,
2025-02-02 01:27:12 +08:00
enable_token_counting = true ,
2024-08-17 16:31:24 -04:00
} ,
2024-08-25 03:12:53 -04:00
history = {
2024-11-04 16:20:28 +08:00
max_tokens = 4096 ,
2024-09-03 05:12:07 -04:00
storage_path = vim.fn . stdpath ( " state " ) .. " /avante " ,
2024-08-28 11:52:12 -04:00
paste = {
extension = " png " ,
filename = " pasted-%Y-%m-%d-%H-%M-%S " ,
} ,
2024-08-25 03:12:53 -04:00
} ,
2024-08-15 17:45:46 +08:00
highlights = {
2024-08-17 14:14:02 -04:00
---@type AvanteConflictHighlights
2024-08-15 17:45:46 +08:00
diff = {
2024-08-19 05:40:57 -04:00
current = " DiffText " ,
incoming = " DiffAdd " ,
2024-08-15 17:45:46 +08:00
} ,
} ,
mappings = {
2024-08-28 23:56:00 -04:00
---@class AvanteConflictMappings
2024-08-15 17:45:46 +08:00
diff = {
ours = " co " ,
theirs = " ct " ,
2024-08-29 20:32:00 +08:00
all_theirs = " ca " ,
2024-08-15 17:45:46 +08:00
both = " cb " ,
2024-08-28 23:25:45 -07:00
cursor = " cc " ,
2024-08-15 17:45:46 +08:00
next = " ]x " ,
prev = " [x " ,
} ,
2024-09-03 14:03:59 +08:00
suggestion = {
accept = " <M-l> " ,
next = " <M-]> " ,
prev = " <M-[> " ,
dismiss = " <C-]> " ,
} ,
2024-08-17 10:39:59 -04:00
jump = {
next = " ]] " ,
prev = " [[ " ,
} ,
2024-08-25 00:51:59 +08:00
submit = {
normal = " <CR> " ,
insert = " <C-s> " ,
} ,
2024-08-28 23:56:00 -04:00
-- NOTE: The following will be safely set by avante.nvim
ask = " <leader>aa " ,
edit = " <leader>ae " ,
refresh = " <leader>ar " ,
2024-10-15 10:24:48 +07:00
focus = " <leader>af " ,
2024-08-25 00:16:25 -04:00
toggle = {
2024-09-02 12:22:48 -04:00
default = " <leader>at " ,
2024-08-25 00:16:25 -04:00
debug = " <leader>ad " ,
hint = " <leader>ah " ,
2024-09-06 01:09:02 -04:00
suggestion = " <leader>as " ,
2024-10-20 22:45:53 -04:00
repomap = " <leader>aR " ,
2024-08-25 00:16:25 -04:00
} ,
2024-09-14 20:42:55 +02:00
sidebar = {
2024-10-12 03:41:08 -07:00
apply_all = " A " ,
apply_cursor = " a " ,
2024-09-14 20:42:55 +02:00
switch_windows = " <Tab> " ,
reverse_switch_windows = " <S-Tab> " ,
2024-12-12 03:29:10 +10:00
remove_file = " d " ,
add_file = " @ " ,
2025-02-02 00:48:11 +10:00
close = { " <Esc> " , " q " } ,
2024-09-14 20:42:55 +02:00
} ,
2024-12-13 06:57:42 -08:00
files = {
add_current = " <leader>ac " , -- Add current buffer to selected files
} ,
2025-02-14 12:42:51 +08:00
providers = {
2025-02-14 18:31:39 +08:00
show_provides = " <leader>ap " , -- Show providers selector
2025-02-14 12:42:51 +08:00
} ,
2024-08-15 17:45:46 +08:00
} ,
2024-08-17 15:14:30 +08:00
windows = {
2025-02-14 12:42:51 +08:00
2024-10-15 17:12:10 +08:00
---@alias AvantePosition "right" | "left" | "top" | "bottom" | "smart"
2024-09-01 15:52:16 +08:00
position = " right " ,
2024-08-22 01:48:40 -04:00
wrap = true , -- similar to vim.o.wrap
2024-08-31 23:35:35 +08:00
width = 30 , -- default % based on available width in vertical layout
height = 30 , -- default % based on available height in horizontal layout
2024-08-21 23:31:11 +08:00
sidebar_header = {
2024-10-20 20:42:07 +01:00
enabled = true , -- true, false to enable/disable the header
2024-08-21 11:12:10 -04:00
align = " center " , -- left, center, right for title
2024-08-21 23:31:11 +08:00
rounded = true ,
2024-08-21 11:12:10 -04:00
} ,
2024-08-27 03:44:05 -04:00
input = {
prefix = " > " ,
2024-11-03 16:48:37 +08:00
height = 8 , -- Height of the input window in vertical layout
2024-08-27 03:44:05 -04:00
} ,
2024-08-27 13:13:38 -04:00
edit = {
border = " rounded " ,
2024-10-14 20:22:34 -07:00
start_insert = true , -- Start insert mode when opening the edit window
} ,
ask = {
floating = false , -- Open the 'AvanteAsk' prompt in a floating window
border = " rounded " ,
start_insert = true , -- Start insert mode when opening the ask window
2024-11-02 03:33:08 -07:00
---@alias AvanteInitialDiff "ours" | "theirs"
focus_on_apply = " ours " , -- which diff to focus after applying
2024-08-27 13:13:38 -04:00
} ,
2024-08-17 15:14:30 +08:00
} ,
2024-09-02 12:22:48 -04:00
--- @class AvanteConflictConfig
2024-08-17 14:14:02 -04:00
diff = {
autojump = true ,
2024-11-02 03:31:54 -07:00
--- Override the 'timeoutlen' setting while hovering over a diff (see :help timeoutlen).
--- Helps to avoid entering operator-pending mode with diff mappings starting with `c`.
--- Disable by setting to -1.
override_timeoutlen = 500 ,
2024-08-17 14:14:02 -04:00
} ,
2024-08-19 12:40:33 +10:00
--- @class AvanteHintsConfig
hints = {
2024-08-19 05:11:38 -04:00
enabled = true ,
2024-08-19 12:40:33 +10:00
} ,
2024-11-12 02:56:20 +10:00
--- @class AvanteRepoMapConfig
repo_map = {
ignore_patterns = { " %.git " , " %.worktree " , " __pycache__ " , " node_modules " } , -- ignore files matching these
2024-11-14 19:30:00 +10:00
negate_patterns = { } , -- negate ignore files matching these.
2024-11-12 02:56:20 +10:00
} ,
2024-12-13 09:55:36 -05:00
--- @class AvanteFileSelectorConfig
file_selector = {
2025-02-11 15:57:15 +08:00
--- @alias FileSelectorProvider "native" | "fzf" | "mini.pick" | "snacks" | "telescope" | string | fun(params: avante.file_selector.IParams|nil): nil
2024-12-13 09:55:36 -05:00
provider = " native " ,
-- Options override for custom providers
provider_opts = { } ,
} ,
2025-01-14 15:39:57 +08:00
suggestion = {
debounce = 600 ,
throttle = 600 ,
} ,
2024-08-15 17:45:46 +08:00
}
2024-08-17 15:14:30 +08:00
---@type avante.Config
2025-01-05 18:27:23 +08:00
M._options = { }
2024-08-17 15:14:30 +08:00
2024-09-02 12:22:48 -04:00
---@class avante.ConflictConfig: AvanteConflictConfig
2024-08-17 14:14:02 -04:00
---@field mappings AvanteConflictMappings
---@field highlights AvanteConflictHighlights
M.diff = { }
2024-09-02 12:22:48 -04:00
---@type Provider[]
M.providers = { }
2024-08-17 15:14:30 +08:00
---@param opts? avante.Config
function M . setup ( opts )
2024-09-03 05:12:07 -04:00
vim.validate ( { opts = { opts , " table " , true } } )
2024-09-01 19:33:04 -04:00
2025-01-11 11:56:21 -05:00
local merged = vim.tbl_deep_extend (
2024-08-28 14:43:14 -04:00
" force " ,
2025-01-05 18:27:23 +08:00
M._defaults ,
2024-08-28 14:43:14 -04:00
opts or { } ,
---@type avante.Config
{
behaviour = {
2024-09-06 01:09:02 -04:00
support_paste_from_clipboard = M.support_paste_image ( ) ,
2024-08-28 14:43:14 -04:00
} ,
}
)
2025-01-11 11:56:21 -05:00
M._options = merged
2024-09-02 12:22:48 -04:00
M.providers = vim
2025-01-05 18:27:23 +08:00
. iter ( M._defaults )
2024-09-03 04:19:54 -04:00
: filter ( function ( _ , value ) return type ( value ) == " table " and value.endpoint ~= nil end )
2024-09-02 12:22:48 -04:00
: fold ( { } , function ( acc , k )
acc = vim.list_extend ( { } , acc )
acc = vim.list_extend ( acc , { k } )
return acc
end )
2024-08-17 14:14:02 -04:00
2025-01-05 18:27:23 +08:00
vim.validate ( { provider = { M._options . provider , " string " , false } } )
2024-09-01 19:33:04 -04:00
2024-08-17 14:14:02 -04:00
M.diff = vim.tbl_deep_extend (
" force " ,
{ } ,
2025-01-05 18:27:23 +08:00
M._options . diff ,
{ mappings = M._options . mappings.diff , highlights = M._options . highlights.diff }
2024-08-17 14:14:02 -04:00
)
2024-08-22 01:48:40 -04:00
2025-01-05 18:27:23 +08:00
if next ( M._options . vendors ) ~= nil then
for k , v in pairs ( M._options . vendors ) do
M._options . vendors [ k ] = type ( v ) == " function " and v ( ) or v
2024-08-22 01:48:40 -04:00
end
2025-01-05 18:27:23 +08:00
vim.validate ( { vendors = { M._options . vendors , " table " , true } } )
M.providers = vim.list_extend ( M.providers , vim.tbl_keys ( M._options . vendors ) )
2024-08-22 01:48:40 -04:00
end
2024-08-17 15:14:30 +08:00
end
2024-08-18 22:20:29 -04:00
---@param opts? avante.Config
function M . override ( opts )
2024-09-03 05:12:07 -04:00
vim.validate ( { opts = { opts , " table " , true } } )
2024-09-01 19:33:04 -04:00
2025-01-05 18:27:23 +08:00
M._options = vim.tbl_deep_extend ( " force " , M._options , opts or { } )
2024-08-22 01:48:40 -04:00
M.diff = vim.tbl_deep_extend (
" force " ,
{ } ,
2025-01-05 18:27:23 +08:00
M._options . diff ,
{ mappings = M._options . mappings.diff , highlights = M._options . highlights.diff }
2024-08-22 01:48:40 -04:00
)
2024-08-29 17:08:39 -04:00
2025-01-05 18:27:23 +08:00
if next ( M._options . vendors ) ~= nil then
for k , v in pairs ( M._options . vendors ) do
M._options . vendors [ k ] = type ( v ) == " function " and v ( ) or v
2024-09-03 04:19:54 -04:00
if not vim.tbl_contains ( M.providers , k ) then M.providers = vim.list_extend ( M.providers , { k } ) end
2024-08-29 17:08:39 -04:00
end
2025-01-05 18:27:23 +08:00
vim.validate ( { vendors = { M._options . vendors , " table " , true } } )
2024-08-29 17:08:39 -04:00
end
2024-08-18 22:20:29 -04:00
end
2024-08-17 15:14:30 +08:00
M = setmetatable ( M , {
__index = function ( _ , k )
2025-01-05 18:27:23 +08:00
if M._options [ k ] then return M._options [ k ] end
2024-08-17 15:14:30 +08:00
end ,
} )
2024-09-06 01:09:02 -04:00
M.support_paste_image = function ( ) return Utils.has ( " img-clip.nvim " ) or Utils.has ( " img-clip " ) end
2024-08-29 17:08:39 -04:00
2024-09-03 04:19:54 -04:00
M.get_window_width = function ( ) return math.ceil ( vim.o . columns * ( M.windows . width / 100 ) ) end
2024-08-15 17:45:46 +08:00
2024-08-22 01:48:40 -04:00
---@param provider Provider
---@return boolean
2025-01-05 18:27:23 +08:00
M.has_provider = function ( provider ) return M._options [ provider ] ~= nil or M.vendors [ provider ] ~= nil end
2024-08-22 01:48:40 -04:00
---get supported providers
---@param provider Provider
2024-08-24 17:52:38 -04:00
---@return AvanteProviderFunctor
2024-08-22 01:48:40 -04:00
M.get_provider = function ( provider )
2025-01-05 18:27:23 +08:00
if M._options [ provider ] ~= nil then
2025-02-13 03:21:29 +08:00
return vim.deepcopy ( M._options [ provider ] , true )
2025-01-16 16:56:57 +08:00
elseif M.vendors and M.vendors [ provider ] ~= nil then
2025-02-13 03:21:29 +08:00
return vim.deepcopy ( M.vendors [ provider ] , true )
2024-08-22 01:48:40 -04:00
else
error ( " Failed to find provider: " .. provider , 2 )
end
end
2024-08-24 17:52:38 -04:00
M.BASE_PROVIDER_KEYS = {
" endpoint " ,
" model " ,
" deployment " ,
" api_version " ,
" proxy " ,
" allow_insecure " ,
" api_key_name " ,
" timeout " ,
2024-08-26 01:13:12 -04:00
-- internal
" local " ,
" _shellenv " ,
2024-08-31 13:39:50 -04:00
" tokenizer_id " ,
2024-09-03 04:09:13 -04:00
" use_xml_format " ,
2024-11-04 16:20:28 +08:00
" role_map " ,
2024-11-16 02:09:14 +08:00
" __inherited_from " ,
2025-02-06 02:46:52 +08:00
" disable_tools " ,
2024-08-24 17:52:38 -04:00
}
2024-08-22 01:48:40 -04:00
2024-08-15 17:45:46 +08:00
return M