labnotes

AI in Emacs

everything in emacs

tags
ollama
emacs
ai

Everything is better with emacs. Lets see how we can plug in ollama into it. We are going to use ellama and they like the zephyr, so lets pull that. You can configure it to use other things, but lets go with the defaults for now.

Installation

1
  ollama pull zephyr

Update your repos

M-x straight-pull-recipe-repositories

Then:

1
2
3
4
5
6
  (use-package ellama
    :ensure t
    :init
    ;; setup key bindings
    (setopt ellama-keymap-prefix "C-c e")
    )

Chat interface

Then we can start up a chat usine ellama-chat or using C-c e a i – which is a bit of a mouthful. Let me see what it thinks about Rudolf Steiner:

Ok, so it works. Lets see what else we can do

Ask it about a document

C-c e a a

Here's what it says about this document I'm writing now:

My question: What is the purpose of this text?

The text describes how to integrate Ollama, an AI writing assistant, into the Emacs text editor using Ellama, a plugin for Emacs that facilitates communication with Ollama. The author explains how to install and configure Ellama, shows examples of its chat interface and grammar improvement features, and demonstrates how it can be used to define words and complete code automatically. The author also provides references for further information about Ellama and the Zephyr model that Ollama uses. Overall, the text aims to demonstrate the potential benefits of using AI in Emacs through the use of Ellama.

Neat.

Summarize a webpage

C-c e s w:

For example:

https://www.nytimes.com/2024/02/29/world/europe/navalny-prison-russia.html:

Five former inmates who served time at the same prison as Russian opposition leader Aleksei Navalny have described the conditions there as among the harshest in Russia's penal system, with brutal cold, repulsive food, unsanitary conditions and beatings. The men said that the psychological pressure and loneliness were especially dreaded, designed to break the human spirit by making survival depend on total and unconditional obedience to guards. This was echoed by Navalny himself in occasional social media posts during his time there. He died at the prison, known as IK-3 or the Troika, two weeks ago, aged 44. The men interviewed spoke of complete and utter annihilation, some saying it had left them struggling with mental illness since their release.

Improve grammer

Create a new buffer, copy something into it.

Here be a file that is written sloppyish. because typing really fast on my phone.

M-x ellama-improve-grammar

This is a file written in a sloppy manner due to rapid typing on my mobile device. Because typing quickly on my phone. No additional quotes needed.

Define word

Point at a word, then C-c e d w. For example, nonplused:

Nonplussed is a term used to describe someone who is unaffected, unperturbed, or indifferent in response to an unexpected or surprising situation. In other words, a person who is nonplussed remains calm and composed, without showing any sign of surprise, shock, or discomfort. This word originated from the French expression "plus de l'une que de l'autre", which literally means "no more one than the other" and suggests that someone in this state has equal reactions to both positive and negative events. In essence, being nonplussed implies a person's ability to maintain their composure and react rationally in any circumstance.

Code complete

C-c e c c is code complete. So we can make a comment, like

1
  # Write a function that computes the fibonacci sequence

And put the cursor after that, and it will spit out:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Define a method to compute the Fibonacci sequence recursively
def fibonacci(n)
  # Base case for empty or single element sequences
  return n if n <= 1
  
  # Recursive call to calculate the sum of the previous two numbers in the sequence
  fibonacci(n - 1) + fibonacci(n - 2)
end

# Test the function with a few examples
puts fibonacci(0)    # => 0
puts fibonacci(1)    # => 1
puts fibonacci(5)   # => 5 (Fibonacci sequence: 0, 1, 1, 2, 3)

Which then spits out

0
1
5

Previously

fragments

Fifteen or twenty thousand years

tags

Next

fragments

5 year old hacking chatgpt

tags