Files
nvim-config/lua/plugins/ai.lua
2026-01-12 23:12:11 -07:00

197 lines
5.1 KiB
Lua

-- AI Chat Integration using avante.nvim
-- Supports: Anthropic Claude, OpenAI, Google Gemini, Copilot, and more
-- API keys via environment variables:
-- ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY
-- Or scoped: AVANTE_ANTHROPIC_API_KEY, AVANTE_OPENAI_API_KEY, etc.
return {
{
"yetone/avante.nvim",
event = "VeryLazy",
version = false, -- Never set to "*"
build = "make",
dependencies = {
"nvim-treesitter/nvim-treesitter",
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
"nvim-tree/nvim-web-devicons",
{
-- Image support (optional)
"HakonHarnes/img-clip.nvim",
event = "VeryLazy",
opts = {
default = {
embed_image_as_base64 = false,
prompt_for_file_name = false,
drag_and_drop = {
insert_mode = true,
},
},
},
},
{
-- Markdown rendering in Avante
"MeanderingProgrammer/render-markdown.nvim",
opts = {
file_types = { "markdown", "Avante" },
},
ft = { "markdown", "Avante" },
},
},
---@module 'avante'
---@type avante.Config
opts = {
-- Default provider (switch with :AvanteProvider command)
-- Options: "claude", "openai", "azure", "gemini", "copilot", "cohere"
provider = "claude",
-- Provider configurations
providers = {
claude = {
endpoint = "https://api.anthropic.com",
model = "claude-sonnet-4-5-20250929",
timeout = 30000,
extra_request_body = {
temperature = 0.75,
max_tokens = 20480,
},
},
openai = {
endpoint = "https://api.openai.com/v1",
model = "gpt-4o",
timeout = 30000,
extra_request_body = {
temperature = 0.75,
max_completion_tokens = 16384,
},
},
azure = {
endpoint = "", -- e.g., "https://<resource>.openai.azure.com"
deployment = "", -- Azure deployment name
api_version = "2024-12-01-preview",
timeout = 30000,
extra_request_body = {
temperature = 0.75,
max_completion_tokens = 16384,
},
},
gemini = {
endpoint = "https://generativelanguage.googleapis.com/v1beta/models",
model = "gemini-2.0-flash",
timeout = 30000,
extra_request_body = {
generationConfig = {
temperature = 0.75,
},
},
},
copilot = {
endpoint = "https://api.githubcopilot.com",
model = "gpt-4o-2024-08-06",
timeout = 30000,
extra_request_body = {
temperature = 0.75,
max_tokens = 20480,
},
},
-- Custom provider example for Ollama (local models)
-- Uncomment and configure if using local LLMs
-- ollama = {
-- __inherited_from = "openai",
-- endpoint = "http://localhost:11434/v1",
-- model = "llama3.2",
-- api_key_name = "",
-- },
},
-- Behavior settings
behaviour = {
auto_suggestions = false, -- Set true for copilot-like suggestions
auto_set_highlight_group = true,
auto_set_keymaps = true,
auto_apply_diff_after_generation = false,
support_paste_from_clipboard = false,
minimize_diff = true,
enable_token_counting = true,
},
-- Mappings
mappings = {
diff = {
ours = "co",
theirs = "ct",
all_theirs = "ca",
both = "cb",
cursor = "cc",
next = "]x",
prev = "[x",
},
suggestion = {
accept = "<M-l>",
next = "<M-]>",
prev = "<M-[>",
dismiss = "<C-]>",
},
jump = {
next = "]]",
prev = "[[",
},
submit = {
normal = "<CR>",
insert = "<C-s>",
},
sidebar = {
apply_all = "A",
apply_cursor = "a",
switch_windows = "<Tab>",
reverse_switch_windows = "<S-Tab>",
},
},
-- Hints shown in the UI
hints = { enabled = true },
-- Window configuration
windows = {
position = "right",
wrap = true,
width = 30,
sidebar_header = {
enabled = true,
align = "center",
rounded = true,
},
input = {
prefix = "> ",
height = 8,
},
edit = {
border = "rounded",
start_insert = true,
},
ask = {
floating = false,
start_insert = true,
border = "rounded",
},
},
-- Highlight groups
highlights = {
diff = {
current = "DiffText",
incoming = "DiffAdd",
},
},
-- Diff settings
diff = {
autojump = true,
list_opener = "copen",
override_timeoutlen = 500,
},
},
},
}