blob: 1b4fc904a6c39087e54d64d7767786e420c2af0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
;;; read_buffer.el --- Read buffer tool for GPTel -*- coding: utf-8; lexical-binding: t; -*-
;;; Commentary:
;; Gptel tool that returns the contents of an Emacs buffer by name.
;;; Code:
(require 'gptel)
(defun cj/read-buffer--get-content (buffer)
"Return the substring of BUFFER from `point-min' to `point-max'.
BUFFER may be a buffer object or a buffer name string. Signal an
error when no live buffer matches."
(unless (buffer-live-p (get-buffer buffer))
(error "Buffer %s is not live" buffer))
(with-current-buffer buffer
(buffer-substring-no-properties (point-min) (point-max))))
(gptel-make-tool
:name "read_buffer"
:function (lambda (buffer) (cj/read-buffer--get-content buffer))
:description "return the contents of an emacs buffer"
:args (list '(:name "buffer"
:type string
:description "the name of the buffer whose contents are to be retrieved"))
:category "emacs")
(add-to-list 'gptel-tools (gptel-get-tool '("emacs" "read_buffer")))
(provide 'read_buffer)
;;; read_buffer.el ends here
|