nftable-migration
  1;;; config-llm.el --- -*- lexical-binding: t -*-
  2;;; Commentary:
  3;;; LLM configuration
  4;;; Code:
  5
  6(use-package copilot
  7  ;; :hook
  8  ;; (prog-mode . copilot-mode)
  9  ;; (markdown-mode . copilot-mode) ;; Enable this on-demand only
 10  ;; (text-mode . copilot-mode) ;; I may not want copilot in org-mode for example.
 11  ;; (log-edit-mode . copilot-mode)
 12  ;; (vc-git-log-edit-mode . copilot-mode)
 13  :bind
 14  (:map copilot-completion-map
 15        ("C-g" . copilot-clear-overlay)
 16        ("C-j" . copilot-next-completion)
 17        ("C-k" . copilot-previous-completion)
 18        ("M-RET" . copilot-accept-completion)
 19        ("C-f" . copilot-accept-completion)
 20        ("C-l" . copilot-panel-complete))
 21  :custom
 22  (copilot-idle-delay 1)
 23  (copilot-max-char -1)
 24  (copile-indent-offset-warning-disable t))
 25
 26(setq copilot-chat-commit-prompt "Here is the result of running `git diff --cached`. Based on this, suggest a **Conventional Commit message**. Ensure the message includes both a clear title describing the change and a body explaining the change. Do not invent anything new; just comprehend the diff and explain it.
 27
 28- Do not add extra markdown formatting.
 29- Always make sure the commit message is in markdown format.
 30- Do not include any additional text outside the commit message.
 31- Make sure the title is a max of 50 characters long and not more.
 32- The summaries need to be wrapped to 80 characters long and not more (or break the line).
 33- Avoid overused words and phrases often associated with AI-generated text. Do not use the following words: *delve, tapestry, vibrant, landscape, realm, embark, excels, vital, comprehensive, intricate, pivotal, moreover, arguably, notably.*
 34- Avoid the following phrases: *dive into, it’s important to note, it’s important to remember, certainly, here are, important to consider, based on the information provided, remember that, navigating the [landscape]/[complexities of], delving into the intricacies of, a testament to.*
 35- Do not include any generic AI disclaimers or self-references (e.g., \"As an AI language model...\").
 36
 37# Conventional Commits 1.0.0
 38
 39## Summary
 40
 41Conventional Commits is a specification for commit messages that follows these rules to ensure clarity and consistency:
 42
 43### Format
 44
 45`<type>[optional scope]: <description>`
 46
 47`[body]`
 48
 49### Types
 50
 511. **fix:** A bug fix correlating to a PATCH version.
 522. **feat:** A new feature correlating to a MINOR version.
 53
 54Other types include:
 55
 56- **build:** Changes to build systems or dependencies.
 57- **chore:** Maintenance tasks (e.g., dependency updates).
 58- **ci:** Changes to CI configuration.
 59- **refactor:** Code changes not adding features or fixing bugs.
 60- **test:** Changes to or addition of tests.
 61
 62Here is the result of `git diff --cached`:")
 63
 64(use-package copilot-chat
 65  :custom
 66  (copilot-chat-model "claude-3.7-sonnet")
 67  :bind
 68  (("C-c a c p" . copilot-chat-prompt-transient-menu)
 69   ("C-c a c c" . copilot-chat-insert-commit-message)
 70   ("C-c a c o" . copilot-chat-optimize)
 71   ("C-c a c m" . copilot-chat-set-model)
 72   ("C-c a c w" . my-copilot-chat-copy-source-block)
 73   ("C-c a c y" . copilot-chat-yank)
 74   ("C-c a c Y" . copilot-chat-yank-pop)
 75   ("C-c a c b" . copilot-chat-display)
 76   ("C-c a c a" . copilot-chat-switch-to-buffer)
 77   ("C-c a c f" . copilot-chat-custom-prompt-function)
 78   ("C-c a c s" . copilot-chat-custom-prompt-selection)
 79   (:map embark-general-map
 80	 ("M a d" . copilot-chat-doc)
 81	 ("M a e" . copilot-chat-explain)
 82	 ("M a o" . copilot-chat-optimize)
 83	 ("M a p" . copilot-chat-custom-prompt-selection)
 84	 ("M a r" . copilot-chat-review))
 85   (:map copilot-chat-prompt-mode-map
 86         ("C-M-w" . my-copilot-chat-copy-source-block)
 87         ("C-q" . delete-window)))
 88  :config
 89  (setq copilot-chat-prompts copilot-chat-markdown-prompt)
 90  (defun my-copilot-chat-copy-source-block ()
 91    "Copy the source block at point to kill ring."
 92    (interactive)
 93    (let* ((temp-buffer-name "*copilot-kr-temp*"))
 94      (with-current-buffer (get-buffer-create temp-buffer-name)
 95        (erase-buffer)
 96        (copilot-chat-yank)
 97        (kill-ring-save (point-min) (point-max))
 98        (kill-buffer))
 99      (message "Source block copied to kill ring")))
100
101  (defun copilot-chat-prompt-transient-menu ()
102    "Show a transient menu for Copilot Chat actions."
103    (interactive)
104    (unless (use-region-p)
105      (mark-defun))
106    (transient-define-prefix copilot-chat-prompt-menu ()
107      "Copilot Chat Menu"
108      ["Copilot Chat Actions"
109       ["Target"
110        ("c" "Commit" copilot-chat-insert-commit-message)
111        ("o" "Optimize" copilot-chat-optimize)
112        ("r" "Review" copilot-chat-review)
113        ("f" "Fix" copilot-chat-fix)
114        ("e" "Explain" copilot-chat-explain)
115        ("d" "Doc" copilot-chat-doc)]
116       ["Commands"
117        ("d" "Display chat" copilot-chat-display)
118        ("h" "Hide chat" copilot-chat-hide)
119        ("R" "Reset & reopen" (lambda ()
120                                (interactive)
121                                (copilot-chat-reset)
122                                (copilot-chat-display)))
123        ("x" "Reset" copilot-chat-reset)
124        ("g" "Go to buffer" copilot-chat-switch-to-buffer)
125        ("m" "Set model" copilot-chat-set-model)
126        ("q" "Quit" transient-quit-one)]
127       ["Actions"
128        ("p" "Custom prompt" copilot-chat-custom-prompt-selection)
129        ("i" "Ask and insert" copilot-chat-ask-and-insert)
130        ("m" "Insert commit message" copilot-chat-insert-commit-message)
131        ("b" "Buffers" copilot-chat-transient-buffers)]
132       ["Data"
133        ("y" "Yank last code block" copilot-chat-yank)
134        ("s" "Send code to buffer" copilot-chat-send-to-buffer)]])
135    (copilot-chat-prompt-menu))
136  :after (copilot embark)
137  :commands
138  (copilot-chat-mode))
139
140(use-package aidermacs
141  :bind (("C-c a a m" . aidermacs-transient-menu))
142  :custom
143  (aidermacs-use-architect-mode t)
144  (aidermacs-auto-commits nil)
145  :config
146  (aidermacs-setup-minor-mode))
147
148(use-package gptel
149  :commands (gptel gptel-mode)
150  :bind (("C-c a g" . gptel))
151  :hook
152  (gptel-mode . visual-line-mode)
153  :bind
154  (:map gptel-mode-map
155        ("C-c C-k" . gptel-abort)
156        ("C-c C-m" . gptel-menu)
157        ("C-c C-c" . gptel-send))
158  :custom
159  (gptel-default-mode #'markdown-mode)
160  :config
161  ;; (general-leader
162  ;;   "o"   '(:ignore t :wk "GPTel")
163  ;;   "o o" '(gptel :wk "Start GPTel")
164  ;;   "o m" '(gptel-menu :wk "GPTel menu"))
165  (setq mcp-hub-servers
166	`(("jira" :command "/home/vincent/src/github.com/chmouel/jayrah/.venv/bin/jayrah" :args ("mcp"))
167	  ("github" :command "github-mcp-server" :args ("stdio")
168	   :env (:GITHUB_PERSONAL_ACCESS_TOKEN ,(passage-get "github/vdemeester/github-mcp-server")))))
169  (require 'gptel-curl)
170  (require 'gptel-gemini)
171  (require 'gptel-ollama)
172  (require 'gptel-transient)
173  (require 'gptel-integrations)
174  (require 'gptel-rewrite)
175  (require 'gptel-org)
176  (require 'gptel-openai)
177  (require 'gptel-openai-extras)
178  (require 'gptel-autoloads)
179  (gptel-mcp-connect)
180  (setq gptel-model 'gemini-2.0-flash
181	gptel-backend (gptel-make-gemini "Gemini"
182			:key (passage-get "ai/gemini/api_key"))
183	)
184
185  (gptel-make-deepseek "Deepseek"
186		       :key  (passage-get "ai/deepseek/api_key")
187		       ;; :models '("deepseek-reasoner" "deepseek-chat" )
188		       )
189
190  (gptel-make-openai "MistralLeChat"
191    :host "api.mistral.ai/v1"
192    :endpoint "/chat/completions"
193    :protocol "https"
194    :key (passage-get "ai/mistralai/api_key")
195    :models '("mistral-small"))
196  
197  (gptel-make-openai "OpenRouter"
198    :host "openrouter.ai"
199    :endpoint "/api/v1/chat/completions"
200    :stream t
201    :key (passage-get "ai/openroute/api_key")
202    :models '(cognitivecomputations/dolphin3.0-mistral-24b:free
203	      cognitivecomputations/dolphin3.0-r1-mistral-24b:free
204	      deepseek/deepseek-r1-zero:free
205	      deepseek/deepseek-chat:free
206	      deepseek/deepseek-r1-distill-qwen-32b:free
207	      deepseek/deepseek-r1-distill-llama-70b:free
208	      google/gemini-2.0-flash-lite-preview-02-05:free
209	      google/gemini-2.0-pro-exp-02-05:free
210	      google/gemini-2.5-pro-exp-03-25
211	      google/gemini-2.5-pro-exp-03-25:free
212	      google/gemma-3-12b-it:free
213	      google/gemma-3-27b-it:free
214	      google/gemma-3-4b-it:free
215	      mistralai/mistral-small-3.1-24b-instruct:free
216	      open-r1/olympiccoder-32b:free
217	      qwen/qwen2.5-vl-3b-instruct:free
218	      qwen/qwen-2.5-coder-32b-instruct:free
219	      qwen/qwq-32b:free
220              codellama/codellama-70b-instruct
221              google/gemini-pro
222              google/palm-2-codechat-bison-32k
223              meta-llama/codellama-34b-instruct
224              mistralai/mixtral-8x7b-instruct
225	      openai/gpt-3.5-turbo))
226
227  (gptel-make-openai "Groq"
228    :host "api.groq.com"
229    :endpoint "/openai/v1/chat/completions"
230    :stream t
231    :key (passage-get "ai/groq/wakasu")
232    :models '("llama-3.3-70b-versatile"
233              "llama-3.1-70b-versatile"
234              "llama-3.1-8b-instant"
235              "llama3-70b-8192"
236              "llama3-8b-8192"
237              "deepseek-r1-distill-qwen-32b"
238              "deepseek-r1-distill-llama-70b-specdec"
239              "qwen-2.5-coder-32b"
240              "mixtral-8x7b-32768"
241              "gemma-7b-it"))
242  
243  (gptel-make-ollama "Ollama"
244    :host "localhost:11434"
245    :stream t
246    :models '("smollm:latest"
247              "llama3.1:latest"
248              "deepseek-r1:latest"
249              "mistral-small:latest"
250              "deepseek-r1:7b"
251              "nomic-embed-text:latest")))
252
253(use-package gptel-context
254  :after gptel
255  :config
256  ;; (general-leader
257  ;;   "o c" '(:ignore t :which-key "GPTel Context")
258  ;;   "o c a" 'gptel-context-add
259  ;;   "o c r" 'gptel-context-remove
260  ;;   "o c s" '(lambda ()
261  ;;              (interactive)
262  ;;              (gptel-context-remove-all nil)
263  ;;              (unless (use-region-p)
264  ;;                (mark-defun))
265  ;;              (gptel-context-add)
266  ;;              (my-switch-to-gptel-buffer)))
267  )
268
269(defun my-switch-to-gptel-buffer (&optional arg)
270  "Switch to the most recent buffer with gptel-mode enabled or start it."
271  (interactive "P")
272  (let (target-buffer)
273    (setq target-buffer (cl-find-if 
274                         (lambda (buf)
275                           (with-current-buffer buf
276                             (bound-and-true-p gptel-mode)))
277                         (buffer-list)))
278    (unless target-buffer
279      (call-interactively 'gptel))
280    (pop-to-buffer target-buffer)))
281
282(provide 'config-llm)
283;;; config-llm.el ends here