From 396c8e0318a3f1ac2d0bac38d53bc00e015142d7 Mon Sep 17 00:00:00 2001 From: John Ogle Date: Wed, 10 Sep 2025 06:57:25 -0700 Subject: [PATCH] [doom] Configure gptel for tool calling Adds some basic tools for experimenting --- home/modules/emacs/doom/config.el | 40 +++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/home/modules/emacs/doom/config.el b/home/modules/emacs/doom/config.el index 4c13071..c2a39cf 100644 --- a/home/modules/emacs/doom/config.el +++ b/home/modules/emacs/doom/config.el @@ -80,11 +80,47 @@ (after! gptel :config - (setq! gptel-api-key (my/get-rbw-password "openai-api-key-chatgpt-el")) + (setq! gptel-api-key (my/get-rbw-password "openai-api-key-chatgpt-el") + gptel-default-mode 'org-mode + gptel-use-tools t + gptel-confirm-tool-calls 'always) + (gptel-make-ollama "Ollama-Local" :host "localhost:11434" :stream t - :models '(deepseek-r1 deepseek-r1-fullctx qwen3 qwen3-coder))) + :models '(deepseek-r1 deepseek-r1-fullctx qwen3 qwen3-coder llama3.1 qwen2.5-coder mistral-nemo gpt-oss)) + + ;; Define custom tools + (gptel-make-tool + :name "run_shell_command" + :description "Execute shell commands and return output. Use this to run system commands, check file contents, or perform system operations." + :function (lambda (command) + (condition-case err + (shell-command-to-string command) + (error (format "Error running command: %s" (error-message-string err))))) + :args (list '(:name "command" :type "string" :description "Shell command to execute"))) + + (gptel-make-tool + :name "read_file" + :description "Read the contents of a file and return as text" + :function (lambda (filepath) + (condition-case err + (with-temp-buffer + (insert-file-contents (expand-file-name filepath)) + (buffer-string)) + (error (format "Error reading file %s: %s" filepath (error-message-string err))))) + :args (list '(:name "filepath" :type "string" :description "Path to the file to read"))) + + (gptel-make-tool + :name "list_directory" + :description "List contents of a directory" + :function (lambda (dirpath) + (condition-case err + (mapconcat 'identity + (directory-files (expand-file-name dirpath) nil "^[^.]") + "\n") + (error (format "Error listing directory %s: %s" dirpath (error-message-string err))))) + :args (list '(:name "dirpath" :type "string" :description "Directory path to list")))) (use-package! claude-code-ide :defer t