From dc2ab927cf5e92087746d925dff284f8958d1230 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 15 Jun 2025 12:57:45 +0300 Subject: [PATCH] Emacs helper utility supports priority selection --- doc/index.org | 73 +++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/doc/index.org b/doc/index.org index 15a90db..9af7b89 100644 --- a/doc/index.org +++ b/doc/index.org @@ -316,7 +316,7 @@ configuration file and allows user to select one. Finally function inserts at the beginning of currently opened file something like this: -: TOCOMPUTE: prompt= model= +: TOCOMPUTE: prompt= model= priority= - Adjust *prompt-dir* variable to point to your prompts directory. - Adjust *config-file* variable to point to your Älyverkko CLI @@ -324,41 +324,44 @@ something like this: #+begin_src emacs-lisp - (defun alyverkko-compute () - "Select a prompt and a model interactively, then insert them at the - beginning of the current buffer." - (interactive) - (let ((prompt-dir "~/.config/alyverkko-cli/prompts/") - (config-file "~/.config/alyverkko-cli/alyverkko-cli.yaml") - (models '()) - ) - - (with-temp-buffer - (insert-file-contents config-file) - ;; Move to the beginning of the prompts section - (goto-char (point-min)) - (when (search-forward-regexp "^models:" nil t) - ;; Collect all aliases - (while (search-forward-regexp "^\\s-+- alias: \"\\([^\"]+\\)\"" nil t) - (push (match-string 1) models)))) - - (if (file-exists-p prompt-dir) - (let* ((files (directory-files prompt-dir t "\\`[^.].*\\.txt\\'")) - (aliases (mapcar (lambda (f) (file-name-base f)) files))) - (if aliases - (let ((selected-alias (completing-read "Select prompt alias: " aliases)) - (model (completing-read "Select AI model: " models))) - (alyverkko-insert-tocompute-line selected-alias model)) - (message "No prompt files found."))) - (message "Prompt directory not found.")))) - - (defun alyverkko-insert-tocompute-line (prompt-alias model) - "Inserts TOCOMPUTE line with selected PROMPT-ALIAS and MODEL at the - beginning of the buffer." - (save-excursion +(defun alyverkko-compute () + "Interactively pick a prompt, model, and priority, then insert a +TOCOMPUTE line at the top of the current buffer. + +Adjust `prompt-dir` and `config-file` to match your setup." + (interactive) + (let ((prompt-dir "~/.config/alyverkko-cli/prompts/") + (config-file "~/.config/alyverkko-cli/alyverkko-cli.yaml") + models) + + ;; Harvest model aliases from the Älyverkko CLI config + (with-temp-buffer + (insert-file-contents config-file) (goto-char (point-min)) - (insert (format "TOCOMPUTE: prompt=%s model=%s\n" prompt-alias model)) - (save-buffer))) + (when (search-forward-regexp "^models:" nil t) + (while (search-forward-regexp "^\\s-+- alias: \"\\([^\"]+\\)\"" nil t) + (push (match-string 1) models)))) + + (if (file-exists-p prompt-dir) + (let* ((files (directory-files prompt-dir t "\\`[^.].*\\.txt\\'")) + (aliases (mapcar #'file-name-base files))) + (if aliases + (let* ((selected-alias (completing-read "Select prompt alias: " aliases)) + (model (completing-read "Select AI model: " models)) + (priority (number-to-string + (read-number "Priority (integer, default 0): " 0)))) + (alyverkko-insert-tocompute-line selected-alias model priority)) + (message "No prompt files found."))) + (message "Prompt directory not found.")))) + +(defun alyverkko-insert-tocompute-line (prompt-alias model &optional priority) + "Insert a TOCOMPUTE line with PROMPT-ALIAS, MODEL, and PRIORITY at +the top of the current buffer." + (save-excursion + (goto-char (point-min)) + (insert (format "TOCOMPUTE: prompt=%s model=%s priority=%s\n" + prompt-alias model (or priority "0"))) + (save-buffer))) #+end_src * Getting the source code -- 2.20.1