Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gptel-anthropic.el
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ TOOLS is a list of `gptel-tool' structs, which see."
for argspec = (copy-sequence arg)
for name = (plist-get arg :name) ;handled differently
for newname = (or (and (keywordp name) name)
(make-symbol (concat ":" name)))
(intern (concat ":" name)))
do ;ARGSPEC is ARG without unrecognized keys
(cl-remf argspec :name)
(cl-remf argspec :optional)
Expand Down
4 changes: 2 additions & 2 deletions gptel-gemini.el
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ TOOLS is a list of `gptel-tool' structs, which see."
:description (gptel-tool-description tool)
:parameters
(if (not (gptel-tool-args tool))
:null ;NOTE: Gemini wants :null if the function takes no args
:null ;NOTE: Gemini wants :null if the function takes no args
(list :type "object"
;; See the generic implementation for an explanation of this
;; transformation.
Expand All @@ -206,7 +206,7 @@ TOOLS is a list of `gptel-tool' structs, which see."
for argspec = (copy-sequence arg)
for name = (plist-get arg :name) ;handled differently
for newname = (or (and (keywordp name) name)
(make-symbol (concat ":" name)))
(intern (concat ":" name)))
do ;ARGSPEC is ARG without unrecognized keys
(cl-remf argspec :name)
(cl-remf argspec :optional)
Expand Down
23 changes: 18 additions & 5 deletions gptel-openai.el
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,15 @@ information if the stream contains it."
for spec = (plist-get tool-call :function)
collect (list :id (plist-get tool-call :id)
:name (plist-get spec :name)
:args (ignore-errors (gptel--json-read-string
(plist-get spec :arguments))))
:args (condition-case err
(gptel--json-read-string
(plist-get spec :arguments))
(error
(gptel--log 'error "Failed to parse tool call arguments for %s: %s\nArguments string: %s"
(plist-get spec :name)
(error-message-string err)
(plist-get spec :arguments))
nil)))
into call-specs
finally (plist-put info :tool-use call-specs)))
(when-let* ((response (gptel--json-read))
Expand Down Expand Up @@ -274,9 +281,15 @@ Mutate state INFO with response metadata."
(cl-loop ;Then capture the tool call data for running the tool
for tool-call across tool-calls ;replace ":arguments" with ":args"
for call-spec = (copy-sequence (plist-get tool-call :function))
do (ignore-errors (plist-put call-spec :args
(gptel--json-read-string
(plist-get call-spec :arguments))))
do (condition-case err
(plist-put call-spec :args
(gptel--json-read-string
(plist-get call-spec :arguments)))
(error
(gptel--log 'error "Failed to parse tool call arguments for %s: %s\nArguments string: %s"
(plist-get call-spec :name)
(error-message-string err)
(plist-get call-spec :arguments))))
(plist-put call-spec :arguments nil)
(plist-put call-spec :id (plist-get tool-call :id))
collect call-spec into tool-use
Expand Down
2 changes: 1 addition & 1 deletion gptel-request.el
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ implementation, used by OpenAI-compatible APIs and Ollama."
for argspec = (copy-sequence arg)
for name = (plist-get arg :name) ;handled differently
for newname = (or (and (keywordp name) name)
(make-symbol (concat ":" name)))
(intern (concat ":" name)))
do ;ARGSPEC is ARG without unrecognized keys
(cl-remf argspec :name)
(cl-remf argspec :optional)
Expand Down