branch: elpa/gptel commit 9d324892d033b7e65f6db6b68dc061dcc921463f Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
gptel-openai: Refine reasoning block detection in stream parser * gptel-openai.el (gptel-curl--parse-stream): Previously the stream parser assumed that all streaming chunks in a response from a streaming model would have the :reasoning field, even if its value was null. Post-reasoning content blocks would then have a (possibly null) :reasoning field and a non-null :content field. Reasoning block processing depended partially on this assumption. Use only the value of :reasoning-block instead. This implies a little extra work on the very first streaming chunk, but makes fewer assumptions about the presence of both :reasoning and :content fields in all future chunks. (#901) --- gptel-openai.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gptel-openai.el b/gptel-openai.el index 689c715330..f81c1f2387 100644 --- a/gptel-openai.el +++ b/gptel-openai.el @@ -231,9 +231,9 @@ information if the stream contains it." ;; old tool block continues, so continue collecting arguments in :partial_json (push (plist-get func :arguments) (plist-get info :partial_json))))) ;; Check for reasoning blocks, currently only used by Openrouter - ;; MAYBE: Should this be moved to a dedicated Openrouter backend? - (unless (or (eq (plist-get info :reasoning-block) 'done) - (not (plist-member delta :reasoning))) + (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 ((not (eq reasoning-chunk :null)))) (plist-put info :reasoning