gptel icon indicating copy to clipboard operation
gptel copied to clipboard

gptel-request wrong type argument

Open ppanko opened this issue 9 months ago • 10 comments

Hello, thank you for the wonderful package. I am running into an error attempting to run a function that uses gptel-request (using Windows 11 OS). Here is my config setup:

  (use-package gptel
    :config
    ;; Set the default model to use
    (setq-default gptel-model "gpt-3.5-turbo")
    ;; set API key
    (setq gptel-api-key "____________"))

  (defun gptel-rewrite-and-replace (bounds &optional directive)
    (interactive
     (list
      (cond
       ((use-region-p) (cons (region-beginning) (region-end)))
       ((derived-mode-p 'text-mode)
        (list (bounds-of-thing-at-point 'sentence)))
       (t (cons (line-beginning-position) (line-end-position))))
      (and current-prefix-arg
           (read-string "ChatGPT Directive: "
                        "You are a prose editor. Rewrite my prompt more professionally."))))
    (gptel-request
        (buffer-substring-no-properties (car bounds) (cdr bounds)) ;the prompt
      :system (or directive "You are a prose editor. Rewrite my prompt more professionally.")
      :buffer (current-buffer)
      :context (cons (set-marker (make-marker) (car bounds))
                     (set-marker (make-marker) (cdr bounds)))
      :callback
      (lambda (response info)
        (if (not response)
            (message "ChatGPT response failed with: %s" (plist-get info :status))
          (let* ((bounds (plist-get info :context))
                 (beg (car bounds))
                 (end (cdr bounds))
                 (buf (plist-get info :buffer)))
            (with-current-buffer buf
              (save-excursion
                (goto-char beg)
                (kill-region beg end)
                (insert response)
                (set-marker beg nil)
                (set-marker end nil)
                (message "Rewrote line. Original line saved to kill-ring."))))))))

The gptel-rewrite-and-replace function, which was borrowed from example 2 on the gptel wiki page, throws the following error:

error in process sentinel: gptel-curl--parse-response: Wrong type argument: stringp, nil
error in process sentinel: Wrong type argument: stringp, nil

gptel-send works just fine as does sending requests through curl directly. I can send the debug/log output if needed. Thanks in advance!

ppanko avatar May 21 '24 14:05 ppanko