branch: externals/ellama
commit 431e525f847bb540db7728a00260c0ffecd478b4
Author: Sergey Kostyaev <[email protected]>
Commit: Sergey Kostyaev <[email protected]>
Add prepend_file tool
This commit introduces a new function `ellama-tools-prepend-file-tool` that
prepends the supplied CONTENT to the file at the given PATH, and registers
it as
the `prepend_file` tool in ellama tools. The implementation mirrors
`ellama-tools-append-file-tool` but inserts the content at the beginning of
the
buffer. This expands the set of file manipulation utilities available
through
the ellama tools.
---
ellama-tools.el | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/ellama-tools.el b/ellama-tools.el
index 47db0e700a..a2b6b63e59 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -303,6 +303,34 @@ TOOL-PLIST is a property list in the format expected by
`llm-make-tool'."
:description
"Append CONTENT to the file located at the specified PATH."))
+(defun ellama-tools-prepend-file-tool (path content)
+ "Prepend CONTENT to the file located at the specified PATH."
+ (with-current-buffer (find-file-noselect path)
+ (goto-char (point-min))
+ (insert content)
+ (save-buffer)))
+
+(ellama-tools-define-tool
+ '(:function
+ ellama-tools-prepend-file-tool
+ :name
+ "prepend_file"
+ :args
+ ((:name
+ "path"
+ :type
+ string
+ :description
+ "Path to the file.")
+ (:name
+ "content"
+ :type
+ string
+ :description
+ "Content to prepend to the file."))
+ :description
+ "Prepend 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."