branch: elpa/gptel commit fdd4ede799fdcbdf16f064a5b720ca507bbddca8 Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
gptel-ollama: Handle combined tool calls and reasoning content * gptel-ollama.el (gptel--parse-response): Look for tool calls even when content is non-empty. (#908) * NEWS (New features and UI changes): Mention change. --- NEWS | 7 +++++++ gptel-ollama.el | 33 ++++++++++++++++----------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 9f49be8438..646bc6b9dc 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,12 @@ # -*- mode: org; -*- +* 0.9.9-pre + +** New features and UI changes + +- gptel now handles Ollama models that return both reasoning content + and tool calls in a single request. + * 0.9.8.5 2025-06-11 ** Breaking changes diff --git a/gptel-ollama.el b/gptel-ollama.el index a444303341..929e9c215a 100644 --- a/gptel-ollama.el +++ b/gptel-ollama.el @@ -74,23 +74,22 @@ Store response metadata in state INFO." (plist-put info :output-tokens (plist-get response :eval_count)) (let* ((message (plist-get response :message)) (content (plist-get message :content))) - (if (and content (not (or (eq content :null) (string-empty-p content)))) - content - (prog1 nil ; Look for tool calls only if no content - (when-let* ((tool-calls (plist-get message :tool_calls))) - ;; First add the tool call to the prompts list - (let* ((data (plist-get info :data)) - (prompts (plist-get data :messages))) - (plist-put data :messages (vconcat prompts `(,message)))) - ;; Then capture the tool call data for running the tool - (cl-loop - for tool-call across tool-calls ;replace ":arguments" with ":args" - for call-spec = (copy-sequence (plist-get tool-call :function)) - do (plist-put call-spec :args - (plist-get call-spec :arguments)) - (plist-put call-spec :arguments nil) - collect call-spec into tool-use - finally (plist-put info :tool-use tool-use))))))) + (when-let* ((tool-calls (plist-get message :tool_calls))) + ;; First add the tool call to the prompts list + (let* ((data (plist-get info :data)) + (prompts (plist-get data :messages))) + (plist-put data :messages (vconcat prompts `(,message)))) + ;; Then capture the tool call data for running the tool + (cl-loop + for tool-call across tool-calls ;replace ":arguments" with ":args" + for call-spec = (copy-sequence (plist-get tool-call :function)) + do (plist-put call-spec :args + (plist-get call-spec :arguments)) + (plist-put call-spec :arguments nil) + collect call-spec into tool-use + finally (plist-put info :tool-use tool-use))) + (when (and content (not (or (eq content :null) (string-empty-p content)))) + content))) (cl-defmethod gptel--request-data ((backend gptel-ollama) prompts) "JSON encode PROMPTS for sending to Ollama."