100 lines
3.4 KiB
Lua
100 lines
3.4 KiB
Lua
return {
|
||
"madox2/vim-ai",
|
||
config = function ()
|
||
vim.g.vim_ai_roles_config_file = '/home/jay/.config/nvim/vim-ai-roles.ini'
|
||
|
||
local vim_ai_endpoint_url = "http://localhost:11434/v1/chat/completions"
|
||
-- local vim_ai_endpoint_url = "http://192.168.88.11:11434/v1/chat/completions"
|
||
local vim_ai_model = "gemma3:12b"
|
||
local vim_ai_model_large = "deepseek-r1"
|
||
local vim_ai_temperature = 0.3
|
||
|
||
local vim_ai_chat_config = {
|
||
engine = "chat",
|
||
options = {
|
||
model = vim_ai_model,
|
||
temperature = vim_ai_temperature,
|
||
endpoint_url = vim_ai_endpoint_url,
|
||
auth_type = "none",
|
||
max_tokens = 0,
|
||
request_timeout = 180,
|
||
},
|
||
ui = {
|
||
code_syntax_enabled = 1,
|
||
},
|
||
}
|
||
|
||
local vim_ai_edit_config = {
|
||
engine = "chat",
|
||
options = {
|
||
model = vim_ai_model,
|
||
temperature = vim_ai_temperature,
|
||
endpoint_url = vim_ai_endpoint_url,
|
||
auth_type = "none",
|
||
max_tokens = 0,
|
||
request_timeout = 180,
|
||
},
|
||
ui = {
|
||
paste_mode = 1,
|
||
},
|
||
}
|
||
|
||
vim.g.vim_ai_chat = vim_ai_chat_config
|
||
vim.g.vim_ai_complete = vim_ai_edit_config
|
||
vim.g.vim_ai_edit = vim_ai_edit_config
|
||
|
||
function git_commit_message_fn(model, intent)
|
||
model = model or vim_ai_model
|
||
intent = intent or ""
|
||
local diff = vim.fn.system('git --no-pager diff --staged')
|
||
local initial_prompt = [[
|
||
You are a Senior Software Engineer responsible for crafting clear and informative Git commit messages. Your goal is to ensure that every commit message contributes to the maintainability and understandability of the codebase. A well-written commit message allows other developers to quickly grasp the purpose and impact of the changes.
|
||
|
||
**Here's the structure we'll use for all commit messages:**
|
||
|
||
1. **Subject Line (Required):**
|
||
* Use a conventional prefix: `feat:`, `fix:`, `chore:`, `refactor:`, `docs:`, `test:`, `style:`, `perf:`, `build:`
|
||
* Keep it concise – 50 characters or less.
|
||
* Use an imperative verb (e.g., "Add...", "Fix...", "Update...", "Remove...").
|
||
|
||
2. **Body (Optional, but recommended):**
|
||
* Start with a blank line after the subject line.
|
||
* Provide a brief explanation (3-4 bullet points) of *why* the change was made, not *what* was changed.
|
||
* Keep lines under 72 characters.
|
||
* Avoid implementation details.
|
||
|
||
**Do not include:** Markdown, emojis, or overly detailed code descriptions.
|
||
|
||
]]
|
||
local prompt = [["\n" .. "**Now, generate a Git commit message based on the following changes:**\n```" ]] .. diff .. [[```]]
|
||
local range = 0
|
||
|
||
if not (intent == "")
|
||
then
|
||
prompt = [[Short Description:\n"]] .. intent .. prompt
|
||
end
|
||
|
||
local config = {
|
||
engine = "chat",
|
||
options = {
|
||
model = model,
|
||
initial_prompt = initial_prompt,
|
||
endpoint_url = vim_ai_endpoint_url,
|
||
auth_type = "none",
|
||
temperature = 0.8,
|
||
request_timeout = 240,
|
||
},
|
||
}
|
||
vim.api.nvim_call_function("vim_ai#AIRun", { range, config, prompt })
|
||
end
|
||
|
||
vim.api.nvim_create_user_command("GitCommitMessage", function(opts)
|
||
git_commit_message_fn(vim_ai_model, opts.args)
|
||
end, {nargs = '?'})
|
||
vim.api.nvim_create_user_command("GitCommitMessageL", function(opts)
|
||
git_commit_message_fn(vim_ai_model_large, opts.args)
|
||
end, {nargs = '?'})
|
||
|
||
end
|
||
}
|