From: Svjatoslav Agejenko Date: Mon, 27 May 2024 18:40:20 +0000 (+0300) Subject: Improve emacs helper function to start AI computation. X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=da5f5e850384333b16e60cdef4140ccfcf03e4f4;p=alyverkko-cli.git Improve emacs helper function to start AI computation. Emacs now parses Älyverkko CLI configuration file, discovers available prompts and allows user to choose prompt template for particular AI task. --- diff --git a/doc/index.org b/doc/index.org index 3cd03db..bbec1d0 100644 --- a/doc/index.org +++ b/doc/index.org @@ -549,18 +549,45 @@ file and open it for editing. #+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