branch: externals/ellama
commit 3ddbe73e862a3bb6f0bdfbf977602cab85fbdf5c
Merge: 644230178b 1b68caacf6
Author: Sergey Kostyaev <[email protected]>
Commit: GitHub <[email protected]>

    Merge pull request #362 from s-kostyaev/add_ask_user_tool
    
    Add ask_user tool for user clarification
---
 NEWS.org        |  7 +++++++
 ellama-tools.el | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ellama.el       |  2 +-
 3 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/NEWS.org b/NEWS.org
index 1cafe341bf..959fd2eab8 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,3 +1,10 @@
+* Version 1.10.4
+- Added a new tool called "ask_user" that allows the system to pose questions 
to
+  the user and receive clarifications.
+- Added a new tool to append content to files, including
+  ~ellama-tools-append-file-tool~ and ~ellama-tools-append-file-tool-confirm~.
+- Registered the new append file tool in ~ellama-tools-available~ with
+  appropriate arguments and description.
 * Version 1.10.3
 - Removed redundant checks for function arguments and streamlined the execution
   logic in ellama-tools.el, making the code more concise and maintainable by
diff --git a/ellama-tools.el b/ellama-tools.el
index e5f8e223c8..2eb1a1c194 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -255,6 +255,42 @@ otherwise."
                 :description
                 "Write CONTENT to the file located at the specified PATH."))
 
+(defun ellama-tools-append-file-tool (path content)
+  "Append CONTENT to the file located at the specified PATH."
+  (with-current-buffer (find-file-noselect path)
+    (goto-char (point-max))
+    (insert content)
+    (save-buffer)))
+
+(defun ellama-tools-append-file-tool-confirm (path content)
+  "Append CONTENT to the file located at the specified PATH."
+  (ellama-tools-confirm
+   (format "Allow appending file %s?" path)
+   'ellama-tools-append-file-tool
+   (list path content)))
+
+(add-to-list
+ 'ellama-tools-available
+ (llm-make-tool :function
+                'ellama-tools-append-file-tool-confirm
+                :name
+                "append_file"
+                :args
+                (list '(:name
+                        "path"
+                        :type
+                        string
+                        :description
+                        "Path to the file.")
+                      '(:name
+                        "content"
+                        :type
+                        string
+                        :description
+                        "Content to append to the file."))
+                :description
+                "Append CONTENT to the file located at the specified PATH."))
+
 (defun ellama-tools-directory-tree-tool (dir &optional depth)
   "Return a string representing the directory tree under DIR.
 DEPTH is the current recursion depth, used internally."
@@ -566,5 +602,34 @@ Replace OLDCONTENT with NEWCONTENT."
                 :description
                 "Return current project root directory."))
 
+(defun ellama-tools-ask-user-tool (question answer-variant-list)
+  "Ask user a QUESTION to receive a clarification.
+ANSWER-VARIANT-LIST is a list of possible answer variants."
+  (completing-read (concat question " ") (seq--into-list answer-variant-list)))
+
+(add-to-list
+ 'ellama-tools-available
+ (llm-make-tool :function
+                'ellama-tools-ask-user-tool
+                :name
+                "ask_user"
+                :args
+                (list
+                 '(:name
+                   "question"
+                   :type
+                   string
+                   :description
+                   "Question to ask user for clarification.")
+                 '(:name
+                   "answer_variant_list"
+                   :type array
+                   :description
+                   "List of possible answer variants."
+                   :items (:type string)))
+                :description
+                "Ask user a QUESTION to receive a clarification.
+ANSWER-VARIANT-LIST is a list of possible answer variants."))
+
 (provide 'ellama-tools)
 ;;; ellama-tools.el ends here
diff --git a/ellama.el b/ellama.el
index 9486e1f891..9204c1f03b 100644
--- a/ellama.el
+++ b/ellama.el
@@ -6,7 +6,7 @@
 ;; URL: http://github.com/s-kostyaev/ellama
 ;; Keywords: help local tools
 ;; Package-Requires: ((emacs "28.1") (llm "0.24.0") (plz "0.8") (transient 
"0.7") (compat "29.1"))
-;; Version: 1.10.3
+;; Version: 1.10.4
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;; Created: 8th Oct 2023
 

Reply via email to