From 2fd6f65d68c68166888fcb67cd130b51a87f977d Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Tue, 4 Jun 2024 23:50:38 +0300 Subject: [PATCH] Moved prompts from config YAML to dedicated files --- doc/index.org | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/doc/index.org b/doc/index.org index 52041a6..88a1de5 100644 --- a/doc/index.org +++ b/doc/index.org @@ -549,37 +549,32 @@ 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. +a specific prompt and automatically inserting the appropriate +directive at the beginning of the current buffer in Emacs. + +Adjust *~/.config/alyverkko-cli/prompts/* to point to your prompts +directory. #+begin_src elisp :results none (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/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))) + "Select a prompt file name interactively and insert it at the beginning of the current buffer." + (interactive) + (let ((prompt-dir "~/.config/alyverkko-cli/prompts/")) + (if (file-exists-p prompt-dir) + (let* ((files (directory-files prompt-dir t "\\`[^.].*\\.txt\\'")) ; Filter to include only .txt files, ignoring hidden files + (aliases (mapcar (lambda (f) (file-name-base f)) files))) + (if aliases + (let ((selected-alias (completing-read "Select prompt alias: " aliases))) + (alyverkko-insert-tocompute-line selected-alias)) + (message "No prompt files found."))) + (message "Prompt directory not 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 -- 2.20.1