Retrieve model list directly from the Ollama server

This commit is contained in:
Ohad Livne 2025-11-17 23:45:11 +02:00
parent 90c310302d
commit fd645f60a2
Signed by: libohad-dev
GPG key ID: 34FDC68B51191A4D

View file

@ -307,11 +307,12 @@
(defun list-ollama-models () (defun list-ollama-models ()
"Query the local Ollama server for the list of installed models." "Query the local Ollama server for the list of installed models."
(condition-case error-var (let* ((tags-buffer (url-retrieve-synchronously "http://ollama:11434/api/tags"))
(mapcar #'intern (mapcar #'car (mapcar #'split-string (cdr (process-lines "podllama" "list"))))) (raw-response (with-current-buffer tags-buffer (buffer-string)))
(error (tags-payload (nth 1 (split-string raw-response "\n\n")))
(message "Failed to list local models: %s" error-var) (models (gethash "models" (json-parse-string tags-payload)))
()))) (model-names (mapcar (lambda (model) (gethash "name" model)) models)))
model-names))
(defun enrich-ollama-models (available library) (defun enrich-ollama-models (available library)
"Enrich the available models with metadata from the library of known models." "Enrich the available models with metadata from the library of known models."