diff options
| author | ache <ache@ache.one> | 2024-07-21 05:30:30 +0200 |
|---|---|---|
| committer | ache <ache@ache.one> | 2024-07-21 05:30:30 +0200 |
| commit | d69c281f43ba4168df32ef4ae6b77f88bfc60d86 (patch) | |
| tree | 844fe20b45d099cbd35c1ccb3ae89dafb3da51a7 /lua/ache/plugins/llm | |
Init commit
Diffstat (limited to 'lua/ache/plugins/llm')
| -rw-r--r-- | lua/ache/plugins/llm/gen.lua | 47 | ||||
| -rw-r--r-- | lua/ache/plugins/llm/llm.lua_ | 23 | ||||
| -rw-r--r-- | lua/ache/plugins/llm/model.lua | 81 | ||||
| -rw-r--r-- | lua/ache/plugins/llm/ollama.lua_ | 44 | ||||
| -rw-r--r-- | lua/ache/plugins/llm/ollamachad.lua_ | 35 | ||||
| -rw-r--r-- | lua/ache/plugins/llm/tabby.lua_ | 23 |
6 files changed, 253 insertions, 0 deletions
diff --git a/lua/ache/plugins/llm/gen.lua b/lua/ache/plugins/llm/gen.lua new file mode 100644 index 0000000..482ffa7 --- /dev/null +++ b/lua/ache/plugins/llm/gen.lua @@ -0,0 +1,47 @@ +return { + "David-Kunz/gen.nvim", + enabled = false, + cmd = { "Gen" }, + opts = { + host = "box.ache.one", -- The host running the Ollama service. + port = "1080", -- The port on which the Ollama service is listening. + quit_map = "q", -- set keymap for close the response window + retry_map = "wc-rw", -- set keymap to re-send the current prompt + init = function(_) + -- pcall(io.popen, "ollama serve > /dev/null 2>&1 &") + end, + -- Function to initialize Ollama + command = function(options) + local body = { model = options.model, stream = true } + return "curl -u 'cecca:rouge_et_hedy<3' --basic --silent --no-buffer -X POST https://" + .. options.host + .. ":" + .. options.port + .. "/ollama/api/chat -d $body" + end, + -- The command for the Ollama service. You can use placeholders $prompt, $model and $body (shellescaped). + -- This can also be a command string. + -- The executed command must return a JSON object with { response, context } + -- (context property is optional). + -- list_models = '<omitted lua function>', -- Retrieves a list of model names + display_mode = "float", -- The display mode. Can be "float" or "split" or "horizontal-split". + show_prompt = false, -- Shows the prompt submitted to Ollama. + show_model = false, -- Displays which model you are using at the beginning of your chat session. + no_auto_close = false, -- Never closes the window automatically. + debug = false, -- Prints errors and the command which is run. + }, + config = function(_, opts) + local gen = require("gen") + gen.setup(opts) + + gen.prompts["Complete"] = { + prompt = "$text", + replace = true, + } + gen.prompts["Improove"] = { + prompt = "Améliore ce texte de manière à le rendre formel mais amical:\n\n$text\n", + -- replace = true, + model = "MathiasB/llama3fr:latest", + } + end, +} diff --git a/lua/ache/plugins/llm/llm.lua_ b/lua/ache/plugins/llm/llm.lua_ new file mode 100644 index 0000000..6e0e6ff --- /dev/null +++ b/lua/ache/plugins/llm/llm.lua_ @@ -0,0 +1,23 @@ +return { + "huggingface/llm.nvim", + enabled = false, + opts = { + backend = "ollama", + model = "codestral:latest", + url = "http://192.168.1.11:11434/", -- llm-ls uses "/api/generate" + -- cf https://github.com/ollama/ollama/blob/main/docs/api.md#parameters_doc + -- Function that print fibonacci numbers: + -- tec = + + request_body = { + -- Modelfile options for the model you use + options = { + temperature = 0.2, + top_p = 0.95, + }, + }, + lsp = { + bin_path = vim.api.nvim_call_function("stdpath", { "data" }) .. "/mason/bin/llm-ls", + }, + }, +} diff --git a/lua/ache/plugins/llm/model.lua b/lua/ache/plugins/llm/model.lua new file mode 100644 index 0000000..20ccb10 --- /dev/null +++ b/lua/ache/plugins/llm/model.lua @@ -0,0 +1,81 @@ +return { + "gsuuon/model.nvim", + enabled = true, + + -- Don't need these if lazy = false + cmd = { "M", "Model", "Mchat" }, + init = function() + vim.filetype.add({ + extension = { + mchat = "mchat", + }, + }) + end, + ft = "mchat", + + keys = { + { "<C-m>d", ":Mdelete<cr>", mode = "n" }, + { "<C-m>s", ":Mselect<cr>", mode = "n" }, + { "<C-m><space>", ":Mchat<cr>", mode = "n" }, + }, + config = function(_, opts) + local ollama = require("model.providers.ollama") + local model = require("model") + local starters = require("model.prompts.chats") + local qflist = require("model.util.qflist") + + model.setup({ + chats = { + ["codellama:qfix"] = vim.tbl_deep_extend("force", starters["together:codellama"], { + system = "You are an intelligent programming assistant", + create = function() + return qflist.get_text() + end, + }), + ["ollama:mistral"] = vim.tbl_deep_extend("force", starters["ollama:starling"], {}), + }, + prompts = { + ["ollama:starling"] = { + provider = ollama, + params = { + model = "starling-lm", + }, + builder = function(input) + return { + prompt = "GPT4 Correct User: " .. input .. "<|end_of_turn|>GPT4 Correct Assistant: ", + } + end, + }, + ["ollama:mistral"] = { + provider = ollama, + params = { + model = "mistral", + }, + builder = function(input) + return { + prompt = input, + params = { + model = "mistral", + }, + } + end, + }, + }, + }) + end, + + -- To override defaults add a config field and call setup() + + -- config = function() + -- require('model').setup({ + -- prompts = {..}, + -- chats = {..}, + -- .. + -- }) + -- + -- require('model.providers.llamacpp').setup({ + -- binary = '~/path/to/server/binary', + -- models = '~/path/to/models/directory' + -- }) + --end +} diff --git a/lua/ache/plugins/llm/ollama.lua_ b/lua/ache/plugins/llm/ollama.lua_ new file mode 100644 index 0000000..3cfda80 --- /dev/null +++ b/lua/ache/plugins/llm/ollama.lua_ @@ -0,0 +1,44 @@ +return { + "nomnivore/ollama.nvim", + enabled = false, + dependencies = { + "nvim-lua/plenary.nvim", + "MunifTanjim/nui.nvim", + }, + + -- All the user commands added by the plugin + cmd = { "Ollama", "OllamaModel" }, + + keys = { + -- Sample keybind for prompt menu. Note that the <c-u> is important for selections to work properly. + { + "<leader>oo", + ":<c-u>lua require('ollama').prompt()<cr>", + desc = "ollama prompt", + mode = { "n", "v" }, + }, + + -- Sample keybind for direct prompting. Note that the <c-u> is important for selections to work properly. + { + "<leader>oG", + ":<c-u>lua require('ollama').prompt('Generate_Code')<cr>", + desc = "ollama Generate Code", + mode = { "n", "v" }, + }, + }, + + ---@type Ollama.Config + opts = { + -- your configuration overrides + url = "https://box.ache.one:1080/ollama", + prompts = { + Complete_this = { + prompt = "$sel", + input_label = "> ", + model = "mistral", + action = "display_replace", + extract = "$after", + }, + }, + }, +} diff --git a/lua/ache/plugins/llm/ollamachad.lua_ b/lua/ache/plugins/llm/ollamachad.lua_ new file mode 100644 index 0000000..9c1b01e --- /dev/null +++ b/lua/ache/plugins/llm/ollamachad.lua_ @@ -0,0 +1,35 @@ +return { + "Lommix/ollamachad.nvim", + enabled = false, + config = function() + --- this is the default, you do not need to call setup if you use the default endpoints + require("ollamachad").setup({ + generate_api_url = "https://box.ache.one:1080/ollama/api/generate", + chat_api_url = "https://box.ache.one:1080/ollama/api/chat", + keymap = { + -- send prompt + prompt = "<CR>", + -- close chat + close = "<Esc>", + -- clear chat + clear = "<C-n>", + -- tab between prompt and chat + tab = "<Tab>", + }, + }) + + -- local chat = require("ollamachad.chat") + local gen = require("ollamachad.generate") + local util = require("ollamachad.util") + + -- rewrite selected text in visual mode + vim.keymap.set("v", "<leader>cr", function() + local instruction = "Improove the following text in its original language: " + local request = { + model = "mistral", + prompt = instruction .. util.read_visiual_lines(), + } + gen.prompt(request) + end, { silent = true, desc = "Rewrite the selected text" }) + end, +} diff --git a/lua/ache/plugins/llm/tabby.lua_ b/lua/ache/plugins/llm/tabby.lua_ new file mode 100644 index 0000000..cdc8a2d --- /dev/null +++ b/lua/ache/plugins/llm/tabby.lua_ @@ -0,0 +1,23 @@ +-- vim.g.tabby_trigger_mode = "automatic" + +-- Accept with Tab +-- vim.g.tabby_keybinding_accept = "<Tab>" +-- +-- -- Trigger with Ctr + h +-- vim.g.tabby_keybinding_trigger_or_dismiss = "<c-h>" +-- vim.g.tabby_trigger_mode = "manual" +-- +-- -- Toggle auto mode with Ctr + x then <leader> +-- vim.keymap.set({ "i", "n" }, "<c-x><leader>", function() +-- if vim.g.tabby_trigger_mode == "manual" then +-- vim.g.tabby_trigger_mode = "auto" +-- else +-- vim.g.tabby_trigger_mode = "manual" +-- end +-- end) + +-- No configuration +return { + { "TabbyML/vim-tabby" }, + enabled = false, +} |