From ae4178f270c82c302fcf67abc8fa3c084332d0f3 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Tue, 22 Oct 2024 16:48:49 +0000 Subject: [PATCH] Make Ollama config pull models dynamically --- emacs/.emacs.d/config/init-ai.el | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/emacs/.emacs.d/config/init-ai.el b/emacs/.emacs.d/config/init-ai.el index 2170095..b1abf13 100644 --- a/emacs/.emacs.d/config/init-ai.el +++ b/emacs/.emacs.d/config/init-ai.el @@ -39,12 +39,22 @@ :stream t :models '("gpt-4o" "gpt-4o-mini"))) + (defun ollama-models () + (if (executable-find "ollama") + (->> (shell-command-to-string "ollama list") + (s-lines) + (cdr) + (mapcar (lambda (line) + (let ((parts (s-split-up-to " " line 1 t))) + (car parts)))) + (-filter #'s-present?)) + (list "llama3.1:latest" + "mistral-nemo:latest" + "gemma2:2b" + "tinyllama:latest"))) (defvar gptel-backend-ollama (gptel-make-ollama "Ollama" :stream t - :models '("llama3.1:latest" - "mistral-nemo:latest" - "gemma2:2b" - "tinyllama:latest"))) + :models (ollama-models))) (defvar gptel-backend-anthropic (gptel-make-anthropic "Claude" :stream t :key (password-store-get "anthropic-api-key")))