I would like first to thank gera2ld for his work on ai.nvim, because this plugin is a fork of his work. Without his plugin, there wouldnt be this one. Thank you @gera2ld for your work.
A Neovim plugin powered by Google Gemini and ChatGPT. Here is a demo:
First get API keys from Google Cloud and ChatGPT and set them in your environment:
Using Lazy.nvim:
{
'natixgroup/code-ai.nvim',
dependencies = 'nvim-lua/plenary.nvim',
opts = {
gemini_api_key = 'YOUR_GEMINI_API_KEY', -- or read from env: `os.getenv('GEMINI_API_KEY')`
chatgtp_api_key = 'YOUR_CHATGPT_API_KEY', -- or read from env: `os.getenv('CHATGPT_API_KEY')`
-- Gemini's answer is displayed in a popup buffer
-- Default behaviour is not to give it the focus because it is seen as a kind of tooltip
-- But if you prefer it to get the focus, set to true.
result_popup_gets_focus = false,
-- Define custom prompts here, see below for more details
prompts = {
javascript_vanilla = {
command = 'AIJavascriptVanilla',
instruction_tpl = 'Act as a Vanilla Javascript developer. Format you answer with Markdown.',
prompt_tpl = '${input}',
result_tpl = '${output}',
loading_tpl = 'Loading...',
require_input = true,
},
},
},
event = 'VimEnter',
},
The prompts will be merged into built-in prompts. Here are the available fields for each prompt:
Fields | Required | Description |
---|---|---|
command |
No | If defined, a user command will be created for this prompt. |
loading_tpl |
No | Template for content shown when communicating with Gemini. See below for available placeholders. |
prompt_tpl |
Yes | Template for the prompt string passed to Gemini. See below for available placeholders. |
result_tpl |
No | Template for the result shown in the popup. See below for available placeholders. |
require_input |
No | If set to true , the prompt will only be sent if text is selected or passed to the command. |
Placeholders can be used in templates. If not available, it will be left as is.
Placeholders | Description | Availability |
---|---|---|
${locale} |
opts.locale |
Always |
${alternate_locale} |
opts.alternate_locale |
Always |
${input} |
The text selected or passed to the command. | Always |
${input_encoded} |
The text encoded with JSON so that Gemini will take it as literal instead of a new prompt. | Always |
${output} |
The result returned by Gemini. | After the request |