Every LLM in Emacs, with gptel

karthink
25 Dec 202317:56

TLDRGPTel is a client for Emacs that enables interaction with large language models (LLMs). It's simple, flexible, and supports various LLM providers. Users can communicate with LLMs asynchronously across any Emacs buffer and even configure shortcuts for ease of use. GPTel integrates smoothly, offering consistent functionality without disrupting workflow. The package also supports advanced tasks like rewriting content and explaining code. It's highly customizable, allowing users to personalize behaviors, and focuses on keeping the interface simple while enabling diverse, text-based interactions within Emacs.

Takeaways

  • 💻 GPTel is a flexible LLM client for Emacs, supporting various LLM providers and offering an asynchronous, non-intrusive interface.
  • 🛠️ Installation is straightforward via MELPA, and once set up, you can start sending requests to LLMs from anywhere in Emacs.
  • 🔑 GPTel supports persistent chats and allows you to use custom system messages to influence LLM behavior, like acting as a calculator or dictionary.
  • 🗂️ You can save chat buffers to disk in plain text formats (Org or Markdown), and GPTel can restore conversation contexts when reopening files.
  • 🧠 The tool supports using multiple LLMs (like ChatGPT, Gemini, or local models) simultaneously, offering a consistent interface across all of them.
  • 📦 GPTel aims to be simple and invisible, integrating seamlessly into Emacs without requiring special commands or dedicated buffers.
  • 📜 There's flexibility in setting directives on the fly, and GPTel offers advanced features like redirecting input/output between buffers and sessions.
  • ⚡ GPTel is fully asynchronous and tries to avoid hogging the event loop while responses are streaming in, making it efficient to use.
  • 🔧 The package is highly customizable, allowing users to change behavior, such as auto-scrolling or integrating more advanced features through hooks.
  • 📝 For more complex tasks, GPTel provides a general API for non-interactive uses, ensuring it remains lightweight and text-focused.

Q & A

  • What is GPTel and how does it work in Emacs?

    -GPTel is a simple LLM client for Emacs that supports asynchronous communication with various language models. It integrates into Emacs seamlessly, allowing users to interact with language models from any Emacs buffer.

  • How do you install GPTel in Emacs?

    -GPTel is available on MELPA. To install it, add MELPA to Emacs' package archive list, evaluate the code, and install gptel using the 'eval-buffer' command.

  • What is a system message in GPTel, and how can you use it?

    -A system message in GPTel allows you to set specific behaviors or instructions for the LLM, like making it act as a calculator or a dictionary. You can configure system messages either in Emacs settings or on the fly using a prefix argument when calling 'gptel-send'.

  • How does GPTel handle chats in Emacs buffers?

    -Chats in GPTel can be stored in regular Emacs buffers (Org or Markdown) and saved as text files. When reopening the file, turning on 'gptel-mode' restores the conversation context.

  • What makes GPTel asynchronous, and why is it useful?

    -GPTel is asynchronous, meaning it allows Emacs users to keep working while waiting for LLM responses. This helps prevent blocking the Emacs event loop and ensures a smooth workflow.

  • Can GPTel be used with multiple LLM providers, and how do they differ?

    -Yes, GPTel supports multiple LLM providers such as Google's Gemini, Mistral AI, Kagi, and OpenAI's models. Their behavior can differ, for example, some may stream responses continuously while others don't.

  • How does GPTel ensure a minimal interface within Emacs?

    -GPTel strives to be unobtrusive, integrating into any buffer without dedicated blocks or special syntax. The goal is for GPTel to blend seamlessly into Emacs' workflow, requiring minimal user attention.

  • What customization options does GPTel provide for users?

    -GPTel is highly customizable, allowing users to change default behaviors such as auto-scrolling or adding 'magic' behavior using hooks. It also offers a stable API, 'gptel-request', for custom uses.

  • How can GPTel be used for complex tasks, like handling code?

    -GPTel can process complex queries, such as explaining functions in a codebase. Users can select specific code regions and request explanations or modifications using custom directives.

  • How does GPTel handle multi-LLM queries, and is there a consistent interface?

    -GPTel offers a consistent interface for all LLMs, allowing users to query multiple LLMs simultaneously. While behaviors may differ across LLMs, the interface remains uniform for ease of use.

Outlines

00:00

🛠️ Introduction to GPTel and its Setup in Emacs

This paragraph introduces GPTel, a large language model (LLM) client for Emacs that supports persistent chats and multiple LLM providers. The goal of GPTel is to be unobtrusive and seamlessly integrated into Emacs. The paragraph then outlines the steps to install GPTel via the MELPA package archive, using a scratch buffer to evaluate and install the code. Once installed, users can interact with LLMs like ChatGPT from any Emacs buffer using gptel-send, and can bind the function to a key for convenience. The option to create a dedicated chat buffer is also mentioned, along with the ability to switch LLM providers, like Google's Gemini, through prefix arguments.

05:05

📊 GPTel in Action: Math Problems and Dictionary Functions

The second paragraph demonstrates how GPTel handles specific tasks, including math problems and dictionary functions. First, the author shows how to set GPT-4 to a 'mathematician' directive to solve definite integrals, receiving accurate responses. Then, the focus shifts to GPTel acting as a dictionary, where synonyms and antonyms are requested, with adjustments made to the system message to refine output. The author emphasizes how system messages help shape responses and how GPTel can be used across different types of buffers like markdown or org-mode in Emacs.

