branch: elpa/aidermacs commit 4ad55b60885b1f235a5f3f8b0934dae2b641624f Author: Kang Tu <tni...@gmail.com> Commit: GitHub <nore...@github.com>
Feat: Add aider-change-model function (#59) * refactor: add buffer check to dispatch aider-ask-question based on context * refactor: Extract common test instructions to constant in `aider-write-unit-test` * docs: update test generation instructions to discourage mocks * feat: add interactive model selection with /model command * feat(models): reorganize model options and rename to aider-popular-models * refactor: Move aider-current-file-read-only to aider.el and add to transient menu * feat: Add read-only option for current file in Aider menu * docs: update aider models list reference and fix shortcuts * fix: use aider-popular-models list default value in select-model prompt * feat: Add model selection section to README with supported AI models * docs(models): update model descriptions and add date reference --- README.org | 9 +++++++++ aider-doom.el | 7 ------- aider.el | 57 ++++++++++++++++++++++++++++++++++++++++++----------- transient_menu.png | Bin 77779 -> 91139 bytes 4 files changed, 55 insertions(+), 18 deletions(-) diff --git a/README.org b/README.org index 0d450a9155..bd4013ee21 100644 --- a/README.org +++ b/README.org @@ -25,6 +25,15 @@ When being called with the universal argument (`C-u`), a prompt will offer the u - (`aider-switch-to-buffer`): Switch to the Aider buffer. - use "^" in the menu to toggle open aider session in other window inside current frame, or open a dedicate frame for aider session +*** Model Selection: + - (`aider-change-model`): Interactively select and change AI model in current aider session + - Customize `aider-popular-models` to define your preferred models list. Default models are (as date of 2025-01-26): + - gemini/gemini-exp-1206 (free) + - anthropic/claude-3-5-sonnet-20241022 (really good in practical) + - r1 (performance matches o1, price << claude sonnet. weakness: small context) + - deepseek/deepseek-chat (chatgpt-4o level performance, price is 1/100. weakness: small context) + - gpt-4o-mini + *** More ways to add files to the Aider buffer: - use "@" in the menu to toggle add file between read-write mode and read-only mode - (`aider-add-current-file`): Add the current buffer file. diff --git a/aider-doom.el b/aider-doom.el index 52c22a8fe1..35a1a0c205 100644 --- a/aider-doom.el +++ b/aider-doom.el @@ -57,13 +57,6 @@ :desc "Exit Aider" "x" #'aider-exit )))) -;; Function to send "/read <current buffer file full path>" to corresponding aider buffer -;;;###autoload -(defun aider-current-file-read-only () - "Send the command \"/read-only <current buffer file full path>\" to the corresponding aider comint buffer. This is only useful for doom menu now" - (interactive) - (aider-add-or-read-current-file "/read-only")) - ;; Add the setup function to appropriate hooks (add-hook 'find-file-hook #'aider-doom-setup-keys) (add-hook 'dired-mode-hook #'aider-doom-setup-keys) diff --git a/aider.el b/aider.el index b7c9ebaf50..823453cacc 100644 --- a/aider.el +++ b/aider.el @@ -38,6 +38,18 @@ When nil, use standard `display-buffer' behavior." :type 'boolean :group 'aider) +(defcustom aider-popular-models '("gemini/gemini-exp-1206" ;; free + "anthropic/claude-3-5-sonnet-20241022" ;; really good in practical + "r1" ;; performance match o1, price << claude sonnet. weakness: small context + "deepseek/deepseek-chat" ;; chatgpt-4o level performance, price is 1/100. weakness: small context + "gpt-4o-mini" + ) + "List of available AI models for selection. +Each model should be in the format expected by the aider command line interface. +Also based on aider LLM benchmark: https://aider.chat/docs/leaderboards/" + :type '(repeat string) + :group 'aider) + (defface aider-command-separator '((((type graphic)) :strike-through t :extend t) (((type tty)) :inherit font-lock-comment-face :underline t :extend t)) @@ -108,6 +120,7 @@ Affects the system message too.") (aider--infix-switch-to-buffer-other-frame) ("a" "Run Aider" aider-run-aider) ("z" "Switch to Aider Buffer" aider-switch-to-buffer) + ("o" "Select Model" aider-change-model) ("l" "Clear Aider" aider-clear) ("s" "Reset Aider" aider-reset) ("x" "Exit Aider" aider-exit) @@ -115,6 +128,7 @@ Affects the system message too.") ["Add File to Aider" (aider--infix-add-file-read-only) ("f" "Add Current File" aider-add-current-file) + ("R" "Add Current File Read-Only" aider-current-file-read-only) ("w" "Add All Files in Current Window" aider-add-files-in-current-window) ("d" "Add Same Type Files under dir" aider-add-same-type-files-under-dir) ("b" "Batch Add Dired Marked Files" aider-batch-add-dired-marked-files) @@ -305,6 +319,12 @@ COMMAND should be a string representing the command to send." (interactive) (aider-add-or-read-current-file (aider--get-add-command-prefix))) +;;;###autoload +(defun aider-current-file-read-only () + "Send the command \"/read-only <current buffer file full path>\" to the corresponding aider comint buffer." + (interactive) + (aider-add-or-read-current-file "/read-only")) + ;; New function to add files in all buffers in current emacs window ;;;###autoload (defun aider-add-files-in-current-window () @@ -345,6 +365,11 @@ COMMAND should be a string representing the command to send." If a region is active, append the region text to the question. If cursor is inside a function, include the function name as context." (interactive) + ;; Dispatch to general question if in aider buffer + (when (string= (buffer-name) (aider-buffer-name)) + (call-interactively 'aider-general-question) + (cl-return-from aider-ask-question)) + (let* ((function-name (which-function)) (initial-input (when function-name (format "About function '%s': " function-name))) @@ -569,20 +594,17 @@ Otherwise, generate unit tests for the entire file." (if (string-match-p "test" (file-name-nondirectory buffer-file-name)) (message "Current buffer appears to be a test file.") (let* ((function-name (which-function)) - (initial-input - (if function-name - (format "Please write unit test code for function '%s'. Include test cases for: + (common-instructions "Include test cases for: 1. Normal input/output scenarios 2. Edge cases and boundary conditions 3. Error handling and invalid inputs -Make the test comprehensive but maintainable. Follow standard unit testing practices." - function-name) - (format "Please write unit test code for file '%s'. For each function include test cases for: -1. Normal input/output scenarios -2. Edge cases and boundary conditions -3. Error handling and invalid inputs -Make the tests comprehensive but maintainable. Follow standard unit testing practices." - (file-name-nondirectory buffer-file-name)))) +Make the test comprehensive but maintainable. Do not use Mock if possible. Follow standard unit testing practices.") + (initial-input + (if function-name + (format "Please write unit test code for function '%s'. %s" + function-name common-instructions) + (format "Please write unit test code for file '%s'. For each function %s" + (file-name-nondirectory buffer-file-name) common-instructions))) (user-command (aider-read-string "Unit test generation instruction: " initial-input)) (command (format "/architect %s" user-command))) (aider-add-current-file) @@ -602,6 +624,19 @@ This function assumes the cursor is on or inside a test function." (aider--send-command command t)) (message "No test function found at cursor position."))) +;;; Model selection functions +;;;###autoload +(defun aider-change-model () + "Interactively select and change AI model in current aider session." + (interactive) + (let ((model (aider--select-model))) + (when model + (aider--send-command (format "/model %s" model) t)))) + +(defun aider--select-model () + "Private function for model selection with completion." + (completing-read "Select AI model: " aider-popular-models nil t nil nil (car aider-popular-models))) + ;;; functions for sending text blocks ;; New function to send "<line under cursor>" or region line by line to the Aider buffer diff --git a/transient_menu.png b/transient_menu.png index 3545c19c59..0d60c75389 100644 Binary files a/transient_menu.png and b/transient_menu.png differ