From 9b6463240c8790f45ed5dfdfe28600fc10bee527 Mon Sep 17 00:00:00 2001 From: jasmine Date: Sun, 28 Sep 2025 22:12:29 +0800 Subject: [PATCH] setup codecompanion with ollama models --- config/default.nix | 1 + config/plugins/cmp/codecompanion.nix | 201 +++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 config/plugins/cmp/codecompanion.nix diff --git a/config/default.nix b/config/default.nix index ed1e517..22b3be3 100644 --- a/config/default.nix +++ b/config/default.nix @@ -17,6 +17,7 @@ # Completion & AI Assistancee ./plugins/cmp/cmp.nix + ./plugins/cmp/codecompanion.nix # Editor Enhancements ./plugins/editor/commentary.nix diff --git a/config/plugins/cmp/codecompanion.nix b/config/plugins/cmp/codecompanion.nix new file mode 100644 index 0000000..96b3c84 --- /dev/null +++ b/config/plugins/cmp/codecompanion.nix @@ -0,0 +1,201 @@ +{...}: { + plugins.codecompanion = { + enable = true; + + # Settings for the CodeCompanion plugin + settings = { + # Display options for the chat interface + display = { + chat.window = { + layout = "vertical"; + position = "right"; + width = 0.33; + }; + }; + + # Adapters for different backends + adapters = { + http = { + "ollama:qwen2.5-coder" = { + __raw = '' + function() + return require('codecompanion.adapters').extend('ollama', { + name = "ollama:qwen2.5-coder", + env = { + url = "http://127.0.0.1:11434", + }, + schema = { + model = { + default = 'qwen2.5-coder:7b', + }, + num_ctx = { + default = 32768, + }, + }, + }) + end + ''; + }; + + "ollama:deepseek-r1" = { + __raw = '' + function() + return require('codecompanion.adapters').extend('ollama', { + name = "ollama:deepseek-r1", + env = { + url = "http://127.0.0.1:11434", + }, + schema = { + model = { + default = 'deepseek-r1:8b', + }, + num_ctx = { + default = 131072, + }, + }, + }) + end + ''; + }; + + "ollama:gemma3" = { + __raw = '' + function() + return require('codecompanion.adapters').extend('ollama', { + name = "ollama:gemma3", + env = { + url = "http://127.0.0.1:11434", + }, + schema = { + model = { + default = 'gemma3:4b', + }, + num_ctx = { + default = 131072, + }, + }, + }) + end + ''; + }; + + "ollama:qwen3" = { + __raw = '' + function() + return require('codecompanion.adapters').extend('ollama', { + name = "ollama:qwen3", + env = { + url = "http://127.0.0.1:11434", + }, + schema = { + model = { + default = 'qwen3:8b', + }, + num_ctx = { + default = 40960, + }, + }, + }) + end + ''; + }; + + "ollama:llama3" = { + __raw = '' + function() + return require('codecompanion.adapters').extend('ollama', { + name = "ollama:llama3", + env = { + url = "http://127.0.0.1:11434", + }, + schema = { + model = { + default = 'llama3:8b', + }, + num_ctx = { + default = 8192, + }, + }, + }) + end + ''; + }; + + # Options for the HTTP protocol + opts = { + # Enable or disable displaying default adapters + show_defaults = false; + }; + }; + + # Options for the ACP protocol + acp = { + opts = { + # Enable or disable displaying default adapters + show_defaults = false; + }; + }; + }; + + # Global options for CodeCompanion + opts = { + log_level = "TRACE"; + send_code = true; + use_default_actions = true; + use_default_prompts = true; + }; + + # Strategies for different interaction modes + strategies = { + agent = { + adapter = "ollama:qwen2.5-coder"; + }; + chat = { + adapter = "ollama:qwen2.5-coder"; + }; + inline = { + adapter = "ollama:qwen2.5-coder"; + }; + }; + }; + }; + + # Keymaps for accessing CodeCompanion functionalities + keymaps = [ + { + mode = ["n" "v"]; + key = "c"; + action = ""; + options = { + desc = "+companion"; + }; + } + + { + mode = ["n" "v"]; + key = "cA"; + action = "CodeCompanionActions"; + options = { + desc = "Open actions"; + }; + } + + { + mode = ["n" "v"]; + key = "cc"; + action = "CodeCompanionChat Toggle"; + options = { + desc = "Toggle chat"; + }; + } + + { + mode = ["v"]; + key = "ca"; + action = "CodeCompanionChat Add"; + options = { + desc = "Add selection to chat"; + }; + } + ]; +}