From 3c09eb3cbd01b17ea079dccbcd241dbc0ac910b8 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Fri, 17 May 2024 13:30:09 -0400 Subject: [PATCH] Enable llm.el to work with ollama models --- emacs/.emacs.d/packages/llm/llm.el | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/emacs/.emacs.d/packages/llm/llm.el b/emacs/.emacs.d/packages/llm/llm.el index cdfacf7..13740c2 100644 --- a/emacs/.emacs.d/packages/llm/llm.el +++ b/emacs/.emacs.d/packages/llm/llm.el @@ -121,16 +121,26 @@ The process is named NAME and runs in BUFFER-NAME." (split-string (shell-command-to-string (format "%s models" (executable-find llm-executable))) "\n" t " ")) - (models (mapcar (lambda (s) - (cons s (cadr (s-match ".*?: \\(.*?\\) -" s)))) - model-strings)) + (models (mapcar + (lambda (s) + (cons s + (cadr + (s-match ".*?: \\(.*?\\)\\(?:[[:blank:]]\\|$\\)" s)))) + model-strings)) (selected (completing-read "Model: " models))) (alist-get selected models nil nil #'equal)))) (setq llm-model model)) +(defvar llm-model-extra-args-alist + `(("Meta-Llama-3-8B-Instruct" . ("-o" "max_tokens" ,(number-to-string llm-max-tokens)))) + "Alist mapping model names to extra arguments to pass to llm.") + (defun llm--prompt-args (query &rest extra-args) "Return the arguments to prompt LLM with QUERY, appending EXTRA-ARGS." - (let* ((args (list "-o" "max_tokens" (number-to-string llm-max-tokens))) + (let* ((args nil) + (args (if-let ((extra-args (alist-get llm-model llm-model-extra-args-alist nil nil #'equal))) + (append extra-args args) + args)) (args (if llm-model (append (list "--model" llm-model) args) args))