David-Kunz / gen.nvim

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

Support defining a prompt as a function in addition to a string #15

Closed leafo closed 9 months ago

leafo commented 9 months ago

This will allow you to provide a function when declaring the prompt for the prompt field. The function should return a string that will be used in the final prompt. The function is called every time a generate call is issued. Variables still work on the output string.

I gave the function one argument, a table of properties that are in scope relevant the interpolation of the prompt, should you want to do manual interpolation.

The purpose is to enable dynamic prompt generation that is more flexible than just the variable system. A few examples:

leafo commented 9 months ago

Threw in a minor bug fix to prevent printing $ a bunch if you change focus from the output window: https://github.com/David-Kunz/gen.nvim/pull/15/commits/ba9b73d55167647a3bb64a7dc565bbc188890ec3