branch: externals/ellama
commit 6615a857d62008759173bc6d709bda87a63019d0
Merge: 2b75043cd6 280b97119a
Author: Sergey Kostyaev <s-kosty...@users.noreply.github.com>
Commit: GitHub <nore...@github.com>

    Merge pull request #217 from s-kostyaev/improve-ctx
    
    Improve working with context
---
 NEWS.org  | 12 ++++++++++--
 ellama.el | 39 +++++++++++++++++++++++++++------------
 2 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index 3a2a696fa7..459acd14a3 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,6 +1,14 @@
+* Version 1.1.3
+- Ensure unique elements in session and global contexts.
+- Change default transient host and port to fix ollama provider setup.
+- Deactivate ellama session on setting ellama-provider.
+- Added functionality to convert Org mode content to Markdown when
+  extracting buffer or file content for the context. This ensures that
+  any Org mode files are properly formatted as Markdown before being
+  processed further.
 * Version 1.1.2
-- Clear session context on calling reset context commant to prevent
-  suprising behaviour.
+- Clear session context when resetting context to prevent unexpected
+  behavior.
 * Version 1.1.1
 - Improve ~ellama-add-selection~.
 - Add buffer quote context element.
diff --git a/ellama.el b/ellama.el
index ae7c8ff0c8..f8d56e8e26 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.22.0") (spinner "1.7.4") 
(transient "0.7") (compat "29.1") (posframe "1.4.0"))
-;; Version: 1.1.2
+;; Version: 1.1.3
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;; Created: 8th Oct 2023
 
@@ -1084,8 +1084,8 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
   (if-let* ((id ellama--current-session-id)
            (session (with-current-buffer (ellama-get-session-buffer id)
                       ellama--current-session)))
-      (push element (ellama-session-context session)))
-  (push element ellama--global-context)
+      (cl-pushnew element (ellama-session-context session) :test 
#'equal-including-properties))
+  (cl-pushnew element ellama--global-context :test 
#'equal-including-properties)
   (get-buffer-create ellama--context-buffer t)
   (with-current-buffer ellama--context-buffer
     (erase-buffer)
@@ -1115,7 +1115,11 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
   "Extract the content of the context ELEMENT."
   (with-slots (name) element
     (with-current-buffer name
-      (buffer-substring-no-properties (point-min) (point-max)))))
+      (let* ((data (buffer-substring-no-properties (point-min) (point-max)))
+            (content (if (derived-mode-p 'org-mode)
+                         (ellama-convert-org-to-md data)
+                       data)))
+       content))))
 
 (cl-defmethod ellama-context-element-display
   ((element ellama-context-element-buffer))
@@ -1189,7 +1193,11 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
   (with-slots (name) element
     (with-temp-buffer
       (insert-file-contents name)
-      (buffer-substring-no-properties (point-min) (point-max)))))
+      (let* ((data (buffer-substring-no-properties (point-min) (point-max)))
+            (ext (file-name-extension name)))
+       (if (string= ext "org")
+           (ellama-convert-org-to-md data)
+         data)))))
 
 (cl-defmethod ellama-context-element-display
   ((element ellama-context-element-file))
@@ -1503,7 +1511,10 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
   "Add active region to context."
   (interactive)
   (if (region-active-p)
-      (let* ((content (buffer-substring-no-properties (region-beginning) 
(region-end)))
+      (let* ((data (buffer-substring-no-properties (region-beginning) 
(region-end)))
+            (content (if (derived-mode-p 'org-mode)
+                         (ellama-convert-org-to-md data)
+                       data))
             (file-name (buffer-file-name))
             (buffer-name (buffer-name (current-buffer)))
              (element (if file-name
@@ -2617,8 +2628,8 @@ Call CALLBACK on result list of strings.  ARGS contains 
keys for fine control.
 (defvar ellama-transient-ollama-model-name "")
 (defvar ellama-transient-temperature 0.7)
 (defvar ellama-transient-context-length 4096)
-(defvar ellama-transient-host nil)
-(defvar ellama-transient-port nil)
+(defvar ellama-transient-host "localhost")
+(defvar ellama-transient-port 11434)
 
 (transient-define-suffix ellama-transient-set-ollama-model ()
   "Set ollama model name."
@@ -2664,10 +2675,14 @@ Call CALLBACK on result list of strings.  ARGS contains 
keys for fine control.
 (transient-define-suffix ellama-transient-set-provider ()
   "Set transient model to provider."
   (interactive)
-  (set (read
-       (completing-read "Select provider: "
-                        (mapcar #'prin1-to-string ellama-provider-list)))
-       (ellama-construct-ollama-provider-from-transient)))
+  (let ((provider (read
+                  (completing-read "Select provider: "
+                                   (mapcar #'prin1-to-string 
ellama-provider-list)))))
+    (set provider
+        (ellama-construct-ollama-provider-from-transient))
+    ;; if you change `ellama-provider' you probably want to start new chat 
session
+    (when (equal provider 'ellama-provider)
+      (setq ellama--current-session-id nil))))
 
 (transient-define-prefix ellama-select-ollama-model ()
   "Select ollama model."

Reply via email to