branch: externals/llm
commit beb296ac3cc61b4e640622ac4f4ae50d9daefacf
Author: Andrew Hyatt <[email protected]>
Commit: GitHub <[email protected]>

    Fix breakage in Ollama streaming tool calls and incorrect capability (#225)
    
    This should fix https://github.com/ahyatt/llm/issues/224
---
 NEWS.org      |  2 ++
 llm-ollama.el | 14 +++++++-------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index d8e18eeb25..2bc2eb25a0 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,4 +1,6 @@
 * Version 0.28.3
+- Fixed breakage in Ollama streaming tool calling
+- Fixed incorrect Ollama streaming tool use capability reporting
 - Add Gemini 3 Flash
 * Version 0.28.2
 - Add Chat GPT post 5.0 series models, such as 5.1 and 5.2
diff --git a/llm-ollama.el b/llm-ollama.el
index 9725bd2fd4..c4eccdbe7d 100644
--- a/llm-ollama.el
+++ b/llm-ollama.el
@@ -267,11 +267,11 @@ These are just the text inside the tag, not the tag 
itself."))
                         (funcall receiver response)))))))
 
 (cl-defmethod llm-provider-collect-streaming-tool-uses ((_ llm-ollama) data)
-  (mapcar (lambda (fc) (let ((f-alist (cdr fc)))
-                         (make-llm-provider-utils-tool-use
-                          :name (assoc-default 'name f-alist)
-                          :args (assoc-default 'arguments f-alist))))
-          data))
+  ;; Ollama only supports one tool used at a time.
+  (when-let* ((f-alist (cdadr data)))
+    (list (make-llm-provider-utils-tool-use
+           :name (assoc-default 'name f-alist)
+           :args (assoc-default 'arguments f-alist)))))
 
 (cl-defmethod llm-name ((provider llm-ollama))
   (or (llm-ollama-chat-model provider)
@@ -282,7 +282,7 @@ These are just the text inside the tag, not the tag 
itself."))
                                         2048))
 
 (cl-defmethod llm-capabilities ((provider llm-ollama))
-  (append '(streaming streaming-tool-use json-response model-list)
+  (append '(streaming json-response model-list)
           (when (and (llm-ollama-embedding-model provider)
                      (let ((embedding-model (llm-models-match
                                              (llm-ollama-embedding-model 
provider))))
@@ -293,7 +293,7 @@ These are just the text inside the tag, not the tag 
itself."))
                       (chat-model (llm-models-match model))
                       (capabilities (llm-model-capabilities chat-model)))
             (append
-             (when (member 'tool-use capabilities) '(tool-use))
+             (when (member 'tool-use capabilities) '(tool-use 
streaming-tool-use))
              (seq-intersection capabilities '(image-input))))))
 
 (cl-defmethod llm-models ((provider llm-ollama))

Reply via email to