branch: elpa/gptel commit 9caf7684c3a4182e173afe57fa06e53aafc53434 Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
gptel-openai: Simplify reasoning handling further * gptel-openai.el (gptel-curl--parse-stream): Simplify the reasoning handling for OpenAI-compatible APIs (#901). It now works as follows: - Look for :reasoning content. If found, capture it and do nothing else. - Otherwise, check if this is a reasoning model. - If it is, check if we are receiving non-empty content. - If we are, signal the end of the reasoning block. The last step sets :reasoning-block to t. The process filter handles closing out the reasoning handling and setting it to done. --- gptel-openai.el | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/gptel-openai.el b/gptel-openai.el index f81c1f2387..241a9b56ba 100644 --- a/gptel-openai.el +++ b/gptel-openai.el @@ -232,18 +232,15 @@ information if the stream contains it." (push (plist-get func :arguments) (plist-get info :partial_json))))) ;; Check for reasoning blocks, currently only used by Openrouter (unless (eq (plist-get info :reasoning-block) 'done) - ;; We could also check for (plist-member delta :reasoning) - ;; here, but some APIs don't include it with content. (#901) - (if-let* ((reasoning-chunk (plist-get delta :reasoning)) ;for openrouter + (if-let* ((reasoning-chunk (plist-get delta :reasoning)) ;for Openrouter and co ((not (eq reasoning-chunk :null)))) (plist-put info :reasoning (concat (plist-get info :reasoning) reasoning-chunk)) ;; Done with reasoning if we get non-empty content - (if-let* ((c (plist-get delta :content)) + (if-let* (((plist-member info :reasoning)) ;Is this a reasoning model? + (c (plist-get delta :content)) ;Started receiving text content? ((not (or (eq c :null) (string-empty-p c))))) - (if (plist-member info :reasoning) ;Is this a reasoning model? - (plist-put info :reasoning-block t) ;End of streaming reasoning block - (plist-put info :reasoning-block 'done))))))))) ;Not using a reasoning model + (plist-put info :reasoning-block t)))))))) ;Signal end of reasoning block (error (goto-char (match-beginning 0)))) (apply #'concat (nreverse content-strs))))