Skip to content

Commit

Permalink
tweak(ellama): auto load installed models
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Feb 4, 2024
1 parent d2c45d1 commit 0a6f71d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions modules/me-ai.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
(message "The Ollama server is already running, call `+ellama-kill-server' to stop it.")
(if (make-process :name +ellama-process-name :buffer +ellama-server-buffer-name :command '("ollama" "serve"))
(message "Successfully started Ollama server.")
(user-error "Cannot start the Ollama server")))
(user-error "Cannot start the Ollama server"))
(with-eval-after-load 'ellama (+ellama-set-providers)))
(user-error "Cannot find the \"ollama\" executable")))
(defun +ellama-kill-server ()
"Kill Ellama server."
Expand All @@ -36,8 +37,19 @@
(message "Killed Ollama server.")
(user-error "Cannot kill the Ollama server"))
(message "No running Ollama server."))))
:custom
(ellama-provider (make-llm-ollama :chat-model "llama2:13b" :embedding-model "llama2:13b")))
:config
(defun +ellama-list-installed-models ()
"Return the installed models"
(let* ((ret (shell-command-to-string "ollama list"))
(models (cdr (string-lines ret))))
(if (and (string-match-p "NAME[[:space:]]*ID[[:space:]]*SIZE[[:space:]]*MODIFIED" ret) (length> models 0))
(mapcar (lambda (m) (car (string-split m))) models)
(user-error "Cannot detect installed models, please make sure Ollama server is started"))))
(defun +ellama-set-providers ()
(setopt ellama-providers
(cl-loop for model in (+ellama-list-installed-models)
collect (cons model (make-llm-ollama :chat-model model :embedding-model model)))
ellama-provider (cdr (car ellama-providers)))))


(provide 'me-ai)
Expand Down

0 comments on commit 0a6f71d

Please sign in to comment.