branch: elpa/gptel
commit b068edb808bb17df90900038949e33da5638b15c
Author: Ragnar Dahlén <r.dah...@gmail.com>
Commit: GitHub <nore...@github.com>

    gptel-openai: Prevent null tool-calls from causing error (#830)
    
    * gptel-openai.el (gptel--parse-response): Ensure that tool-calls
     are processed only if they are not null. This issue was
     discovered when using LiteLLM, and is possibly an implementation
    JK bug there. This differs from the real OpenAI.com API, which
     doesn't have this issue. However, for gptel to be usable with
     LiteLLM, this check is necessary.
---
 gptel-openai.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gptel-openai.el b/gptel-openai.el
index 5de95d709d..69f3ce7cd0 100644
--- a/gptel-openai.el
+++ b/gptel-openai.el
@@ -260,7 +260,8 @@ Mutate state INFO with response metadata."
     ;; OpenAI returns either non-blank text content or a tool call, not both.
     ;; However OpenAI-compatible APIs like llama.cpp can include both (#819), 
so
     ;; we check for both tool calls and responses independently.
-    (when-let* ((tool-calls (plist-get message :tool_calls)))
+    (when-let* ((tool-calls (plist-get message :tool_calls))
+                ((not (eq tool-calls :null))))
       (gptel--inject-prompt        ; First add the tool call to the prompts 
list
        (plist-get info :backend) (plist-get info :data) message)
       (cl-loop             ;Then capture the tool call data for running the 
tool

Reply via email to