Skip to content

Commit dc4372f

Browse files
committed
tweak(llm): minor refactoring
1 parent 3cdda14 commit dc4372f

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

modules/me-ai.el

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,52 @@
88

99
;;; Code:
1010

11+
(use-package llm
12+
:straight t)
13+
1114
(use-package llm-ollama
1215
:straight llm
13-
:autoload make-llm-ollama)
16+
:autoload make-llm-ollama +ollama-serve +ollama-kill-server +ollama-list-installed-models
17+
:config
18+
(defvar +ollama-process-name "ellama-server")
19+
(defvar +ollama-server-buffer-name " *ellama-server*")
1420

15-
(use-package ellama
16-
:straight t
17-
:init
18-
(defvar +ellama-process-name "ellama-server")
19-
(defvar +ellama-server-buffer-name " *ellama-server*")
20-
(defun +ellama-serve ()
21+
(defun +ollama-serve ()
2122
"Start Ellama server."
2223
(interactive)
2324
(if (executable-find "ollama")
24-
(if (get-process +ellama-process-name)
25-
(message "The Ollama server is already running, call `+ellama-kill-server' to stop it.")
26-
(if (make-process :name +ellama-process-name :buffer +ellama-server-buffer-name :command '("ollama" "serve"))
25+
(if (get-process +ollama-process-name)
26+
(message "The Ollama server is already running, call `+ollama-kill-server' to stop it.")
27+
(if (make-process :name +ollama-process-name :buffer +ollama-server-buffer-name :command '("ollama" "serve"))
2728
(message "Successfully started Ollama server.")
2829
(user-error "Cannot start the Ollama server"))
2930
(with-eval-after-load 'ellama (+ellama-set-providers)))
3031
(user-error "Cannot find the \"ollama\" executable")))
31-
(defun +ellama-kill-server ()
32+
33+
(defun +ollama-kill-server ()
3234
"Kill Ellama server."
3335
(interactive)
34-
(let ((ollama (get-process +ellama-process-name)))
36+
(let ((ollama (get-process +ollama-process-name)))
3537
(if ollama
3638
(if (kill-process ollama)
3739
(message "Killed Ollama server.")
3840
(user-error "Cannot kill the Ollama server"))
3941
(message "No running Ollama server."))))
40-
:config
41-
(defun +ellama-list-installed-models ()
42+
43+
(defun +ollama-list-installed-models ()
4244
"Return the installed models"
4345
(let* ((ret (shell-command-to-string "ollama list"))
4446
(models (cdr (string-lines ret))))
4547
(if (and (string-match-p "NAME[[:space:]]*ID[[:space:]]*SIZE[[:space:]]*MODIFIED" ret) (length> models 0))
4648
(mapcar (lambda (m) (car (string-split m))) models)
47-
(user-error "Cannot detect installed models, please make sure Ollama server is started"))))
49+
(user-error "Cannot detect installed models, please make sure Ollama server is started")))))
50+
51+
(use-package ellama
52+
:straight t
53+
:config
4854
(defun +ellama-set-providers ()
4955
(setopt ellama-providers
50-
(cl-loop for model in (+ellama-list-installed-models)
56+
(cl-loop for model in (+ollama-list-installed-models)
5157
collect (cons model (make-llm-ollama :chat-model model :embedding-model model)))
5258
ellama-provider (cdr (car ellama-providers)))))
5359

0 commit comments

Comments
 (0)