branch: elpa/gptel
commit 54ce1c3d26715414a014c67e3b9062d9997333ce
Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>

    gptel-curl: Handle Deepseek API variance (#709)
    
    * gptel-openai-extras.el (gptel-curl--parse-stream): Some deepseek
    model providers will stop supplying "reasoning_content" entries in
    the streaming response after the end of the reasoning block.  This
    breaks our check in `gptel-deepseek' to detect if we're working
    with a reasoning or non-reasoning model.  Fix by explicitly
    setting the :reasoning-block key in INFO to indicate that we're in
    a reasoning block, then use the value of :reasoning-block to
    determine if the model is reasoning-capable.
    
    * gptel-curl.el (gptel-curl--stream-filter):  Set :reasoning-block
    when reading reasoning content delivered via a separate JSON
    field (i.e. when it's not integrated in the main response stream.)
---
 gptel-curl.el          | 2 ++
 gptel-openai-extras.el | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/gptel-curl.el b/gptel-curl.el
index 11ced1fbe4..425d25aeee 100644
--- a/gptel-curl.el
+++ b/gptel-curl.el
@@ -338,6 +338,8 @@ Optional RAW disables text properties and transformation."
                  ((stringp reasoning)
                   ;; Obtained from separate JSON field in response
                   (funcall callback (cons 'reasoning reasoning) proc-info)
+                  (unless reasoning-block ;Record that we're in a reasoning 
block (#709)
+                    (plist-put proc-info :reasoning-block 'in))
                   (plist-put proc-info :reasoning nil)) ;Reset for next 
parsing round
                  ((and (null reasoning-block) (length> response 0))
                   (if (string-match-p "^ *<think>" response)
diff --git a/gptel-openai-extras.el b/gptel-openai-extras.el
index c9e0630747..078666cb7b 100644
--- a/gptel-openai-extras.el
+++ b/gptel-openai-extras.el
@@ -296,7 +296,7 @@ parameters."
                                (concat (plist-get info :reasoning) reasoning))
                   (when-let* ((content (plist-get delta :content))
                               ((not (eq content :null))))
-                    (if (plist-member delta :reasoning_content) ;Check for 
reasoning model
+                    (if (eq (plist-get info :reasoning-block) 'in) ;Check if 
in reasoning block
                         (plist-put info :reasoning-block t) ;End of streaming 
reasoning block
                       (plist-put info :reasoning-block 'done)) ;Not using a 
reasoning model
                     (throw 'done t)))))))))))

Reply via email to