### Install with packer.nvim Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md Example configuration for installing ChatGPT.nvim using the packer.nvim plugin manager, including required dependencies. ```lua -- Packer use({ "jackMort/ChatGPT.nvim", config = function() require("chatgpt").setup() end, requires = { "MunifTanjim/nui.nvim", "nvim-lua/plenary.nvim", "folke/trouble.nvim", "nvim-telescope/telescope.nvim" } }) ``` -------------------------------- ### Install with lazy.nvim Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md Example configuration for installing ChatGPT.nvim using the lazy.nvim plugin manager, including dependencies and event triggers. ```lua -- Lazy { "jackMort/ChatGPT.nvim", event = "VeryLazy", config = function() require("chatgpt").setup() end, dependencies = { "MunifTanjim/nui.nvim", "nvim-lua/plenary.nvim", "folke/trouble.nvim", -- optional "nvim-telescope/telescope.nvim" } } ``` -------------------------------- ### Lua API Mapping Example Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md Demonstrates how to map the `edit_with_instructions` functionality using the `which-key.nvim` plugin for visual mode editing. ```lua local chatgpt = require("chatgpt") wk.register({ p = { name = "ChatGPT", e = { function() chatgpt.edit_with_instructions() end, "Edit with instructions", }, }, }, { prefix = "", mode = "v", }) ``` -------------------------------- ### Basic Configuration Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md Configures the ChatGPT.nvim plugin with OpenAI parameters, assuming OPENAI_API_KEY is set in the environment. ```lua { "jackMort/ChatGPT.nvim", event = "VeryLazy", config = function() require("chatgpt").setup({ -- this config assumes you have OPENAI_API_KEY environment variable set openai_params = { -- NOTE: model can be a function returning the model name -- this is useful if you want to change the model on the fly -- using commands -- Example: -- model = function() -- if some_condition() then -- return "gpt-4-1106-preview" -- else -- return "gpt-3.5-turbo" -- end -- end, model = "gpt-4-1106-preview", frequency_penalty = 0, presence_penalty = 0, max_tokens = 4095, temperature = 0.2, top_p = 0.1, n = 1, } }) end, dependencies = { "MunifTanjim/nui.nvim", "nvim-lua/plenary.nvim", "folke/trouble.nvim", -- optional "nvim-telescope/telescope.nvim" } } ``` -------------------------------- ### Configure Azure OpenAI Deployment (Environment Variables) Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md Sets up the plugin for Azure OpenAI deployments by specifying API type, base URL, engine, and version via environment variables. ```bash export OPENAI_API_TYPE="azure" export OPENAI_API_BASE="https://{your-resource-name}.openai.azure.com" export OPENAI_API_AZURE_ENGINE="chat" export OPENAI_API_AZURE_VERSION="2023-05-15" ``` -------------------------------- ### API Key Management with 1Password CLI Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md Configures the plugin to fetch the OpenAI API key using the 1Password CLI, enhancing security by avoiding environment variables. ```lua require("chatgpt").setup({ api_key_cmd = "op read op://private/OpenAI/credential --no-newline" }) ``` -------------------------------- ### Configure Azure OpenAI Deployment (Lua) Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md Sets up the plugin for Azure OpenAI deployments by specifying API type, base URL, engine, and version via Lua configuration commands. ```lua local config = { api_host_cmd = 'echo -n ""', api_key_cmd = 'pass azure-openai-key', api_type_cmd = 'echo azure', azure_api_base_cmd = 'echo https://{your-resource-name}.openai.azure.com', azure_api_engine_cmd = 'echo chat', azure_api_version_cmd = 'echo 2023-05-15' } require("chatgpt").setup(config) ``` -------------------------------- ### API Key Management with GPG Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md Configures the plugin to fetch the OpenAI API key by decrypting a local file using GPG, providing a secure alternative to environment variables. ```lua local home = vim.fn.expand("$HOME") require("chatgpt").setup({ api_key_cmd = "gpg --decrypt " .. home .. "/secret.txt.gpg" }) ``` -------------------------------- ### ChatGPT.nvim Commands and API Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md Details the primary commands and Lua API functions provided by the ChatGPT.nvim plugin for interacting with AI models. ```APIDOC ChatGPT: - Opens an interactive window using the default model (e.g., gpt-3.5-turbo). - Usage: `:ChatGPT` ChatGPTActAs: - Opens a prompt selection window from Awesome ChatGPT Prompts to be used with the default model. - Usage: `:ChatGPTActAs` ChatGPTEditWithInstructions: - Opens an interactive window to edit selected text or the whole buffer using a code-specific model (e.g., code-davinci-edit-001). - Usage: `:ChatGPTEditWithInstructions` Lua API: chatgpt.edit_with_instructions(): - Function to trigger the edit-with-instructions functionality programmatically. - Example: `chatgpt.edit_with_instructions()` ``` -------------------------------- ### Whichkey Plugin Mappings for ChatGPT Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md Lua code snippet to integrate ChatGPT.nvim commands into the Whichkey plugin for convenient keyboard shortcuts. These mappings provide quick access to various ChatGPT actions directly from Neovim. ```lua c = { name = "ChatGPT", c = { "ChatGPT", "ChatGPT" }, e = { "ChatGPTEditWithInstruction", "Edit with instruction", mode = { "n", "v" } }, g = { "ChatGPTRun grammar_correction", "Grammar Correction", mode = { "n", "v" } }, t = { "ChatGPTRun translate", "Translate", mode = { "n", "v" } }, k = { "ChatGPTRun keywords", "Keywords", mode = { "n", "v" } }, d = { "ChatGPTRun docstring", "Docstring", mode = { "n", "v" } }, a = { "ChatGPTRun add_tests", "Add Tests", mode = { "n", "v" } }, o = { "ChatGPTRun optimize_code", "Optimize Code", mode = { "n", "v" } }, s = { "ChatGPTRun summarize", "Summarize", mode = { "n", "v" } }, f = { "ChatGPTRun fix_bugs", "Fix Bugs", mode = { "n", "v" } }, x = { "ChatGPTRun explain_code", "Explain Code", mode = { "n", "v" } }, r = { "ChatGPTRun roxygen_edit", "Roxygen Edit", mode = { "n", "v" } }, l = { "ChatGPTRun code_readability_analysis", "Code Readability Analysis", mode = { "n", "v" } }, } ``` -------------------------------- ### ChatGPTRun Command and Actions Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md The `ChatGPTRun` command executes predefined or custom actions using AI models. It supports various actions like grammar correction, translation, code explanation, and more. Custom actions can be defined via JSON files, allowing flexible integration with different AI tasks and strategies. ```APIDOC ChatGPTRun Command: Usage: :ChatGPTRun [action] Description: Executes a specified AI action. Available Actions: - grammar_correction: Improves grammar of selected text. - translate: Translates selected text to another language. - keywords: Extracts keywords from selected text. - docstring: Generates a docstring for code. - add_tests: Creates unit tests for code. - optimize_code: Optimizes selected code. - summarize: Summarizes selected text. - fix_bugs: Fixes bugs in code. - explain_code: Explains selected code. - roxygen_edit: Edits Roxygen documentation. - code_readability_analysis: Analyzes code readability. Custom Actions: - Define custom actions using JSON files specified in the plugin's configuration (`actions_paths`). - Actions can be of type 'chat', 'completion', or 'edit'. - Options include 'template', 'strategy' (replace, display, append, edit), and API parameters. - Example custom action structure provided in documentation. ``` -------------------------------- ### Interactive Popup Keybindings Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md Keybindings for interacting with the ChatGPT Neovim plugin's popup windows. These shortcuts facilitate submitting actions, managing chat sessions, toggling windows, and navigating between different UI elements. ```APIDOC Interactive Popup Keybindings: General (Both Chat and Edit): - : Submit action. - : Copy/yank last answer. - : Toggle settings window. - : Toggle help window. - : Cycle over windows. - : Close chat window. - : Toggle system message window. Chat Specific: - : Cycle over modes (center, stick to right). - : Toggle sessions list. - : Scroll up chat window. - : Scroll down chat window. - : Copy/yank code from last answer. - : Start new session. - : Draft message (create message without submitting). - : Switch role (user/assistant). Edit Window Specific: - : Use response as input. - : View diff and use diff-mode commands. ``` -------------------------------- ### Custom Action JSON Structure Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md This JSON structure defines a custom AI action for the chatgpt.nvim plugin. It specifies the action's type, execution options like templates and strategies, and parameters compatible with the OpenAI API. It also includes argument definitions for user-provided inputs. ```json { "action_name": { "type": "chat", "opts": { "template": "A template using possible variable: {{filetype}} (neovim filetype), {{input}} (the selected text) an {{argument}} (provided on the command line), {{filepath}} (the relative path to the file)", "strategy": "replace", "params": { "model": "gpt-3.5-turbo", "stop": [ "```" ] } }, "args": { "argument": { "type": "strig", "optional": "true", "default": "some value" } } } } ``` -------------------------------- ### Configure Extra cURL Parameters Source: https://github.com/jackmort/chatgpt.nvim/blob/main/README.md Allows passing custom cURL parameters to the plugin, useful for including additional headers in requests to the OpenAI API. ```lua { ..., extra_curl_params = { "-H", "Origin: https://example.com" } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.