gptel
gptel copied to clipboard
gptel-request wrong type argument
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!