Finally function inserts at the beginning of currently opened file
something like this:
-: TOCOMPUTE: prompt=<user-chosen-prompt> model=<user-chosen-model>
+: TOCOMPUTE: prompt=<chosen-prompt> model=<chosen-model> priority=<chosen-priority>
- Adjust *prompt-dir* variable to point to your prompts directory.
- Adjust *config-file* variable to point to your Älyverkko CLI
#+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