David-Kunz / gen.nvim

Neovim plugin to generate text using LLMs with customizable prompts
The Unlicense
973 stars 62 forks source link

Please help to get `git diff` into prompt :) #101

Open dvogt23 opened 2 weeks ago

dvogt23 commented 2 weeks ago

Hey thanks for this great plugin, I would try to have something like this as a prompt for my commit messages, but have no idea how to get my local git diff into this prompt. Any suggestions? :)

David-Kunz commented 1 week ago

Hi @dvogt23 ,

Thanks! You can also modify the prompt templates programmatically and I would do it like that:

Create a lua function to 1) get the output of git diff 2) Put that into an appropriate prompt 3) Put that prompt into a temporary require('gen').prompts['someTmp'] 4) Invoke it with :Gen someTmp

Would that work for you?

dvogt23 commented 3 days ago

Seems strange, did try it like this:

function get_git_diff()
  -- Define the command to get the git diff
  local command = "git diff"

  -- Use io.popen to run the command and capture its output
  local handle = io.popen(command)
  local result = handle:read("*a") -- Read all output
  handle:close()

  return result
end

require("gen").prompts["Commit summary"] = {
  prompt = "You are an expert developer specialist in creating commits. Provide a super concise one sentence overall changes summary of the user "
    .. get_git_diff()
    .. " output following strictly the next rules: - Do not use any code snippets, imports, file routes or bullets points. - Do not mention the route of file that has been change. - Simply describe the MAIN GOAL of the changes. - Output directly the summary in plain text.",
  replace = true,
}

but getting always like this as output: The user output shows the main goal of the changes as "Added new features to improve the performance and user experience of the application."

I think I have to chain the output of the first prompt, to this:

You are an expert developer specialist in creating commits messages.
    Your only goal is to retrieve a single commit message. 
    Based on the provided user changes, combine them in ONE SINGLE commit message retrieving the global idea, following strictly the next rules:
    - Always use the next format: \`{type}: {commit_message}\` where \`{type}\` is one of \`feat\`, \`fix\`, \`docs\`, \`style\`, \`refactor\`, \`test\`, \`chore\`, \`revert\`.
    - Output directly only one commit message in plain text.
    - Be as concise as possible. 50 characters max.
    - Do not add any issues numeration nor explain your output.

Is this possible somehow? 😆