branch: elpa/gptel commit a4edfbb2c3075a8dfab7897e1424c0795cdb567a Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
gptel-curl: Fix text handling around end of reasoning block * gptel-curl.el (gptel-curl--stream-filter): At the end of a reasoning block, the response string is non-nil but we end up treating it as reasoning because of the way <think>..</think>n blocks are handled. This causes the first chunk of the response to be painted as reasoning text. To fix this, we need a way to distinguish between the two kinds of reasoning blocks (separate reasoning field vs embedded as <think>..</think> blocks in the response). Use the fact that when reasoning text obtained from a reasoning_content (etc) field in the response, :reasoning-block is set to t to indicate the response stream has ended. --- gptel-curl.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gptel-curl.el b/gptel-curl.el index 018ff07a95..283aa5dea5 100644 --- a/gptel-curl.el +++ b/gptel-curl.el @@ -366,7 +366,7 @@ Optional RAW disables text properties and transformation." (progn (setq response (cons 'reasoning response)) (plist-put proc-info :reasoning-block 'in)) (plist-put proc-info :reasoning-block 'done))) - ((length> response 0) + ((and (not (eq reasoning-block t)) (length> response 0)) (if-let* ((idx (string-match-p "</think>" response))) (progn (funcall callback @@ -374,10 +374,9 @@ Optional RAW disables text properties and transformation." (string-trim-left (substring response nil (+ idx 8)))) proc-info) - ;; Signal end of reasoning stream - (funcall callback '(reasoning . t) proc-info) - (setq response (substring response (+ idx 8))) - (plist-put proc-info :reasoning-block 'done)) + (setq reasoning-block t) ;Signal end of reasoning stream + (plist-put proc-info :reasoning-block t) + (setq response (substring response (+ idx 8)))) (setq response (cons 'reasoning response))))) (when (eq reasoning-block t) ;End of reasoning block (funcall callback '(reasoning . t) proc-info)