From 66d2bafad6a6f51d4e4e015db7e66c5eae319a17 Mon Sep 17 00:00:00 2001 From: Karthik Chikmagalur Date: Tue, 7 Nov 2023 22:37:59 -0800 Subject: [PATCH] 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. --- gptel-ollama.el | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/gptel-ollama.el b/gptel-ollama.el index dac5e8c..d3afd46 100644 --- a/gptel-ollama.el +++ b/gptel-ollama.el @@ -76,20 +76,23 @@ Ollama models.") prompts-plist)) (cl-defmethod gptel--parse-buffer ((_backend gptel-ollama) &optional _max-entries) - (let ((prompts) (prop)) - (setq prop (text-property-search-backward - 'gptel 'response - (when (get-char-property (max (point-min) (1- (point))) - 'gptel) - t))) - (if (prop-match-value prop) + (let ((prompts) + (prop (text-property-search-backward + 'gptel 'response + (when (get-char-property (max (point-min) (1- (point))) + 'gptel) + t)))) + (if (and (prop-match-p prop) + (prop-match-value prop)) (user-error "No user prompt found!") (setq prompts (list :system gptel--system-message :prompt - (string-trim (buffer-substring-no-properties (prop-match-beginning prop) - (prop-match-end prop)) - "[*# \t\n\r]+")))))) + (if (prop-match-p prop) + (string-trim (buffer-substring-no-properties (prop-match-beginning prop) + (prop-match-end prop)) + "[*# \t\n\r]+") + "")))))) ;;;###autoload (cl-defun gptel-make-ollama