From b31c9be5e01785212c79170bf93de8f9d3d273f1 Mon Sep 17 00:00:00 2001 From: Karthik Chikmagalur Date: Fri, 15 Mar 2024 22:27:10 -0700 Subject: [PATCH] gptel-ollama: Adjust Ollama stream parser for libjansson * gptel-ollama.el (gptel-curl--parse-stream): libjansson and json.el behave differently w.r.t moving point when there is a parsing error. Fix by explicitly handling point when there is an error. (#255) --- gptel-ollama.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gptel-ollama.el b/gptel-ollama.el index 5622136..00b40c9 100644 --- a/gptel-ollama.el +++ b/gptel-ollama.el @@ -45,10 +45,10 @@ Ollama models.") (when (bobp) (re-search-forward "^{") (forward-line 0)) - (let* ((content-strs) - (content)) + (let* ((content-strs) (content) (pt (point))) (condition-case nil (while (setq content (gptel--json-read)) + (setq pt (point)) (let ((done (map-elt content :done)) (response (map-elt content :response))) (push response content-strs) @@ -56,7 +56,7 @@ Ollama models.") (with-current-buffer (plist-get info :buffer) (setq gptel--ollama-context (map-elt content :context))) (goto-char (point-max))))) - (error (forward-line 0))) + (error (goto-char pt))) (apply #'concat (nreverse content-strs)))) (cl-defmethod gptel--parse-response ((_backend gptel-ollama) response info)