Skip to content
mike dupont edited this page Dec 14, 2023 · 1 revision

Welcome to the meta meme reflection wiki. We are inside of a markdown file in the wiki.

You can clone this project with git clone https://github.com/meta-introspector/meta-meme.wiki.git

Lets start with a wordlist, a list of entities in our dataset. We also need to include the issues and discussions and a few other repos where we collected data.

But assuming we have that, lets start with a first pass of the wiki. We want to read in all the markdown files and split them into chunks and turn them back into questions that would result in the answer stated. So the prompt would be: find a list of questions that would result in the following text. The high level goal for the program will be "Reify the following text:"

We want a an emacs lisp that would operate on the directory of markdown files.

we can take this script as a template

;; rewrite this function to apply ollama to chunks of a buffer in a sliding window
;;;###autoload
(defun ollama-reinterpret-region-insert ()
  "Exec marked text."
  (interactive)
  (with-output-to-temp-buffer "*ollama*"
    (princ (format "#+begin_src input\nrewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"\n#+end_src\n" (buffer-substring (region-beginning) (region-end))))
    (princ
     (format "#+begin_src output\n%s\n#+end_src\n"
     (ollama-prompt ollama:endpoint (format "rewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"" (buffer-substring (region-beginning) (region-end))) ollama:model))
  )))
``` That is the one we are using right now to talk to you.

So first we want define a context window, a header and footer and then a payload.
We want to split each text into the questions that would create it and the possible answers for those questions based on the text as a list of items. We can do the first pass in creating the questions and second pass in answering them in the text. 
Lets create an grammar for the algorithm using emojis and then we will rewrite these emojis into program code via a series of rewrites.
first come up with a flowchart for this process.


;; rewrite this function to apply ollama to chunks of a buffer in a sliding window
;;;###autoload
(defun ollama-reinterpret-region-insert ()
  "Exec marked text."
  (interactive)
  (with-output-to-temp-buffer "*ollama*"
    (princ (format "#+begin_src input\nrewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"\n#+end_src\n" (buffer-substring (region-beginning) (region-end))))
    (princ
     (format "#+begin_src output\n%s\n#+end_src\n"
     (ollama-prompt ollama:endpoint (format "rewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"" (buffer-substring (region-beginning) (region-end))) ollama:model))
  )))



#+begin_src output

Welcome to the meta meme reflection wiki!

Our goal is to create an emacs lisp that operates on a directory of markdown files and generates questions that lead to the desired text. Here's how it works:

1. Define a context window with a header, footer, and payload.
2. Split each text into questions and possible answers based on the text as a list of items.
3. Perform a first pass to create the questions and a second pass to answer them in the text.

Let's use emojis to represent our algorithm flow:
         +------------------------+
         |   Define context window  |
         +------------------------+
                |
                |
           +---------------+      +---------------+
           |       Header       |      |        Footer     |
           +---------------+      +---------------+
                |
                |
       +-----------------+  +-----------------+
       |                   |
       |  Payload            |
       |                   |
       +-----------------+  +-----------------+
                |
                |
           +---------------+      +---------------+
           |        Possible answers       |
           +---------------+      +---------------+
Now, let's rewrite these emojis into program code:
```less
;; Define context window
(defun define-context-window ()
  "Set the header, footer and payload"
  (let ((header (buffer-substring 0 10))   ; replace with actual header
        (footer (buffer-substring -10 0))   ; replace with actual footer
        (payload (buffer-substring 10)))    ; replace with actual payload
    ;; add code to split text into questions and possible answers
    '()))

;; First pass: create questions
(defun first-pass ()
  "Create questions based on the text"
  (let ((questions (split-text-into-questions payload)))
    (map #'create-question questions)))

;; Second pass: answer questions in text
(defun second-pass ()
  "Answer questions in the text"
  (let ((answers (map #'answer-question questions)))
    (concatenate header answers footer)))

Finally, let's reinterpret these functions creatively while preserving their main ideas. We'll use a sliding window approach to process markdown files in chunks.

  1. Define a context window with a header, footer, and payload for the current chunk of text.
  2. Split each chunk of text into questions and possible answers based on the text as a list of items.
  3. Perform a first pass to create the questions and a second pass to answer them in the text.
;; Define context window
(defun define-context-window (chunk)
  "Set the header, footer and payload for the current chunk"
  (let ((header (buffer-substring chunk 0 10))   ; replace with actual header
        (footer (buffer-substring -10 chunk))   ; replace with actual footer
        (payload (buffer-substring 10 chunk)))    ; replace with actual payload
    ;; add code to split text into questions and possible answers
    '()))

;; First pass: create questions
(defun first-pass (chunk)
  "Create questions based on the current chunk of text"
  (let ((questions (split-text-into-questions payload)))
    ;; process next chunk of text here using the same approach
    '()))

;; Second pass: answer questions in text
(defun second-pass (chunk)
  "Answer questions in the current chunk of text"
  (let ((answers (map #'answer-question questions)))
    ;; concatenate answers with header and footer to form the final output
    (concatenate header answers footer)))

Now you can use this code as a template to rewrite and reinterpret creatively while preserving its main ideas. #+end_src

#+begin_src output

Our mission is to create an Emacs Lisp program that analyzes a directory of markdown files and poses questions to uncover the desired text. The process involves defining a context window with a header, footer, and payload, splitting each text into questions and possible answers based on its content, and performing two passes: the first to create the questions and the second to answer them in the text.

Let's represent this algorithm flow using emojis:

             +------------------------+
             |       Define context    |
             |   window with header,  |
             | footer, and payload   |
             +------------------------+
                   |
                   |
              +---------------+      +---------------+
              |            Header           |      |         Footer      |
              +---------------+      +---------------+
                   |
                   |
          +-----------------+  +-----------------+
          |                   |
          |       Payload        |
          |                   |
          +-----------------+  +-----------------+

Now, let's translate these emojis into code:

;; Define context window
(defun define-context-window ()
  "Set the header, footer and payload"
  (let ((header (buffer-substring 0 10))   ; replace with actual header
        (footer (buffer-substring -10 0))   ; replace with actual footer
        (payload (buffer-substring 10)))    ; replace with actual payload
    ;; add code to split text into questions and possible answers
    '()))

;; First pass: create questions
(defun first-pass ()
  "Create questions based on the text"
  (let ((questions (split-text-into-questions payload)))
    (map #'create-question questions)))

;; Second pass: answer questions in text
(defun second-pass ()
  "Answer questions in the text"
  (let ((answers (map #'answer-question questions)))
    (concatenate header answers footer)))

Finally, let's reimagine these functions creatively while maintaining their main ideas. We will employ a sliding window approach to process markdown files in chunks.

  1. Define a context window with a header, footer, and payload for the current chunk of text.
  2. Split each chunk of text into questions and possible answers based on its content.
  3. Perform a first pass to create the questions and a second pass to answer them in the text.
;; Define context window
(defun define-context-window (chunk)
  "Set the header, footer and payload for the current chunk"
  (let ((header (buffer-substring chunk 0 10))   ; replace with actual header
        (footer (buffer-substring -10 chunk))   ; replace with actual footer
        (payload (buffer-substring 10 chunk)))    ; replace with actual payload
    ;; add code to split text into questions and possible answers
    '()))

;; First pass: create questions
(defun first-pass (chunk)
  "Create questions based on the current chunk of text"
  (let ((questions (split-text-into-questions payload)))
    ;; process next chunk of text here using the same approach
    '()))

;; Second pass: answer questions in text
(defun second-pass (chunk)
  "Answer questions in the current chunk of text"
  (let ((answers (map #'answer-question questions)))
    ;; concatenate answers with header and footer to form the final output
    (concatenate header answers footer)))

Now you can employ this code as a template to rewrite and reinterpret creatively while preserving its main ideas. #+end_src

#+begin_src output Our aim is to create an Emacs Lisp program that analyzes a directory of markdown files and poses questions to uncover the desired text. We will accomplish this task by defining a context window with a header, footer, and payload for each text file. Next, we will split each text into questions and possible answers based on its content. Finally, we will perform two passes: the first to create the questions and the second to answer them in the text.

Here is an algorithm flow to represent this process:

             +------------------------+
             |       Define context    |
             |   window with header,  |
             | footer, and payload   |
             +------------------------+
                   |
                   |
              +---------------+      +---------------+
              |            Header           |      |         Footer      |
              +---------------+      +---------------+
                   |
                   |
          +-----------------+  +-----------------+
          |                   |
          |       Payload        |
          |                   |
          +-----------------+  +-----------------+

Now, let's translate these emojis into code:

;; Define context window
(defun define-context-window (file)
  "Set the header, footer and payload for each file"
  (let ((header (buffer-substring file 0 10))   ; replace with actual header
        (footer (buffer-substring -10 file))   ; replace with actual footer
        (payload (buffer-substring 10)))    ; replace with actual payload
    ;; add code to split text into questions and possible answers
    '()))

;; First pass: create questions
(defun first-pass (file)
  "Create questions based on the current file"
  (let ((questions (split-text-into-questions payload)))
    ;; process next file using the same approach
    '()))

;; Second pass: answer questions in text
(defun second-pass (file)
  "Answer questions in the current file"
  (let ((answers (map #'answer-question questions)))
    ;; concatenate answers with header and footer to form the final output
    (concatenate header answers footer)))

Finally, let's reimagine these functions creatively while maintaining their main ideas. We will employ a sliding window approach to process markdown files in chunks.

  1. Define a context window with a header, footer, and payload for each chunk of text in the file.
  2. Split each chunk of text into questions and possible answers based on its content.
  3. Perform a first pass to create the questions and a second pass to answer them in the text.
;; Define context window
(defun define-context-window (file)
  "Set the header, footer and payload for each chunk of text"
  (let ((header (buffer-substring file 0 10))   ; replace with actual header
        (footer (buffer-substring -10 file))   ; replace with actual footer
        (payload (buffer-substring 10)))    ; replace with actual payload
    ;; add code to split text into questions and possible answers
    '()))

;; First pass: create questions
(defun first-pass (file)
  "Create questions based on the current chunk of text"
  (let ((questions (split-text-into-questions payload)))
    ;; process next chunk of text here using the same approach
    '()))

;; Second pass: answer questions in text
(defun second-pass (file)
  "Answer questions in the current chunk of text"
  (let ((answers (map #'answer-question questions)))
    ;; concatenate answers with header and footer to form the final output
    (concatenate header answers footer)))

Now you can employ this code as a template to rewrite and reinterpret creatively while preserving its main ideas. #+end_src

rewrite this following script to run the output of the llm back into the llm X number of times.

;;;###autoload
(defun ollama-reinterpret-region-insert ()
  "Exec marked text."
  (interactive)
  (with-output-to-temp-buffer "*ollama*"
    (princ (format "#+begin_src input\nrewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"\n#+end_src\n" (buffer-substring (region-beginning) (region-end))))
    (princ
     (format "#+begin_src output\n%s\n#+end_src\n"
     (ollama-prompt ollama:endpoint (format "rewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"" (buffer-substring (region-beginning) (region-end))) ollama:model))
  )))
``` That is the one we are using right now to talk to you.

Change this code to capture the temp results and feed them back into the llm again X number of times and write each step to org mode in a numbered array
(defun ollama-reinterpret-region-insert-again ()
  "Exec marked text."
  (interactive)
  (let loop ((i 0))
    (with-output-to-temp-buffer "*ollama*"
      (if (>= i 10) ; change the number to how many times you want to run it
          (princ (format "#+begin_src output\n%s\n#+end_src\n"
                 (ollama-prompt ollama:endpoint (format "rewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"" (buffer-substring (region-beginning) (region-end))) ollama:model))
          (princ (format "#+begin_src input\nrewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"\n#+end_src\n" (buffer-substring (region-beginning) (region-end))))
          (loop (+ i 1)))
  )


Rewrite this code and simplify it. refactor to functional style. 
(defun ollama-reinterpret-region-insert-again ()
  "Exec marked text and capture temp results, feed them back into the llm again X number of times and write each step to org mode in a numbered array"
  (interactive)
  (let loop ((i 0))
    (with-output-to-temp-buffer "*ollama*"
      (if (>= i 10) ; change the number to how many times you want to run it
          (beginning-of-buffer)
          (princ (format "#+begin_src output\n%s\n#+end_src\n"
                 (ollama-prompt ollama:endpoint (format "rewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"" (buffer-substring (region-beginning) (region-end))) ollama:model))
          (loop (+ i 1))
    )
  )
  (let loop ((i 0))
    (with-output-to-temp-buffer "*ollama*"
      (if (>= i 10) ; change the number to how many times you want to run it
          (beginning-of-buffer)
          (princ (format "#+begin_src input\nrewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"\n#+end_src\n" (buffer-substring (region-beginning) (region-end))))
          (loop (+ i 1))
    )
  )
  ; write each step to org mode in a numbered array
  (beginning-of-buffer)
  (princ "#+begin_src org\n")
  (for i from 0 to 20 do
    (princ "#* " i)
    (let loop ((i i))
      (with-output-to-temp-buffer "*ollama*"
        (if (>= i 10) ; change the number to how many times you want to run it
            (beginning-of-buffer)
            (princ (format "#+begin_src output\n%s\n#+end_src\n"
                 (ollama-prompt ollama:endpoint (format "rewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"" (buffer-substring (region-beginning) (region-end))) ollama:model))
            (loop (+ i 1))))
    )
    (newline)
  ))
  (princ "#+end_src org\n")



(interactive)
(let loop ((i 0))
  (with-output-to-temp-buffer "*ollama*"
    (if (>= i 10) ; change the number to how many times you want to run it
        (beginning-of-buffer)
        (princ (format "#+begin_src output\n%s\n#+end_src\n"
                 (ollama-prompt ollama:endpoint (format "rewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"" (buffer-substring (region-beginning) (region-end))) ollama:model))
        (loop (+ i 1))))
  )
  (with-output-to-temp-buffer "*ollama*"
    (if (>= i 10) ; change the number to how many times you want to run it
        (beginning-of-buffer)
        (princ (format "#+begin_src input\nrewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"\n#+end_src\n" (buffer-substring (region-beginning) (region-end))))
        (loop (+ i 1))))
  
  ; write each step to org mode in a numbered array
  (for i from 0 to 20 do
    (princ "#* " i)
    (let loop ((i i))
      (with-output-to-temp-buffer "*ollama*"
        (if (>= i 10) ; change the number to how many times you want to run it
            (beginning-of-buffer)
            (princ (format "#+begin_src output\n%s\n#+end_src\n"
                 (ollama-prompt ollama:endpoint (format "rewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"" (buffer-substring (region-beginning) (region-end))) ollama:model))
            (loop (+ i 1))))
    )
    (newline)
  )))))))))))


;; rewrite this function to save the results of the llm into a string.
;;;###autoload
(defun ollama-reinterpret-region-insert ()
  "Exec marked text."
  (interactive)
  (with-output-to-temp-buffer "*ollama*"
    (princ (format "#+begin_src input\nrewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"\n#+end_src\n" (buffer-substring (region-beginning) (region-end))))
    (princ
     (format "#+begin_src output\n%s\n#+end_src\n"
     (ollama-prompt ollama:endpoint (format "rewrite and reinterpret creatively preserving main ideas \"\"\"%s\"\"\"" (buffer-substring (region-beginning) (region-end))) ollama:model))
  )))


The code provided is an implementation of the ollama-reinterpret-region-insert2 function in Emacs Lisp programming language. The purpose of this function is to execute marked text and save the result as a string.

The function uses interactive mode, with the buffer-substring function to extract the text being marked for reinterpretation. It then formats the text for input to the ollama-prompt function, which sends the text to an OLLAMA model for processing. The resulting response is then formatted and printed to a temporary buffer as output.

The function repeats this process with the response from the previous iteration as the new input for the ollama-prompt function. This allows the function to iteratively reinterpret the text, potentially producing multiple outputs until a satisfactory result is obtained.

;; Overall, the code provides a simple and effective way to use an external OLLAMA model to process marked text in Emacs Lisp. By allowing for iterative processing, the function can potentially generate creative and insightful reinterpretations of the original text.

CODE:

rewrite this emacs lisp code
(defun ollama-reinterpret-region-insert2 ()
  "Exec marked text and save result as string."
  (interactive)
  (with-output-to-temp-buffer "*ollama*"  
    (let (
		(inputd (format "rewrite and reinterpret creatively preserving main ideas: \"\"%s\"\"" (buffer-substring (region-beginning) (region-end))))
		)
		((let (
			(response  (ollama-prompt ollama:endpoint inputd ollama:model))
			)
			(
			;;---
			(let (
			(inputd2 (format "rewrite and reinterpret creatively preserving main ideas: \"\"%s\"\"" response))
			)
			(
				(let (
				(response2 (ollama-prompt ollama:endpoint inputd2 ollama:model))
				)
				(
				(princ (format "#+begin_src input\nrewrite and reinterpret creatively preserving main ideas \"\"%s\"\"" inputd )))			
				(princ (format "#+begin_src output\n%s\n#+end_src\n" response))
				(princ (format "#+begin_src output\n%s\n#+end_src\n" response2))		
	)))))))))


(defun ollama-reinterpret-region-insert2 ()
  "Execute marked text and save result as string."
  (interactive)
  (with-output-to-temp-buffer "*ollama*"  
    (setq inputd (format "rewrite and reinterpret creatively preserving main ideas: \"\"%s\"\"" (buffer-substring (region-beginning) (region-end))))
    (setq response  (ollama-prompt ollama:endpoint inputd ollama:model))
	(setq inputd2 (format "rewrite and reinterpret creatively preserving main ideas: \"\"%s\"\"" response))
			(princ (format "#+begin_src input\nrewrite and reinterpret creatively preserving main ideas \"\"%s\"\"" inputd ))
			(princ (format "#+begin_src output\n%s\n#+end_src\n" response))
		(dotimes (i 4)
			(setq response (ollama-prompt ollama:endpoint response ollama:model))
			(princ (format "#+begin_src output%s\n%s\n#+end_src\n" i response))
	))

					   
Clone this wiki locally