forked from yetone/avante.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.lua
276 lines (256 loc) · 7.45 KB
/
config.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
---NOTE: user will be merged with defaults and
---we add a default var_accessor for this table to config values.
local Utils = require("avante.utils")
---@class avante.CoreConfig: avante.Config
local M = {}
---@class avante.Config
---@field silent_warning boolean will be determined from debug
M.defaults = {
debug = false,
---@alias Provider "claude" | "openai" | "azure" | "gemini" | "cohere" | string
provider = "claude", -- Only recommend using Claude
---@type AvanteSupportedProvider
openai = {
endpoint = "https://api.openai.com/v1",
model = "gpt-4o",
timeout = 30000, -- Timeout in milliseconds
temperature = 0,
max_tokens = 4096,
["local"] = false,
},
---@type AvanteAzureProvider
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",
timeout = 30000, -- Timeout in milliseconds
temperature = 0,
max_tokens = 4096,
["local"] = false,
},
---@type AvanteSupportedProvider
claude = {
endpoint = "https://api.anthropic.com",
model = "claude-3-5-sonnet-20240620",
timeout = 30000, -- Timeout in milliseconds
temperature = 0,
max_tokens = 4096,
["local"] = false,
},
---@type AvanteSupportedProvider
gemini = {
endpoint = "https://generativelanguage.googleapis.com/v1beta/models",
model = "gemini-1.5-flash-latest",
timeout = 30000, -- Timeout in milliseconds
temperature = 0,
max_tokens = 4096,
["local"] = false,
},
---@type AvanteSupportedProvider
cohere = {
endpoint = "https://api.cohere.com/v1",
model = "command-r-plus",
timeout = 30000, -- Timeout in milliseconds
temperature = 0,
max_tokens = 3072,
["local"] = false,
},
---To add support for custom provider, follow the format below
---See https://github.com/yetone/avante.nvim/README.md#custom-providers for more details
---@type {[string]: AvanteProvider}
vendors = {},
---Specify the behaviour of avante.nvim
---1. auto_apply_diff_after_generation: Whether to automatically apply diff after LLM response.
--- This would simulate similar behaviour to cursor. Default to false.
---2. auto_set_keymaps : Whether to automatically set the keymap for the current line. Default to true.
--- Note that avante will safely set these keymap. See https://github.com/yetone/avante.nvim/wiki#keymaps-and-api-i-guess for more details.
---3. auto_set_highlight_group : Whether to automatically set the highlight group for the current line. Default to true.
---4. support_paste_from_clipboard : Whether to support pasting image from clipboard. This will be determined automatically based whether img-clip is available or not.
behaviour = {
auto_set_highlight_group = true,
auto_set_keymaps = true,
auto_apply_diff_after_generation = false,
support_paste_from_clipboard = false,
},
history = {
storage_path = vim.fn.stdpath("state") .. "/avante",
paste = {
extension = "png",
filename = "pasted-%Y-%m-%d-%H-%M-%S",
},
},
highlights = {
---@type AvanteConflictHighlights
diff = {
current = "DiffText",
incoming = "DiffAdd",
},
},
mappings = {
---@class AvanteConflictMappings
diff = {
ours = "co",
theirs = "ct",
all_theirs = "ca",
none = "c0",
both = "cb",
cursor = "cc",
next = "]x",
prev = "[x",
},
jump = {
next = "]]",
prev = "[[",
},
submit = {
normal = "<CR>",
insert = "<C-s>",
},
-- NOTE: The following will be safely set by avante.nvim
ask = "<leader>aa",
edit = "<leader>ae",
refresh = "<leader>ar",
toggle = {
debug = "<leader>ad",
hint = "<leader>ah",
},
},
windows = {
wrap = true, -- similar to vim.o.wrap
width = 30, -- default % based on available width
sidebar_header = {
align = "center", -- left, center, right for title
rounded = true,
},
input = {
prefix = "> ",
},
edit = {
border = "rounded",
},
},
--- @class AvanteConflictUserConfig
diff = {
autojump = true,
---@type string | fun(): any
list_opener = "copen",
},
--- @class AvanteHintsConfig
hints = {
enabled = true,
},
}
---@type avante.Config
M.options = {}
---@class avante.ConflictConfig: AvanteConflictUserConfig
---@field mappings AvanteConflictMappings
---@field highlights AvanteConflictHighlights
M.diff = {}
---@class AvanteHintsConfig
---@field enabled boolean
M.hints = {}
---@param opts? avante.Config
function M.setup(opts)
M.options = vim.tbl_deep_extend(
"force",
M.defaults,
opts or {},
---@type avante.Config
{
behaviour = {
support_paste_from_clipboard = M.support_paste_image(),
},
}
)
if not M.options.silent_warning then
-- set silent_warning to true if debug is false
M.options.silent_warning = not M.options.debug
end
M.diff = vim.tbl_deep_extend(
"force",
{},
M.options.diff,
{ mappings = M.options.mappings.diff, highlights = M.options.highlights.diff }
)
M.hints = vim.tbl_deep_extend("force", {}, M.options.hints)
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
end
end
end
---@param opts? avante.Config
function M.override(opts)
opts = opts or {}
M.options = vim.tbl_deep_extend("force", M.options, opts)
if not M.options.silent_warning then
-- set silent_warning to true if debug is false
M.options.silent_warning = not M.options.debug
end
M.diff = vim.tbl_deep_extend(
"force",
{},
M.options.diff,
{ mappings = M.options.mappings.diff, highlights = M.options.highlights.diff }
)
M.hints = vim.tbl_deep_extend("force", {}, M.options.hints)
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
end
end
end
M = setmetatable(M, {
__index = function(_, k)
if M.options[k] then
return M.options[k]
end
end,
})
M.support_paste_image = function()
local supported = Utils.has("img-clip.nvim") or Utils.has("img-clip")
if not supported then
Utils.warn("img-clip.nvim is not installed. Pasting image will be disabled.", { once = true })
end
return supported
end
M.get_window_width = function()
return math.ceil(vim.o.columns * (M.windows.width / 100))
end
---@param provider Provider
---@return boolean
M.has_provider = function(provider)
return M.options[provider] ~= nil or M.vendors[provider] ~= nil
end
---get supported providers
---@param provider Provider
---@return AvanteProviderFunctor
M.get_provider = function(provider)
if M.options[provider] ~= nil then
return vim.deepcopy(M.options[provider], true)
elseif M.vendors[provider] ~= nil then
return vim.deepcopy(M.vendors[provider], true)
else
error("Failed to find provider: " .. provider, 2)
end
end
M.BASE_PROVIDER_KEYS = {
"endpoint",
"model",
"deployment",
"api_version",
"proxy",
"allow_insecure",
"api_key_name",
"timeout",
-- internal
"local",
"_shellenv",
}
---@return {width: integer, height: integer}
M.get_sidebar_layout_options = function()
local width = M.get_window_width()
local height = vim.o.lines
return { width = width, height = height }
end
return M