Skip to content

Commit 9d32489

Browse files
committed
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)
1 parent 354c94a commit 9d32489

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

gptel-openai.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ information if the stream contains it."
231231
;; old tool block continues, so continue collecting arguments in :partial_json
232232
(push (plist-get func :arguments) (plist-get info :partial_json)))))
233233
;; Check for reasoning blocks, currently only used by Openrouter
234-
;; MAYBE: Should this be moved to a dedicated Openrouter backend?
235-
(unless (or (eq (plist-get info :reasoning-block) 'done)
236-
(not (plist-member delta :reasoning)))
234+
(unless (eq (plist-get info :reasoning-block) 'done)
235+
;; We could also check for (plist-member delta :reasoning)
236+
;; here, but some APIs don't include it with content. (#901)
237237
(if-let* ((reasoning-chunk (plist-get delta :reasoning)) ;for openrouter
238238
((not (eq reasoning-chunk :null))))
239239
(plist-put info :reasoning

0 commit comments

Comments
 (0)