gregoryg / AIPIHKAL

AI (LLM) Prompts I Have Known And Loved
31 stars 5 forks source link

auto-loading gptel-build-directives with gptel during emacs startup #5

Closed alx closed 6 days ago

alx commented 1 week ago

Hi Gregory,

I'm trying to load the built system prompts as gptel directives when emacs is starting up, with the following configuration lines in my config.el loaded at startup:

(use-package! gptel
  :init
  (setq gptel-directives (gjg/gptel-build-directives "~/code/AIPIHKAL/system-prompts/"))
  :config
  (setq
   gptel-model 'claude-3-opus-20240229 ;  "claude-3-opus-20240229" also available
   gptel-backend (gptel-make-anthropic "Claude"
                   :stream t :key "sk-ant-..."
                   )))

I've tried various method without success, could you help me figure out how to do it?

Here is my dotfile repository and the line in the config.el file: https://github.com/alx/dots/blob/main/dotfiles/doom/config.el#L154

gregoryg commented 6 days ago

Hello, @alx !

Sorry I didn't see this yesterday!

In my config, I load the the gjg/gptel-build-directives function that is included in this AIPIKHAL repo. the poorly-named build-directives-fun symbol is just the path to the file where that function is defined.

If it is there, I load the file - this is the step I think you were missing.

From that point on, you can do what you were doing with setq gptel-directives

Note that I'm not doing it inside of use-package - just out of laziness.

Here's what my config looks like

;; Use the system prompt builder function
(let ((build-directives-fun "~/projects/ai/AIPIHKAL/gptel-build-directives.el"))
  (when (f-exists-p build-directives-fun)
    (load build-directives-fun)
    ;; (custom-set-variables '(gptel-directives
    (setq gptel-directives (gjg/gptel-build-directives "~/projects/ai/AIPIHKAL/system-prompts/")
          gptel-system-message (alist-get 'default gptel-directives))))
alx commented 6 days ago

Hello @gregoryg,

Thanks for your help, I was able to load my built prompt using your example.

In my Doom Emacs config.el:

(use-package! gptel
  :config
  (setq
   gptel-model 'claude-3-opus-20240229
   gptel-backend (gptel-make-anthropic "Claude"
                   :stream t :key "sk-ant-..."
                   ))
  (let ((build-directives-fun "~/code/AIPIHKAL/gptel-build-directives.el"))
    (when (file-exists-p build-directives-fun)
      (load build-directives-fun)
      ;; (custom-set-variables '(gptel-directives
      (setq gptel-directives (gjg/gptel-build-directives "~/code/AIPIHKAL/system-prompts/")
            gptel-system-message (alist-get 'default gptel-directives))))
  )

I had to change some function calls to make it work on my current emacs setup:

gregoryg commented 6 days ago

Your examples are super useful in showing how to use the world's most popular configuration framework for emacs. Maybe we can add a Doom setup section