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:
parent
57a70c23cb
commit
66d2bafad6
1 changed files with 13 additions and 10 deletions
|
@ -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
|
||||||
|
(if (prop-match-p prop)
|
||||||
(string-trim (buffer-substring-no-properties (prop-match-beginning prop)
|
(string-trim (buffer-substring-no-properties (prop-match-beginning prop)
|
||||||
(prop-match-end prop))
|
(prop-match-end prop))
|
||||||
"[*# \t\n\r]+"))))))
|
"[*# \t\n\r]+")
|
||||||
|
""))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(cl-defun gptel-make-ollama
|
(cl-defun gptel-make-ollama
|
||||||
|
|
Loading…
Add table
Reference in a new issue