karthink / gptel

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

`gptel-menu` get `Debugger entered--Lisp error: (void-function gptel--sanitize-model)` #353

Open eval-exec opened 1 month ago

eval-exec commented 1 month ago

I bind "s-m" to gptel-menu, when I hit s-m, I got:

Debugger entered--Lisp error: (void-function gptel--sanitize-model)
  gptel--sanitize-model()
  gptel-menu()
  funcall-interactively(gptel-menu)
  command-execute(gptel-menu)

My gptel related configuration is:

(use-package
  gptel
  :demand t
  :bind
  ("s-m" . gptel-menu)
  :init

  ;; :hook
  ;; (
  ;;  (gptel-mode . (lambda()
  ;;                   (copilot-mode -1)
  ;;                   ))
  ;;  )
  :config
  (defun exec/gptel-send ()
    (interactive)
    ;; insert a space
    (insert " ")
    (evil-normal-state)
    (gptel-send))
  (general-define-key
   :keymaps
   'gptel-mode-map
   "C-<return>"
   'exec/gptel-send
   "C-c C-k"
   'gptel-abort)
  ;; (general-define-key "s-m" 'gptel-menu)

  ;; get first line content of ~/.config/openai_api_key/key.private file to gptel-api-key, without newline
  (setq
   gptel-api-key (exec/file-content "~/.config/openai_api_key/key.private")
   gptel-default-mode 'markdown-mode
   gptel-prompt-prefix-alist '((markdown-mode . "🥷: ") (org-mode . "* ") (text-mode . "🥷: "))
   gptel-directives '((default
                       .
                       "You are a large language model living in Emacs and a helpful assistant. Respond concisely. Your reponse paragraph should start with `🤖:: ` please")
                      (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.")
                      (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.")
                      (translator
                       .
                       "You are a translator, I send you text, you translate it to Chinese or English")))
  ;; Perplexity offers an OpenAI compatible API

  ;; OPTIONAL configuration
  (setq-default gptel-model "gpt-4o")
  ;; Perplexity offers an OpenAI compatible API
  (gptel-make-openai "Perplexity"         ;Any name you want
    :host "api.perplexity.ai"
    :key (exec/file-content "~/.config/perplexity/key.txt") ;can be a function that returns the key
    :endpoint "/chat/completions"
    :stream t
    :models '(;; has many more, check perplexity.ai
              "pplx-7b-chat"
              "pplx-70b-chat"
              "pplx-7b-online"
              "pplx-70b-online"))
  (gptel-make-ollama "Ollama"             ;Any name of your choosing
    :host "127.0.0.1:11434"               ;Where it's running
    :stream t                             ;Stream responses
    :models '("llama3.1" "llama3" "codellama"))          ;List of models
  (add-hook 'gptel-post-stream-hook 'gptel-auto-scroll)

  (transient-define-suffix gptel--suffix-rewrite-and-replace ()
    "Refactor region contents and replace it."
    :key "R"
    :description (lambda () (concat (gptel--refactor-or-rewrite) " in place"))
    (interactive)
    (let* ((prompt (buffer-substring-no-properties
                    (region-beginning) (region-end)))
           (stream gptel-stream)
           (gptel--system-message gptel--rewrite-message))
      (kill-region (region-beginning) (region-end))
      (open-line 1)
      (message "Original text saved to kill-ring.")
      (gptel-request prompt :stream stream :in-place t)))

  (cl-defun my/clean-up-gptel-refactored-code (beg end)
    "Clean up the code responses for refactored code in the current buffer.

The response is placed between BEG and END.  The current buffer is
guaranteed to be the response buffer."
    (when gptel-mode          ; Don't want this to happen in the dedicated buffer.
      (cl-return-from my/clean-up-gptel-refactored-code))
    (when (and beg end)
      (save-excursion
        (let ((contents
               (replace-regexp-in-string
                "\n*``.*\n*" ""
                (buffer-substring-no-properties beg end))))
          (delete-region beg end)
          (goto-char beg)
          (insert contents)
          )
        ;; Indent the code to match the buffer indentation if it's messed up.
        (indent-region beg end)
        (pulse-momentary-highlight-region beg end))))

  (add-hook 'gptel-post-response-functions #'my/clean-up-gptel-refactored-code)

  )

How can I assist in investigating this error? Thank you!

karthink commented 1 month ago

Not sure, gptel--sanitize-model is in gptel.el, which should be loaded when you (require 'gptel) (as your use-package block does). How did you install gptel?