[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ellama 6a426dd913 2/8: Programmatically translate code
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ellama 6a426dd913 2/8: Programmatically translate code blocks from markdown to org-mode |
Date: |
Fri, 19 Jan 2024 18:57:59 -0500 (EST) |
branch: externals/ellama
commit 6a426dd9137fe45dc2e7c4e6052d258d731f10f2
Author: Sergey Kostyaev <sskostyaev@gmail.com>
Commit: Sergey Kostyaev <sskostyaev@gmail.com>
Programmatically translate code blocks from markdown to org-mode
---
ellama.el | 36 ++++++++++++++++--------------------
1 file changed, 16 insertions(+), 20 deletions(-)
diff --git a/ellama.el b/ellama.el
index 1fc00dc4bc..6d50b1f1b6 100644
--- a/ellama.el
+++ b/ellama.el
@@ -253,24 +253,6 @@ It should be a function with single argument generated
text string."
:group 'ellama
:type 'function)
-(defcustom ellama-chat-system-prompt "You are helpful assistant. Use org-mode
syntax in your responses. A source code block conforms to this structure:
-
-#+NAME: <name>
-#+BEGIN_SRC <language> <switches> <header arguments>
- <body>
-#+END_SRC
-
- For example, if you add python code to your answer it should look like this:
-
-#+BEGIN_SRC python
- def foo(x):
- if x>0:
- return x+1
-#+END_SRC"
- "System prompt for ollama chat."
- :group 'ellama
- :type 'string)
-
(defvar-local ellama--change-group nil)
(defvar-local ellama--current-request nil)
@@ -283,11 +265,24 @@ It should be a function with single argument generated
text string."
(rx (minimal-match
(literal "```") (zero-or-more anything))))
+(defconst ellama--code-translate-prefix
+ "^```\\(.+\\)$")
+
+(defconst ellama--code-translate-suffix
+ "^```$")
+
(defun ellama--code-filter (text)
"Filter code prefix/suffix from TEXT."
;; Trim left first as `string-trim' trims from the right and ends up
deleting all the code.
(string-trim-right (string-trim-left text ellama--code-prefix)
ellama--code-suffix))
+(defun ellama--code-block-translate-to-org-filter (text)
+ "Filter to translate code blocks from markdown syntax to org syntax."
+ (replace-regexp-in-string
+ ellama--code-translate-suffix "#+END_SRC"
+ (replace-regexp-in-string
+ ellama--code-translate-prefix "#+BEGIN_SRC \\1" text)))
+
(defcustom ellama-enable-keymap t
"Enable or disable Ellama keymap."
:type 'boolean
@@ -638,7 +633,7 @@ If CREATE-SESSION set, creates new session even if there is
an active session."
current-prefix-arg
(and (not ellama--current-session)
(not ellama--current-session-id)))
- (ellama-new-session provider prompt
ellama-chat-system-prompt)
+ (ellama-new-session provider prompt nil)
(or ellama--current-session
(with-current-buffer (ellama-get-session-buffer
ellama--current-session-id)
@@ -653,7 +648,8 @@ If CREATE-SESSION set, creates new session even if there is
an active session."
ellama-nick-prefix " " ellama-assistant-nick ":\n")
(ellama-stream prompt
:session session
- :on-done #'ellama-chat-done)))))
+ :on-done #'ellama-chat-done
+ :filter #'ellama--code-block-translate-to-org-filter)))))
;;;###autoload
(defun ellama-ask-about ()
- [elpa] externals/ellama updated (b301ed87f5 -> 77d614fd44), ELPA Syncer, 2024/01/19
- [elpa] externals/ellama 6a426dd913 2/8: Programmatically translate code blocks from markdown to org-mode,
ELPA Syncer <=
- [elpa] externals/ellama dec7ebdf5e 3/8: Improve org processing, ELPA Syncer, 2024/01/19
- [elpa] externals/ellama f6337ebb79 6/8: Add ellama-long-lines-length custom variable, ELPA Syncer, 2024/01/19
- [elpa] externals/ellama 466f16f425 7/8: Update documentation, ELPA Syncer, 2024/01/19
- [elpa] externals/ellama 8bab25150a 1/8: Use org-mode by default for chat. Experimental, ELPA Syncer, 2024/01/19
- [elpa] externals/ellama 77d614fd44 8/8: Merge pull request #52 from s-kostyaev/org-experiment, ELPA Syncer, 2024/01/19
- [elpa] externals/ellama 1213032397 4/8: Use org-mode for ellama-instant, ELPA Syncer, 2024/01/19
- [elpa] externals/ellama 02bb628778 5/8: Fix bug wrong clearing session, ELPA Syncer, 2024/01/19