pop-up buffer for ellama chat. much better.

This commit is contained in:
Levi Neely 2024-09-17 20:16:27 +02:00
parent 9efeff0dd9
commit 8493f5c880
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,38 @@
;;; module-ellama-capture.el -- improve ellama chat interaction
;;;
;;; Commentary:
;;;
;;; This module provides an org-capture-like functionality for
;;; interacting with Ellama. It allows users to pop up a temporary
;;; buffer for inputting and submitting text, which can then be fed
;;; into Ellama's underlying functions.
;;; Code:
(defun ellama-capture ()
"Create a temporary pop-up buffer for Ellama input."
(interactive)
(let ((buf (get-buffer-create "*Ellama Input*")))
(with-current-buffer buf
(erase-buffer)
(text-mode)
(use-local-map (copy-keymap text-mode-map))
(local-set-key (kbd "C-c C-c") 'ellama-capture-finalize)
(local-set-key (kbd "C-c C-k") 'ellama-capture-abort))
(pop-to-buffer buf)
(message "Type your message, then C-c C-c to send or C-c C-k to abort")))
(defun ellama-capture-finalize ()
"Send the content of the Ellama input buffer to Ellama and kill the buffer."
(interactive)
(let ((content (buffer-string)))
(kill-buffer (current-buffer))
(ellama-chat content)))
(defun ellama-capture-abort ()
"Kill the Ellama input buffer without sending its content."
(interactive)
(kill-buffer (current-buffer))
(message "Ellama input aborted"))
;;; module-ellama-capture.el ends here.

View File

@ -25,6 +25,18 @@
(with-eval-after-load 'ellama
(ellama-setup-keymap))
(defun ellama-context-add-marked-files ()
"Add all marked files in Dired to Ellama context."
(interactive)
(let ((marked-files (dired-get-marked-files)))
(if (null marked-files)
(message "No files marked")
(dolist (file marked-files)
(ignore-errors (ellama-context-add-file file)))
(message "Added %d file(s) to Ellama context" (length marked-files)))))
(with-eval-after-load 'dired
(define-key dired-mode-map (kbd "C-c e") #'ellama-context-add-marked-files))
;;(pkg/require 'org-ai)
(straight-use-package
@ -33,6 +45,8 @@
(require 'org-ai)
(add-hook 'org-mode-hook #'org-ai-mode)
(require 'module-ellama-capture)
(provide 'module-llm)
;;; module-llm.el ends here.