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)
This commit is contained in:
parent
73a0cc25ba
commit
b31c9be5e0
1 changed files with 3 additions and 3 deletions
|
@ -45,10 +45,10 @@ Ollama models.")
|
||||||
(when (bobp)
|
(when (bobp)
|
||||||
(re-search-forward "^{")
|
(re-search-forward "^{")
|
||||||
(forward-line 0))
|
(forward-line 0))
|
||||||
(let* ((content-strs)
|
(let* ((content-strs) (content) (pt (point)))
|
||||||
(content))
|
|
||||||
(condition-case nil
|
(condition-case nil
|
||||||
(while (setq content (gptel--json-read))
|
(while (setq content (gptel--json-read))
|
||||||
|
(setq pt (point))
|
||||||
(let ((done (map-elt content :done))
|
(let ((done (map-elt content :done))
|
||||||
(response (map-elt content :response)))
|
(response (map-elt content :response)))
|
||||||
(push response content-strs)
|
(push response content-strs)
|
||||||
|
@ -56,7 +56,7 @@ Ollama models.")
|
||||||
(with-current-buffer (plist-get info :buffer)
|
(with-current-buffer (plist-get info :buffer)
|
||||||
(setq gptel--ollama-context (map-elt content :context)))
|
(setq gptel--ollama-context (map-elt content :context)))
|
||||||
(goto-char (point-max)))))
|
(goto-char (point-max)))))
|
||||||
(error (forward-line 0)))
|
(error (goto-char pt)))
|
||||||
(apply #'concat (nreverse content-strs))))
|
(apply #'concat (nreverse content-strs))))
|
||||||
|
|
||||||
(cl-defmethod gptel--parse-response ((_backend gptel-ollama) response info)
|
(cl-defmethod gptel--parse-response ((_backend gptel-ollama) response info)
|
||||||
|
|
Loading…
Add table
Reference in a new issue