From 31220b41b9c16115f68a1bd41a00a3915a2b5867 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Tue, 16 Jul 2024 22:42:22 -0400 Subject: [PATCH] Support multiple GPT backends in gptel config Enhanced the gptel configuration to support multiple backends (Ollama and OpenAI) and added a function to select the desired backend. Default backend is set to OpenAI. --- emacs/.emacs.d/config/init-ai.el | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/emacs/.emacs.d/config/init-ai.el b/emacs/.emacs.d/config/init-ai.el index 79e148d..ce19bd3 100644 --- a/emacs/.emacs.d/config/init-ai.el +++ b/emacs/.emacs.d/config/init-ai.el @@ -6,10 +6,25 @@ gptel-request) :config (setq gptel-model "llama3:latest" - gptel-backend (gptel-make-ollama "Ollama" - :stream t - :models '("llama3:latest" - "mistral: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) :general ("C-c RET" #'gptel-send "C-c C-" #'gptel-menu))