diff --git a/.config/containers/systemd/ollama.container b/.config/containers/systemd/ollama.container index 4c6b9e9..6ae7f6c 100644 --- a/.config/containers/systemd/ollama.container +++ b/.config/containers/systemd/ollama.container @@ -5,8 +5,9 @@ Description=A local LLM server # keep-sorted start ContainerName=ollama Image=docker.io/ollama/ollama:latest +Network=ollama.network PublishPort=11434:11434 -Volume=%h/.local/share/ollama:/root/.ollama:Z +Volume=%h/.local/share/ollama:/root/.ollama:ro,z # keep-sorted end [Install] diff --git a/.config/containers/systemd/ollama.network b/.config/containers/systemd/ollama.network new file mode 100644 index 0000000..5f8c30b --- /dev/null +++ b/.config/containers/systemd/ollama.network @@ -0,0 +1,5 @@ +[Unit] +Description=Isolated network for my local LLM server + +[Network] +Internal=true diff --git a/.config/emacs/init.el b/.config/emacs/init.el index e3a988b..19992c8 100644 --- a/.config/emacs/init.el +++ b/.config/emacs/init.el @@ -306,6 +306,14 @@ auto-mode-alist)) ) +(defun list-ollama-models () + "Query the local Ollama server for the list of installed models" + (condition-case error-var + (mapcar #'intern (mapcar #'car (mapcar #'split-string (cdr (process-lines "podllama" "list"))))) + (error + (message "Failed to list local models: %s" error-var) + ()))) + (use-package gptel :hook ; keep-sorted start @@ -318,6 +326,7 @@ ; keep-sorted start (gptel-backend (gptel-get-backend "Ollama")) (gptel-default-mode 'org-mode) + (gptel-expert-commands t) (gptel-highlight-methods '(face margin)) (gptel-model 'llama3.2:latest) ; keep-sorted end @@ -328,7 +337,7 @@ ) (gptel-make-ollama "Ollama" :stream t - :models '(llama3.2:latest) + :models (list-ollama-models) ) ) diff --git a/.local/bin/podllama b/.local/bin/podllama new file mode 100755 index 0000000..947b0d0 --- /dev/null +++ b/.local/bin/podllama @@ -0,0 +1,9 @@ +#! /usr/bin/bash + +set -euo pipefail +IFS=$'\n\t' + +mkdir --parents ~/.local/share/ollama/ +pod_id=$(podman run --detach --rm --volume ~/.local/share/ollama/:/root/.ollama ollama:latest) +podman exec --interactive --tty "${pod_id}" ollama "$@" +podman kill "${pod_id}" > /dev/null