[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ellama 3ea88206b1 1/5: Support cancellation
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ellama 3ea88206b1 1/5: Support cancellation |
Date: |
Sun, 7 Jan 2024 18:57:58 -0500 (EST) |
branch: externals/ellama
commit 3ea88206b1103b43bcd01f0c4f88b9aa3918af4e
Author: Sergey Kostyaev <sskostyaev@gmail.com>
Commit: Sergey Kostyaev <sskostyaev@gmail.com>
Support cancellation
Fixes #27
---
NEWS.org | 2 ++
ellama.el | 44 ++++++++++++++++++++++++++++----------------
2 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index 5da3f2d133..048c0f30d6 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,3 +1,5 @@
+* Version 0.5.3
+- Support cancellation.
* Version 0.5.2
- Make default prompt templates customizable.
* Version 0.5.1
diff --git a/ellama.el b/ellama.el
index bbcba3045b..7576eb1ebe 100644
--- a/ellama.el
+++ b/ellama.el
@@ -6,7 +6,7 @@
;; URL: http://github.com/s-kostyaev/ellama
;; Keywords: help local tools
;; Package-Requires: ((emacs "28.1") (llm "0.6.0") (spinner "1.7.4"))
-;; Version: 0.5.2
+;; Version: 0.5.3
;; SPDX-License-Identifier: GPL-3.0-or-later
;; Created: 8th Oct 2023
@@ -258,6 +258,8 @@
(defvar-local ellama--change-group nil)
+(defvar-local ellama--current-request nil)
+
(defconst ellama--code-prefix
(rx (minimal-match
(zero-or-more anything) (literal "```") (zero-or-more anything)
line-end)))
@@ -294,6 +296,13 @@
nil)))
" ")))
+(defun ellama--cancel-current-request (&rest _)
+ "Cancel current running request."
+ (when ellama--current-request
+ (llm-cancel-request ellama--current-request)))
+
+(advice-add #'keyboard-quit :before #'ellama--cancel-current-request)
+
(defun ellama-stream (prompt &rest args)
"Query ellama for PROMPT.
ARGS contains keys for fine control.
@@ -356,21 +365,24 @@ when the request completes (with BUFFER current)."
(set-marker-insertion-type start nil)
(set-marker-insertion-type end t)
(spinner-start ellama-spinner-type)
- (llm-chat-streaming ellama-provider
- ellama--chat-prompt
- insert-text
- (lambda (text)
- (funcall insert-text text)
- (with-current-buffer buffer
- (undo-amalgamate-change-group
ellama--change-group)
- (accept-change-group ellama--change-group)
- (spinner-stop)
- (funcall donecb text)))
- (lambda (_ msg)
- (with-current-buffer buffer
- (cancel-change-group ellama--change-group)
- (spinner-stop)
- (funcall errcb msg))))))))
+ (setq ellama--current-request
+ (llm-chat-streaming ellama-provider
+ ellama--chat-prompt
+ insert-text
+ (lambda (text)
+ (funcall insert-text text)
+ (with-current-buffer buffer
+ (undo-amalgamate-change-group
ellama--change-group)
+ (accept-change-group ellama--change-group)
+ (spinner-stop)
+ (funcall donecb text)
+ (setq ellama--current-request nil)))
+ (lambda (_ msg)
+ (with-current-buffer buffer
+ (cancel-change-group ellama--change-group)
+ (spinner-stop)
+ (funcall errcb msg)
+ (setq ellama--current-request nil)))))))))
(defun ellama-chat-done (_)
"Chat done."