#+end_src
***** Easily signal to AI that problem statement is ready for solving
-When *ai-compute* function is triggered, it inserts "TOCOMPUTE:" line
-at the beginning of file and saves it. Marking it for processing by
-AI.
+
+The function =alyverkko-compute= is designed to enhance the workflow
+of users working with the Älyverkko CLI application by automating the
+process of marking text files for computation with a specific AI model
+prompt. Älyverkko CLI applications can process vast amounts of data
+using language models, and typically require an indication of which
+processing prompt to use for each batch of text. This function
+streamlines the workflow by allowing the user to interactively select
+a specific prompt defined in the configuration file, and automatically
+inserting the appropriate directive at the beginning of the current
+buffer in Emacs.
#+begin_src elisp :results none
- (defun ai-compute ()
- "Inserts 'TOCOMPUTE:' at the beginning of the buffer."
- (interactive)
- (goto-char (point-min)) ; Move to the beginning of the buffer
- (insert "TOCOMPUTE:\n") ; Insert the string followed by a new line
- (save-buffer) ; Save the buffer
- )
+(defun alyverkko-compute ()
+ "Select a prompt alias interactively and insert it at the beginning of the current buffer."
+ (interactive)
+ (let ((config-file "~/.config/alyverkko-cli.yaml")
+ (aliases '()))
+ (with-temp-buffer
+ (insert-file-contents config-file)
+ ;; Move to the beginning of the prompts section
+ (goto-char (point-min))
+ (when (search-forward-regexp "^prompts:" nil t)
+ ;; Collect all aliases
+ (while (search-forward-regexp "^\\s-+- alias: \"\\([^\"]+\\)\"" nil t)
+ (push (match-string 1) aliases))))
+ ;; Let the user choose from the collected aliases
+ (if aliases
+ (let ((selected-alias (completing-read "Select prompt alias: " (reverse aliases))))
+ ;; now insert in original buffer
+ (alyverkko-insert-tocompute-line selected-alias))
+ (message "No prompts found."))))
+
+(defun alyverkko-insert-tocompute-line (prompt-alias)
+ "Inserts TOCOMPUTE line with selected PROMPT-ALIAS at the beginning of the buffer."
+ (save-excursion ; Preserve the original cursor location in the buffer
+ (goto-char (point-min))
+ (insert (format "TOCOMPUTE: prompt=%s\n" prompt-alias))
+ (save-buffer)))
#+end_src
* TODO