1
0
Fork 0

Prompts may be functions returning text

This can be used to make an interactive variant of a prompt and a
non-interactive one.
This commit is contained in:
Bram Schoenmakers 2024-03-31 17:43:20 +02:00
parent 48d90f7208
commit b0e33aa8e6
Signed by: bram
GPG key ID: 0CCD19DFDC63258F

22
kagi.el
View file

@ -76,7 +76,6 @@ https://kagi.com/settings?p=api"
(defvar kagi--fastgpt-prompts '()
"List of prompts that were defined with `define-kagi-fastgpt-prompt'.")
;; TODO prompt could be a function, call it
(defmacro define-kagi-fastgpt-prompt (name symbol-name prompt)
"Define a command SYMBOL-NAME that executes the given PROMPT.
@ -92,12 +91,15 @@ called interactively, to select the corresponding prompt."
(push (cons ,name ,prompt) kagi--fastgpt-prompts)
(defun ,symbol-name (text &optional interactive-p)
(interactive (list (kagi--get-text-for-prompt) t))
(kagi-fastgpt-prompt
(kagi--fastgpt-expand-prompt-placeholders
,prompt
(lambda () text))
nil
interactive-p))))
(let ((prompt-template (if (functionp ,prompt)
(funcall ,prompt interactive-p)
,prompt)))
(kagi-fastgpt-prompt
(kagi--fastgpt-expand-prompt-placeholders
prompt-template
(lambda () text))
nil
interactive-p)))))
(defvar kagi--summarizer-engines
'(("agnes" . "Friendly, descriptive, fast summary.")
@ -533,11 +535,11 @@ result is short, otherwise it is displayed in a new buffer."
text)))
(kagi-fastgpt-prompt prompt nil interactive-p)))
;; TODO interactive vs non-interactive "say OK"
(define-kagi-fastgpt-prompt "Proofread" kagi-proofread
"Proofread the following text:
(lambda (interactive-p)
(format "Proofread the following text. %s
%s")
%%s" (if interactive-p "" "Say OK if there are no issues."))))
;;; Summarizer