branch: externals/llm
commit 4e37417eb2d52d9c0ed43e6055a97bd752a6c333
Author: Andrew Hyatt <[email protected]>
Commit: GitHub <[email protected]>
Add more documentation for tool calling and a test for optional args (#296)
---
README.org | 16 ++++++++++------
llm-provider-utils-test.el | 23 +++++++++++++++++++++++
2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/README.org b/README.org
index bbdde9f19b9..4898deb37c7 100644
--- a/README.org
+++ b/README.org
@@ -311,16 +311,20 @@ The way to call tools is to attach a list of tools to the
=tools= slot in the pr
:tools
(list (llm-make-tool
:function
- (lambda (callback result)
- ;; In this example function the assumption is that the
- ;; callback will be called after processing the result is
- ;; complete.
- (notify-user-of-capital result callback))
+ (lambda (callback country)
+ ;; In this example function the assumption is that the callback will
+ ;; be called after processing the result is complete, and receives
+ ;; the result of the processing as an argument.
+ (funcall callback (my-capital-retriever country)))
:name "capital_of_country"
:description "Get the capital of a country."
:args '((:name "country"
:description "The country whose capital to look up."
- :type string))
+
+ :type string
+ ;; Default is nil. This will error if the argument is
+ ;; not provided.
+ :optional nil))
:async t)))
#'identity ;; No need to process the result in this example.
(lambda (_ err)
diff --git a/llm-provider-utils-test.el b/llm-provider-utils-test.el
index 50b27723323..e440502f34a 100644
--- a/llm-provider-utils-test.el
+++ b/llm-provider-utils-test.el
@@ -337,5 +337,28 @@
(should (equal type 'llm-tool-missing-argument))
(should (stringp msg)))))
+(ert-deftest llm-provider-utils-execute-tool-uses--missing-optional-arg ()
+ (llm-provider-utils-execute-tool-uses
+ (make-llm-testing-provider)
+ (llm-make-chat-prompt
+ ""
+ :tools (list
+ (llm-make-tool
+ :name "tool-a"
+ :description "Tool A"
+ :function (lambda (&rest args) "Result A")
+ :args '((:name "arg1" :type string :description "Argument 1"
:optional t)))))
+ (list
+ (make-llm-provider-utils-tool-use
+ :id "1"
+ :name "tool-a"
+ :args '()))
+ nil
+ nil
+ #'ignore
+ (lambda (type msg)
+ (ert-fail (format "Should not error: %s %s" type msg)))))
+
+
(provide 'llm-provider-utils-test)
;;; llm-provider-utils-test.el ends here