1
0
Fork 0

Explain a prompt text generated by a function

This commit is contained in:
Bram Schoenmakers 2024-04-10 18:16:48 +02:00
parent 2252dc0451
commit 3bb896cfa8
Signed by: bram
GPG key ID: 0CCD19DFDC63258F
2 changed files with 24 additions and 1 deletions

View file

@ -143,6 +143,24 @@ The first argument is the name of the command that will be defined. The second a
The defined prompt becomes a typical Emacs command that takes one argument to fill the placeholder. You could bind the prompt command to a key, use it to integrate with Embark (see below) or to list all your prompts with a Hydra.
The prompt string may also be a function that returns the prompt
string. The function may take one argument: whether the command was
called interactively or not. This can be used to alter the prompt
based on how the command was called. E.g. a non-interactive version
could contain an instruction to say either /Yes/ or /No/. See
=kagi-proofread= for an example:
#+begin_src elisp
(define-kagi-fastgpt-prompt kagi-proofread
(lambda (interactive-p)
(format "Proofread the following text. %s
%%s" (if interactive-p "" "Say OK if there are no issues.")))
"Proofread")
#+end_src
Note the =%%s= notation, =format= turns it into =%s= which becomes the prompt placeholder.
** Embark integration
The kagi.el package can be integrated with [[https://github.com/oantolin/embark][Embark]]. Use it to easily summarize, translate or proofread a buffer, region or a URL. It can also be used to call your custom prompts with =define-kagi-fastgpt-prompt=.

View file

@ -79,7 +79,12 @@ https://kagi.com/settings?p=api"
(defmacro define-kagi-fastgpt-prompt (symbol-name prompt &optional name)
"Define a command SYMBOL-NAME that executes the given PROMPT.
PROMPT can be a string or a function returning a string.
PROMPT can be a string or a function returning a string. The
function may take one argument: whether the command was called
interactively or not. This can be used to alter the prompt based
on how the command was called. E.g. a non-interactive version
could contain an instruction to say either Yes or No. See
`kagi-proofread' for an example.
When PROMPT contains %s, it will be replaced with the region (if
active), the (narrowed) buffer content of the selected buffer or