|
16 | 16 | ;; `llm' module for integrating with Ollama
|
17 | 17 | (use-package llm-ollama
|
18 | 18 | :straight llm
|
19 |
| - :autoload make-llm-ollama +ollama-serve +ollama-kill-server +ollama-list-installed-models |
| 19 | + :autoload make-llm-ollama +ollama-list-installed-models |
20 | 20 | :config
|
21 |
| - (defvar +ollama-process-name "ellama-server") |
22 |
| - (defvar +ollama-server-buffer-name " *ellama-server*") |
23 |
| - |
24 |
| - (defun +ollama-serve () |
25 |
| - "Start Ellama server." |
26 |
| - (interactive) |
27 |
| - (if (executable-find "ollama") |
28 |
| - (if (get-process +ollama-process-name) |
29 |
| - (message "The Ollama server is already running, call `+ollama-kill-server' to stop it.") |
30 |
| - (if (make-process :name +ollama-process-name :buffer +ollama-server-buffer-name :command '("ollama" "serve")) |
31 |
| - (message "Successfully started Ollama server.") |
32 |
| - (user-error "Cannot start the Ollama server")) |
33 |
| - (with-eval-after-load 'ellama (+ellama-set-available-providers))) |
34 |
| - (user-error "Cannot find the \"ollama\" executable"))) |
35 |
| - |
36 |
| - (defun +ollama-kill-server () |
37 |
| - "Kill Ellama server." |
38 |
| - (interactive) |
39 |
| - (let ((ollama (get-process +ollama-process-name))) |
40 |
| - (if ollama |
41 |
| - (if (kill-process ollama) |
42 |
| - (message "Killed Ollama server.") |
43 |
| - (user-error "Cannot kill the Ollama server")) |
44 |
| - (message "No running Ollama server.")))) |
45 |
| - |
46 | 21 | (defun +ollama-list-installed-models ()
|
47 | 22 | "Return the installed models"
|
48 |
| - (let* ((ret (shell-command-to-string "ollama list")) |
49 |
| - (models (cdr (string-lines ret)))) |
50 |
| - (if (and (string-match-p "NAME[[:space:]]*ID[[:space:]]*SIZE[[:space:]]*MODIFIED" ret) (length> models 0)) |
51 |
| - (mapcar (lambda (m) (car (string-split m))) models) |
52 |
| - (user-error "Cannot detect installed models, please make sure Ollama server is started"))))) |
| 23 | + (if (zerop (call-process-shell-command "ollama ps")) |
| 24 | + (let* ((ret (shell-command-to-string "ollama list")) |
| 25 | + (models (cdr (string-lines ret)))) |
| 26 | + (if (and (string-match-p "NAME[[:space:]]*ID[[:space:]]*SIZE[[:space:]]*MODIFIED" ret) (length> models 0)) |
| 27 | + (mapcar (lambda (m) (car (string-split m))) models) |
| 28 | + (user-error "No model available, please pull some Ollama model"))) |
| 29 | + (user-error "Please make sure Ollama server is started")))) |
53 | 30 |
|
54 | 31 |
|
55 | 32 | ;; A package for interacting with LLMs from Emacs
|
|
0 commit comments