108 lines
3.8 KiB
EmacsLisp
108 lines
3.8 KiB
EmacsLisp
;; -*- lexical-binding: t; -*-
|
|
|
|
(use-package gptel
|
|
:commands (gptel-send
|
|
gptel
|
|
gptel-request)
|
|
:config
|
|
(setq gptel-model "llama3:latest"
|
|
gptel-backend (gptel-make-ollama "Ollama"
|
|
:stream t
|
|
:models '("llama3:latest"
|
|
"mistral:latest")))
|
|
:general
|
|
("C-c RET" #'gptel-send
|
|
"C-c C-<return>" #'gptel-menu))
|
|
|
|
(use-package gptel-quick
|
|
:straight (:type git :host github :repo "karthink/gptel-quick")
|
|
:commands gptel-quick
|
|
:general
|
|
(embark-general-map
|
|
"?" #'gptel-quick))
|
|
|
|
(use-package llama
|
|
:straight `(:local-repo ,(expand-file-name "packages/llama" user-emacs-directory) :type nil)
|
|
:load-path "packages/llama"
|
|
:config
|
|
(require 'llm-ollama)
|
|
(setq llama-llm-provider (make-llm-ollama :chat-model "llama3:latest")
|
|
llm-warn-on-nonfree nil))
|
|
|
|
(defvar comfy-ui-path (expand-file-name "~/ComfyUI")
|
|
"Path to ComfyUI source repository.")
|
|
|
|
(defvar comfy-ui-command (list "pipenv" "run" "python" "main.py")
|
|
"Command to run ComfyUI server.")
|
|
|
|
(defvar-local comfy-ui--url nil
|
|
"URL for this buffer's ComfyUI process.")
|
|
|
|
(defun comfy-ui-process-filter (proc string)
|
|
(when-let ((match (s-match "To see the GUI go to: \\(.*\\)" string)))
|
|
(with-current-buffer (process-buffer proc)
|
|
(setq comfy-ui--url (nth 1 match))
|
|
(browse-url comfy-ui--url)))
|
|
(when (buffer-live-p (process-buffer proc))
|
|
(with-current-buffer (process-buffer proc)
|
|
(let ((moving (= (point) (process-mark proc))))
|
|
(save-excursion
|
|
;; Insert the text, advancing the process marker.
|
|
(goto-char (process-mark proc))
|
|
(insert string)
|
|
(set-marker (process-mark proc) (point)))
|
|
(if moving (goto-char (process-mark proc)))))))
|
|
|
|
(defun comfy-ui ()
|
|
"Launch Comfy UI in a subprocess and opens the web UI."
|
|
(interactive)
|
|
(unless (file-exists-p (expand-file-name (f-join comfy-ui-path "main.py")))
|
|
(user-error "Could not find ComfyUI installation!"))
|
|
(if-let ((proc (get-process "comfy-ui")))
|
|
(with-current-buffer (process-buffer proc)
|
|
(browse-url comfy-ui--url))
|
|
(with-temp-buffer
|
|
(cd comfy-ui-path)
|
|
(make-process :name "comfy-ui"
|
|
:buffer "*ComfyUI*"
|
|
:command comfy-ui-command
|
|
:filter #'comfy-ui-process-filter))))
|
|
|
|
(defvar ollama-copilot-proxy-port 11435
|
|
"Port for the Ollama Copilot proxy server.")
|
|
|
|
(defvar ollama-copilot-model "codellama:code"
|
|
"Model for the Ollama Copilot proxy server.")
|
|
|
|
(defun ollama-copilot-ensure ()
|
|
"Start the Ollama Copilot proxy server if it's not already running."
|
|
(let ((proc-name "ollama-copilot"))
|
|
(unless (get-process proc-name)
|
|
(unless (executable-find "ollama-copilot")
|
|
(user-error "Could not find ollama-copilot executable!"))
|
|
(make-process :name proc-name
|
|
:buffer (format "*%s*" proc-name)
|
|
:command `("ollama-copilot"
|
|
"-proxy-port" ,(format ":%s" ollama-copilot-proxy-port)
|
|
"-model" ,ollama-copilot-model)))))
|
|
|
|
(defvar ollama-copilot--proxy-cache nil
|
|
"Internal variable to cache the old proxy value.")
|
|
|
|
(define-minor-mode ollama-copilot-mode
|
|
"Minor mode to use ollama-copilot as a local Copilot proxy."
|
|
:global t
|
|
(require 'copilot)
|
|
(if ollama-copilot-mode
|
|
(progn
|
|
(ollama-copilot-ensure)
|
|
(setq ollama-copilot--proxy-cache copilot-network-proxy)
|
|
(setq copilot-network-proxy `(:host "127.0.0.1"
|
|
:port ,ollama-copilot-proxy-port
|
|
:rejectUnauthorized :json-false))
|
|
(copilot-diagnose))
|
|
(setq copilot-network-proxy ollama-copilot--proxy-cache)
|
|
(copilot-diagnose)))
|
|
|
|
(provide 'init-ai)
|