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.
This commit is contained in:
Jeremy Dormitzer 2024-07-16 22:42:22 -04:00
parent 9360580a94
commit 31220b41b9

View File

@ -6,10 +6,25 @@
gptel-request)
:config
(setq gptel-model "llama3:latest"
gptel-backend (gptel-make-ollama "Ollama"
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-<return>" #'gptel-menu))