branch: externals/ellama
commit 9f7742b191ef240f733c058b440b56c2ffba738a
Merge: 8f89be3d91 2d9b728cb1
Author: Sergey Kostyaev <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #364 from s-kostyaev/fix-encoding-read-commands
Wrap tool outputs with JSON encoding
---
NEWS.org | 4 ++++
ellama-tools.el | 43 +++++++++++++++++++++++--------------------
ellama.el | 2 +-
3 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index 13b8e59188..b77a860bc6 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,3 +1,7 @@
+* Version 1.10.6
+- Added json-encode wrapping to ~ellama-tools-read-file-tool~,
+ ~ellama-tools-grep-tool~, ~ellama-tools-grep-in-file-tool~ and
+ ~ellama-tools-lines-range-tool~ outputs for consistent JSON format.
* Version 1.10.5
- Added ~count_lines~ and ~lines_range~ tools for counting lines and retrieving
file content by line range.
diff --git a/ellama-tools.el b/ellama-tools.el
index 24f2618d19..f046289396 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -190,11 +190,11 @@ otherwise."
(defun ellama-tools-read-file-tool (path)
"Read the file located at the specified PATH."
- (if (not (file-exists-p path))
- (format "File %s doesn't exists." path)
- (with-temp-buffer
- (insert-file-contents-literally path)
- (buffer-string))))
+ (json-encode (if (not (file-exists-p path))
+ (format "File %s doesn't exists." path)
+ (with-temp-buffer
+ (insert-file-contents-literally path)
+ (buffer-string)))))
(defun ellama-tools-read-file-tool-confirm (path)
"Read the file located at the specified PATH."
@@ -452,7 +452,9 @@ Replace OLDCONTENT with NEWCONTENT."
(defun ellama-tools-grep-tool (search-string)
"Grep SEARCH-STRING in directory files."
- (shell-command-to-string (format "find . -type f -exec grep --color=never
-nh -e %s \\{\\} +" search-string)))
+ (json-encode
+ (shell-command-to-string
+ (format "find . -type f -exec grep --color=never -nh -e %s \\{\\} +"
search-string))))
(defun ellama-tools-grep-tool-confirm (search-string)
"Grep SEARCH-STRING in directory files."
@@ -479,7 +481,8 @@ Replace OLDCONTENT with NEWCONTENT."
(defun ellama-tools-grep-in-file-tool (search-string file)
"Grep SEARCH-STRING in FILE."
- (shell-command-to-string (format "grep --color=never -nh %s %s"
search-string file)))
+ (json-encode
+ (shell-command-to-string (format "grep --color=never -nh %s %s"
search-string file))))
(defun ellama-tools-grep-in-file-tool-confirm (search-string file)
"Confirm grepping for SEARCH-STRING in FILE."
@@ -682,19 +685,19 @@ ANSWER-VARIANT-LIST is a list of possible answer
variants."))
(defun ellama-tools-lines-range-tool (path from to)
"Return content of file located at PATH lines in range FROM TO."
- (with-current-buffer (find-file-noselect path)
- (save-excursion
- (let ((start (progn
- (goto-char (point-min))
- (forward-line (1- from))
- (beginning-of-line)
- (point)))
- (end (progn
- (goto-char (point-min))
- (forward-line (1- to))
- (end-of-line)
- (point))))
- (buffer-substring-no-properties start end)))))
+ (json-encode (with-current-buffer (find-file-noselect path)
+ (save-excursion
+ (let ((start (progn
+ (goto-char (point-min))
+ (forward-line (1- from))
+ (beginning-of-line)
+ (point)))
+ (end (progn
+ (goto-char (point-min))
+ (forward-line (1- to))
+ (end-of-line)
+ (point))))
+ (buffer-substring-no-properties start end))))))
(defun ellama-tools-lines-range-tool-confirm (path from to)
"Return content of file located at PATH lines in range FROM TO."
diff --git a/ellama.el b/ellama.el
index 70d1e5ef8d..1d767d4ea8 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.5
+;; Version: 1.10.6
;; SPDX-License-Identifier: GPL-3.0-or-later
;; Created: 8th Oct 2023