Make changes to gptel-directives propagate into org-mode properties
I'm currently loading gptel as
(use-package gptel ;https://github.com/karthink/gptel
:ensure t :defer t
:custom
(gptel-default-mode 'org-mode)
(gptel-model 'claude-3-5-sonnet-20241022) ;See `gptel--anthropic-models'.
(gptel-directives
'((default
. "You are a large language model living in Emacs and a helpful assistant. Respond concisely.")
(programming
. "You are a large language model and a careful programmer.
Provide code and only code as output without any additional text, prompt or note.
When generating C code:
- Use as modern constructs as possible including the
ones part of the new upcoming C2Y standard that are available in the
most recent stable version of Clang.
When generating C-like languages like C, C++ and D:
- Formatting should use K&R style with tab character for indentation.
- Variables that aren't mutated after they have been
initialized (read-only)should be qualified with the attribute `const` as
in `const int x = 42`.
When generating D code strictly adhere to these rules:
- (member) function templates shall be qualified with _neither_ `pure`,
`nothrow`, `@safe`, _nor_ `@nogc`,
- formatting shall never insert a new-line before opening curly brace
ASCII character
.")
(writing
. "You are a large language model and a writing assistant. Respond concisely.")
(chat
. "You are a large language model and a conversation partner. Respond concisely.")))
:config
(dolist (hook '(org-mode-hook markdown-mode-hook))
(add-hook hook 'gptel-setup-hook:nordlow))
(add-hook 'gptel-post-response-functions
'gptel-post-response-adjust:nordlow)
(require 'gptel-gemini nil t)
(when (require 'gptel-anthropic nil t)
(setq gptel-backend (gptel-make-anthropic "Claude"
:stream t
:key anthropic-api-token)))
(global-set-key [(control c) (return)] 'gptel-send))
. How do I make new org-mode files choose the programming directive by default?
It would have been useful to able to specify system directive in call to
gptel-make-anthropic
above.
Currently new org-mode files insert
:GPTEL_SYSTEM: You are a large language model living in Emacs and a helpful assistant. Respond concisely.
when I want the programming directive to be inserted. Moreover is newlines automatically converted to \n when inserted into the org-mode file?
How do I make new org-mode files choose the programming directive by default?
Only org-mode files?
It would have been useful to able to specify system directive in call to gptel-make-anthropic above.
The system message is independent of the backend parameters and can be changed at any time, so it doesn't make sense to specify it with the gptel-make-* constructors.
Currently new org-mode files insert...
The active system message is written to the file when you save it. The default directive is active, so it is written.
Moreover is newlines automatically converted to \n when inserted into the org-mode file?
Newlines are converted to \\n (not \n). This is required for serializing Org properties. When they are read from the Org file the newlines are restored.
Similar to the first question: if I add to gptel-directives an entry like
(setopt gptel-directives
'((default . ....)
(my-directiveA . "blablabla")
....)))
how can I make newly created models use my-directiveA by default?
(You asked @nordlow : "Only org-mode files?" In my case, yes, at least for now).
As of now, what I am doing is modifying gptel-directives[1] and changing the default directive. That seems to work but I wonder if it is the best approach.
[1] More precisely, I am using use-package and I either set gpetl-directives in :custom, as in the example from @nordlow above, or use (setopt gptel-directives ....) in :init.
how can I make newly created models use my-directiveA by default?
As of now, what I am doing is modifying gptel-directives[1] and changing the default directive. That seems to work but I wonder if it is the best approach.
Yes, this is fine. You are free to modify the default directive in gptel-directives as you see fit. gptel's included directives are mere suggestions and really barebones, as you may have noticed.
As an alternative to setopt or :custom, you can also do
(setf (alist-get 'default gptel-directives) "blablabla")
Thanks a lot. I'll keep modifying gptel-directives. Since you mention
(setf (alist-get 'default gptel-directives) "blablabla")
is there any benefit compared to setopt or :custom? Is that a better option if we want to modify the directives depending on the backend or model? (I can do this from gptel-menu but I am not successful doing it programatically).