karthink / gptel

A simple LLM client for Emacs
GNU General Public License v3.0
1.04k stars 113 forks source link

Adding directive argument to gptel-send; prompt presets #150

Open polhuang opened 6 months ago

polhuang commented 6 months ago

Amazing package. Thank you so much.

A small feature request: It would be great to allow for a directive argument within gptel-send to programmatically call gptel-send with a directive without using the transient menu.

Additionally, it'd be great to be able to save prompt presets - I might always want the default to use model X1 and max Y1 tokens, but have a custom directive use model X2 and Y2 tokens. A directive argument would solve this problem, as we could define these presets in custom functions.

karthink commented 6 months ago

A small feature request: It would be great to allow for a directive argument within gptel-send to programmatically call gptel-send with a directive without using the transient menu.

Check gptel-request and the wiki. LLM Interaction via the transient menu is implemented using gptel-request.

Additionally, it'd be great to be able to save prompt presets - I might always want the default to use model X1 and max Y1 tokens, but have a custom directive use model X2 and Y2 tokens. A directive argument would solve this problem, as we could define these presets in custom functions.

This is supported on a per-file basis right now. You can set whatever settings you need in a gptel buffer (Org or Markdown) and save the file to disk. When you open the file and turn on gptel-mode, the settings will be read from the stored properties.

Another way to do it right now is to define a command/function that sets whatever settings you need, and store this configuration as code. Example:

(defun my/gptel-preset-1 ()
  (interactive)
  (setq-local gptel-backend gptel--openai
              gptel-model "model-1"
              gptel--system-message (map-elt gptel-directives 'preset-1)
              gptel-max-tokens 500))

Then call my/gptel-preset-1 as required.

I could add a gptel-presets variable and a way to store/load them from the transient menu or programmatically, but I feel like between the composite structures gptel-backend and gptel-directives, gptel already has too much configuration. I would like to adhere to the "simple" part of "A simple LLM client for Emacs".

If you can think of a way of unifying the configuration, I'd be interested in implementing it.