gptel-ollama: Fix buffer parsing

* gptel-ollama.el (gptel--parse-buffer): The prompt construction
for Ollama fails when starting from (point-min).  Fix by checking
if a valid text-property match object is found in the parsing.
This commit is contained in:
Karthik Chikmagalur 2023-11-07 22:37:59 -08:00
parent 57a70c23cb
commit 66d2bafad6

View file

@ -76,20 +76,23 @@ Ollama models.")
prompts-plist)) prompts-plist))
(cl-defmethod gptel--parse-buffer ((_backend gptel-ollama) &optional _max-entries) (cl-defmethod gptel--parse-buffer ((_backend gptel-ollama) &optional _max-entries)
(let ((prompts) (prop)) (let ((prompts)
(setq prop (text-property-search-backward (prop (text-property-search-backward
'gptel 'response 'gptel 'response
(when (get-char-property (max (point-min) (1- (point))) (when (get-char-property (max (point-min) (1- (point)))
'gptel) 'gptel)
t))) t))))
(if (prop-match-value prop) (if (and (prop-match-p prop)
(prop-match-value prop))
(user-error "No user prompt found!") (user-error "No user prompt found!")
(setq prompts (list (setq prompts (list
:system gptel--system-message :system gptel--system-message
:prompt :prompt
(string-trim (buffer-substring-no-properties (prop-match-beginning prop) (if (prop-match-p prop)
(prop-match-end prop)) (string-trim (buffer-substring-no-properties (prop-match-beginning prop)
"[*# \t\n\r]+")))))) (prop-match-end prop))
"[*# \t\n\r]+")
""))))))
;;;###autoload ;;;###autoload
(cl-defun gptel-make-ollama (cl-defun gptel-make-ollama