diff --git a/emacs/.emacs.d/config/init-ai.el b/emacs/.emacs.d/config/init-ai.el index 1a4f2f9..246f7d9 100644 --- a/emacs/.emacs.d/config/init-ai.el +++ b/emacs/.emacs.d/config/init-ai.el @@ -5,26 +5,29 @@ (use-package gptel :config - (setq gptel-model "llama3:latest" - gptel-backends `((ollama . ((backend . ,(gptel-make-ollama "Ollama" - :stream t - :models '("llama3:latest" - "mistral:latest"))) - (model . "llama3:latest"))) - (openai . ((backend . ,(gptel-make-openai "OpenAI" - :key #'gptel-api-key-from-auth-source - :stream t - :models '("gpt-4o"))) - (model . "gpt-4o")))) - gptel-default-backend 'openai) - (defun gptel-select-backend (backend) - (interactive - (list (intern (completing-read "gptel backend: " - (mapcar #'car gptel-backends))))) - (let ((backend (alist-get backend gptel-backends))) - (setq gptel-backend (alist-get 'backend backend) - gptel-model (alist-get 'model backend)))) - (gptel-select-backend gptel-default-backend) + (defvar gptel-backend-openai (gptel-make-openai "OpenAI" + :key #'gptel-api-key-from-auth-source + :stream t + :models '("gpt-4o" + "gpt-4o-mini"))) + (defvar gptel-backend-ollama (gptel-make-ollama "Ollama" + :stream t + :models '("llama3:latest" + "mistral:latest"))) + (setq gptel-backend gptel-backend-openai + gptel-model "gpt-4o") + (defun gptel-select-backend () + (interactive) + (let ((backend + (cl-loop + for (name . backend) in gptel--known-backends + nconc (cl-loop for model in (gptel-backend-models backend) + collect (list (concat name ":" model) backend model)) + into models-alist finally return + (cdr (assoc (completing-read "Backend: " models-alist nil t) + models-alist))))) + (setq gptel-backend (car backend) + gptel-model (cadr backend)))) :general ("C-c RET" #'gptel-send "C-c C-" #'gptel-menu)