From a9f321a847c12bc1656f9c1d4b21a9b1262de074 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 28 Oct 2024 13:45:55 +0000 Subject: [PATCH 1/5] update flake --- flake.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index d89f4a4..2b61d9a 100644 --- a/flake.lock +++ b/flake.lock @@ -427,11 +427,11 @@ }, "nix-secrets": { "locked": { - "lastModified": 1728846526, - "narHash": "sha256-QgLj9RmR8wXCSNxQu4yJpUWG3fs74+RwkBzbTet/7nQ=", + "lastModified": 1729849584, + "narHash": "sha256-byrCBtIcqFLEUoLCAli5g4w1allf4kPrxFV7+3jenCI=", "ref": "refs/heads/master", - "rev": "0a6c9a51bec90e47a577a7229f0519bdd8f0a914", - "revCount": 186, + "rev": "97c60da5f7e750b8d4cdcaacee4dfab393cabb94", + "revCount": 187, "type": "git", "url": "ssh://git@git.bitlab21.com/sam/nix-secrets.git" }, From 13dad7b53272419fca4ebfa262d1285a3a74086d Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 28 Oct 2024 17:46:09 +0000 Subject: [PATCH 2/5] Update: Add Mistral API key and Parrot.nvim plugin - Introduce Mistral API key - Add Parrot.nvim plugin - Implement a function to read the API key from a secrets file - Set up Parrot.nvim with Mistral provider and custom hooks for code assistance and git commit generation --- home/common/core/nixvim/plugins/default.nix | 98 +++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/home/common/core/nixvim/plugins/default.nix b/home/common/core/nixvim/plugins/default.nix index 348b687..fe13b79 100644 --- a/home/common/core/nixvim/plugins/default.nix +++ b/home/common/core/nixvim/plugins/default.nix @@ -1,10 +1,18 @@ { pkgs, config, + lib, + inputs, ... }: let user = config.home.username; + mistralAPIKey = lib.optionalString (lib.hasAttr "sops-nix" inputs) config.sops.secrets."mistral-api-key".path; in { + sops.secrets = { + "mistral-api-key" = { + }; + }; + imports = [ ./cmp.nix ./colorizer.nix @@ -32,6 +40,18 @@ in { pkgs.vimPlugins.vim-dadbod-ui pkgs.vimPlugins.vim-dadbod-completion pkgs.vimPlugins.fugitive + + (pkgs.vimUtils.buildVimPlugin + { + name = "parrot.nvim"; + src = pkgs.fetchFromGitHub { + owner = "frankroeder"; + repo = "parrot.nvim"; + rev = "c992483"; + sha256 = "sha256-P899qNY/h5LTW0pp3sAmcSDsDGWQedXa20J7EggL7F8="; + }; + }) + (pkgs.vimUtils.buildVimPlugin { name = "buffer_manager.nvim"; @@ -58,6 +78,18 @@ in { pkgs.vimPlugins.vim-devicons ]; programs.nixvim.extraConfigLua = '' + -- function to read api key from secrets file + local function read_api_key(file_path) + local file = io.open(file_path, "r") + if file then + local api_key = file:read("*all") + file:close() + return api_key + else + error("Failed to open file: " .. file_path) + end + end + -- buffer_manager.nvim local opts = {noremap = true} @@ -123,5 +155,71 @@ in { end require("conform").format({ async = true, lsp_format = "fallback", range = range }) end, { range = true }) + + -- parrot.nvim setup + require("parrot").setup { + toggle_target = "popup", + providers = { + mistral = { + api_key = read_api_key("${mistralAPIKey}"), + params = { + chat = { temperature = 0, top_p = 1, max_tokens = 16384 }, + command = { temperature = 0, top_p = 1, max_tokens = 16384 }, + }, + -- api_key = os.getenv "MISTRAL_API_KEY", + }, + }, + hooks = { + AskCoder = function(prt, params) + local prompt = [[ + You are a code assistent. Answer my question carefully and concisely. + Answer with code snippets only. Do not give a summary or include any + code comments in your response. Never repeate code from a prevous + response or write obvious or unnecessary code, instead refer to such + code like: "**rest of code here**", or something to that effect. + Tokens are expensive, to we need to be very consice. If you uses + excessive tokens, then I will send you the invoice to pay the bill. + Question: {{command}} + ``` + ]] + prt.ChatNew(params, prompt) + end, + + AskCoderSel = function(parrot, params) + local template = [[ + You are an expert programmer. Here is a code snippet along with a + question. Give me a short, accurate and consice answer. + + ```{{filetype}} + {{selection}} + ``` + ]] + local model_obj = parrot.get_model("command") + parrot.logger.info("Asking model: " .. model_obj.name) + parrot.Prompt(params, parrot.ui.Target.popup, model_obj, "🤖 Ask ~ ", template) + end, + + GitCommit = function(parrot, params) + local template = [[ + You are a git commit generator. You will be provided with a git diff file. + Your role is to create a concise commit message that outlines all of the + most relevant and impactful changes in the diff. You only output a commit + message, do not write anything else not related to the commit. Use + imperative mood for you writing style. Your message should include a + short summary in the first line followed by more detailed descriptions of + the changes on subsequent lines. The first line summary should be no more + than 70 characters, not end with a period, and a blank line should + separate the summary from the body of the message. There should only be 1 + summary line, and 1 body with the description. The body should include no + more than 3 bullet points with more detailed descriptions of the files + and functions that have been modified. Do not output any code. + Diff: {{selection}} + ]] + local model_obj = parrot.get_model("command") + parrot.logger.info("Asking model: " .. model_obj.name) + parrot.Prompt(params, parrot.ui.Target.popup, model_obj, nil, template) + end, + } + } ''; } From 16436da1e47bd97e906ce6ede8df0cde631da211 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 28 Oct 2024 17:51:42 +0000 Subject: [PATCH 3/5] Update nixvim configuration to use unstable Neovim package --- home/common/core/nixvim/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/home/common/core/nixvim/default.nix b/home/common/core/nixvim/default.nix index 80d1209..d0f9db2 100644 --- a/home/common/core/nixvim/default.nix +++ b/home/common/core/nixvim/default.nix @@ -28,6 +28,7 @@ ]; programs.nixvim = { enable = true; + package = pkgs.unstable.neovim-unwrapped; enableMan = true; # install man pages for nixvim options clipboard.register = "unnamedplus"; # use system clipboard instead of internal registers globals.mapleader = " "; From dde54c9aa7245f2d566ac01d3b04f9e56f23ee7b Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 28 Oct 2024 17:52:29 +0000 Subject: [PATCH 4/5] Add lib to configuration --- home/common/core/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/home/common/core/default.nix b/home/common/core/default.nix index db9a86f..31a09bb 100644 --- a/home/common/core/default.nix +++ b/home/common/core/default.nix @@ -1,4 +1,4 @@ -{ pkgs, inputs, outputs, ... }: +{ pkgs, inputs, outputs, lib, ... }: { imports = [ inputs.nix-colors.homeManagerModules.default From 8561f44963fd7d86402198c92a38106e833ad843 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 28 Oct 2024 17:52:45 +0000 Subject: [PATCH 5/5] update flake.lock --- flake.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/flake.lock b/flake.lock index 2b61d9a..3224301 100644 --- a/flake.lock +++ b/flake.lock @@ -427,11 +427,11 @@ }, "nix-secrets": { "locked": { - "lastModified": 1729849584, - "narHash": "sha256-byrCBtIcqFLEUoLCAli5g4w1allf4kPrxFV7+3jenCI=", + "lastModified": 1730130467, + "narHash": "sha256-mcyG1iu8hNmkDjgDEdFQyCZ3bBxBHFKd4nxT8NreMmY=", "ref": "refs/heads/master", - "rev": "97c60da5f7e750b8d4cdcaacee4dfab393cabb94", - "revCount": 187, + "rev": "c82ff6f7e995503acabb9cf2478e5b4e401968ce", + "revCount": 188, "type": "git", "url": "ssh://git@git.bitlab21.com/sam/nix-secrets.git" }, @@ -549,11 +549,11 @@ "treefmt-nix": "treefmt-nix" }, "locked": { - "lastModified": 1729100089, - "narHash": "sha256-B44+e/cYjrzgaDvCNz9TyHQy0q9Q6WaDISV57jxejJ8=", + "lastModified": 1729945968, + "narHash": "sha256-4u+nbBSMuXWGCtXxUPPEflRm54+y/HLIbhIep9do8Ew=", "owner": "nix-community", "repo": "nixvim", - "rev": "341dbb1b5867adb95d75e6dabef6627eb0eae38e", + "rev": "c05ac01070425ed0797b1ff678dc690c333cea74", "type": "github" }, "original": {