10:13

📚 Expanding GPTel's Use in Emacs

This paragraph expands on GPTel's flexibility, emphasizing that it can be used in any Emacs buffer without special syntax or dedicated blocks. The example highlights how GPTel can assist with LaTeX formatting by rewriting long subscripts into multiple lines. The author also explains how GPTel can be used for shell commands, such as generating CLI commands, and for function searches in Emacs, like using the 'describe-function' command. The goal is for GPTel to be unobtrusive and seamlessly integrated into Emacs workflows, allowing users to redirect responses and prompts as needed.

15:16

🔧 GPTel's Customization and Flexibility

In this paragraph, the author discusses the customization and flexibility of GPTel. The tool aims to offer a consistent interface across different LLMs, though API differences might cause slight variations. The example shows GPTel handling queries in different LLMs like Google’s Gemini and ChatGPT, with customizable prefixes for responses. The core command 'gptel-send' is available in any Emacs buffer, and features like saving and restoring chats are built to integrate smoothly into the existing Emacs environment. The paragraph also explains how users can tweak behaviors like autoscrolling or use the gptel-request API for more advanced, non-interactive uses.

Mindmap

Keywords

💡GPTel

GPTel is an Emacs client that integrates Large Language Models (LLMs) like ChatGPT directly into Emacs. It is designed to be flexible and asynchronous, allowing users to access and interact with LLMs across any Emacs buffer. The package supports different LLM providers and can be customized.

💡Emacs

Emacs is a highly customizable text editor that can be expanded with various packages. GPTel integrates with Emacs to provide access to LLMs, offering users a way to utilize AI-generated content while working in any buffer. Emacs’ flexibility complements GPTel’s goal of blending seamlessly with user workflows.

💡LLM (Large Language Model)

Large Language Models (LLMs) are AI models trained on vast amounts of text to generate or understand human language. In this context, LLMs like GPT-3.5 or GPT-4 are used within Emacs via GPTel to assist with tasks such as writing, coding, and answering questions.

💡MELPA

MELPA (Milkypostman’s Emacs Lisp Package Archive) is a popular package repository for Emacs. GPTel is available on MELPA, making it easy for users to install and manage within their Emacs setup. MELPA allows access to a wide range of Emacs packages.

💡API Key

An API key is a unique identifier required to authenticate and authorize access to certain services. In the context of GPTel, users may need an OpenAI API key to interact with models like GPT-3.5 or GPT-4 if they are not using a local LLM.

💡System Message

A system message is a directive that guides the behavior of the LLM. It is used to define how the model should respond. For example, a user might configure a system message to make the model behave like a mathematician or a dictionary.

💡Prefix Argument

A prefix argument is a feature in Emacs that allows commands to accept additional input or change behavior. In GPTel, using a prefix argument with commands like 'gptel-send' allows users to access extra options, such as selecting a specific LLM or adjusting the system message.

💡Buffer

A buffer in Emacs is an area of memory where data is temporarily stored. GPTel operates in any Emacs buffer, meaning it can be used in text, code, or other types of files. Buffers allow users to save, manipulate, and interact with data within Emacs.

💡Asynchronous

Asynchronous refers to processes that occur independently and do not block other operations. GPTel’s asynchronous nature allows users to send requests to LLMs and continue working in Emacs while waiting for responses, enhancing workflow efficiency.

💡Directive

A directive in GPTel is an instruction that shapes how the LLM interprets and responds to user queries. For example, a directive might instruct the model to only return final answers or to behave like a specific professional role (e.g., a mathematician or dictionary).

Highlights

GPTel is an Emacs package that provides a simple, asynchronous LLM client, integrating various models and apps.

Installation is straightforward via MELPA. Users just need to add the MELPA package archive, paste the code into the scratch buffer, evaluate it, and install GPTel.

GPTel supports persistent chats and allows interaction with LLMs from any buffer in Emacs.

A key feature is the ability to bind the `gptel-send` function to any key, allowing for convenient access.

Users can create dedicated chat buffers for specific sessions using commands like `gptel`.

You can configure system messages to adjust LLM behavior, with examples like a 'mathematician' directive for calculations.

GPTel works with various LLM providers, including OpenAI, Google’s Gemini, and local models like Zephyr from Mistral AI.

The package offers asynchronous communication, so users can continue using Emacs while waiting for responses from the LLM.

Responses can be directed to different buffers or locations, giving flexibility in how queries are handled.

The package supports saving chat sessions as regular text files in Org-mode or Markdown format, allowing users to restore conversations.

GPTel tries to integrate seamlessly into Emacs, avoiding disruptions like auto-scrolling or cursor movement by default.

Customization is key: users can tweak GPTel to fit their workflow, including enabling 'magic' behaviors like auto-scrolling.

A general API is available for more complex tasks, allowing integration with non-interactive processes and custom uses.

The system is designed to remain minimal with only two main commands (`gptel-send` and `gptel`) for simplicity and consistency.

GPTel maintains a consistent interface across different LLMs and aims to stay focused on text, which aligns with Emacs' strength.