gptel: 自動載入 directory 內的 prompts

gptel 預設設定 directives (就是 system prompts)的方式很麻煩,必須把 prompts 直接打在配置文件內。

所以我寫了兩個 function ,可以自動載入特定目錄下所有的 prompts file (txt),並設定成 gptel-directives。

(defun yubai/read-directive-from-file (name directive-file)
  (with-temp-buffer
    (insert-file-contents directive-file)
    (setq directive-content (buffer-string))
    (add-to-list 'gptel-directives `(,name ,directive-content))))

(defun yubai/read-directives-from-directory (directives-directory)
  (setq gptel-directives '())
  (dolist (directive-file (directory-files-recursively directives-directory "\\.txt$"))
    (yubai/read-directive-from-file
     (intern (file-name-base directive-file))
     directive-file)))

;; 使用
(yubai/read-directives-from-directory "~/.emacs.d/misc/gptel-directives/")
5 个赞

可以参考下这个包 GitHub - jwiegley/gptel-prompts: Code to make it easier to manage many prompts in GPTel

3 个赞