Refactor gptel backend selection and configuration
Reorganized backend definitions and selection process for gptel, introducing `gptel-backend-openai` and `gptel-backend-ollama` variables. Simplified backend selection logic and improved the `gptel-select-backend` function to dynamically prompt for models.
This commit is contained in:
parent
70599ad053
commit
9fb96b3099
@ -5,26 +5,29 @@
|
||||
|
||||
(use-package gptel
|
||||
:config
|
||||
(setq gptel-model "llama3:latest"
|
||||
gptel-backends `((ollama . ((backend . ,(gptel-make-ollama "Ollama"
|
||||
(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")))
|
||||
(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)
|
||||
(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-<return>" #'gptel-menu)
|
||||
|
Loading…
Reference in New Issue
Block a user