]> Humopery - gptelconfig.git/commitdiff
add primitive postgres database tools
authorErik Mackdanz <erikmack@gmail.com>
Thu, 27 Nov 2025 08:32:17 +0000 (02:32 -0600)
committerErik Mackdanz <erikmack@gmail.com>
Thu, 27 Nov 2025 08:32:17 +0000 (02:32 -0600)
gptel

diff --git a/gptel b/gptel
index 50e7631330dee800f8e160b81b6013f9d69a5572..85faa931ce7604b4524b9dd17709fbde02edbfcc 100644 (file)
--- a/gptel
+++ b/gptel
           ;; "view_buffer"
           )
   )
+
+(gptel-make-tool
+ :name "db_execute"
+ :function (lambda (query)
+            (let ((output-buffer (generate-new-buffer "*query-output*")))
+               (call-process-region query nil "psql" nil output-buffer t "llm")
+              ;; (message "Schema update output: %s" (with-current-buffer output-buffer (buffer-string)))
+              (with-current-buffer output-buffer (buffer-string))
+              ))
+ :description "Run the given query in the sample PostgreSQL database. It can be DML (select, update) or DDL (e.g. create table, alter index)"
+ :confirm nil
+ :args (list '(:name "query"
+                     :type string
+                     :description "The query to run"
+                     )
+             )
+ :category "database")
+
+(gptel-make-tool
+ :name "db_get_schema"
+ :function (lambda ()
+            (let ((output-buffer (generate-new-buffer "*query-output*")))
+               (call-process-region "" nil "pg_dump" nil output-buffer t "llm")
+              ;; (message "Get schema output: %s" (with-current-buffer output-buffer (buffer-string)))
+              (with-current-buffer output-buffer (buffer-string))
+              ))
+ :description "Dump the schema of the sample PostgreSQL database"
+ :confirm nil
+ :args nil
+ :category "database")