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 and automatically inserting the appropriate
-directive at the beginning of the current buffer in Emacs.
+and prompt.
-Adjust *~/.config/alyverkko-cli/prompts/* to point to your prompts
-directory.
+When function is invoked, it detects available prompts and allows user
+to select one.
+
+Thereafter function detects available models from Älyverkko CLI
+configuration file and allows user to select one.
+
+Finally function inserts at the beginning of currently opened file
+something like this:
+
+: TOCOMPUTE: prompt=<user-chosen-prompt> model=<user-chosen-model>
+
+- Adjust *prompt-dir* variable to point to your prompts directory.
+- Adjust *config-file* variable to point to your Älyverkko CLI
+ configuration file path.
+
+#+begin_src emacs-lisp
-#+begin_src elisp :results none
(defun alyverkko-compute ()
- "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)))
+ "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
+ (goto-char (point-min))
+ (insert (format "TOCOMPUTE: prompt=%s model=%s\n" prompt-alias model))
+ (save-buffer)))
#+end_src
* TODO