Skip to content

shouya/ancilla.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ancilla.el: Your AI Coding Assistant

Enhance your coding experience with code generation, rewriting, and interactive discussions.

Demo

./demo.gif

Feature Highlights

  • Generate code at the cursor with instructions
  • Rewrite the selected region with instructions
  • Discuss selected code
  • AI understands the full context displayed on the screen
    • AI sees the visible part of the current buffer, not just the selected region
    • Inspect the raw conversation in the *ancilla-chat* buffer
  • Review diffs before applying rewrites (can be disabled with the ancilla-show-confirmation customization)
  • Asynchronous requests (can be disabled with the ancilla-async customization)
  • Shortcut functions mimic intellij github copilot menu
    • simplify / fix code
    • generate doc, unit-test
    • explain code
    • review diff (can be used with magit revision / diff buffer)
  • A transient menu for easy access to all commands

The architecture is designed to support any AI backends. Currently, only the chat adaptor is implemented, which utilizes OpenAI’s chat completion (ChatGPT and GPT4 supported).

Installation

(use-package ancilla
  :straight (:host github :repo "shouya/ancilla.el")

  ;; ancilla-generate-or-rewrite calls ancilla-generate or
  ;; ancilla-rewrite depending on whether there is an active
  ;; selection.
  :bind ("C-x C-r" . ancilla-generate-or-rewrite)
  :bind ("C-x C-m" . ancilla-transient-menu) ;; provide shorts like intellij copilot plugins

  :custom
  ;; Defaults to gpt-3.5-turbo, you can opt to use gpt-4o-mini or other.
  ;; (ancilla-adaptor-chat-model "gpt-4o-mini")

  ;; Set your API key
  (ancilla-adaptor-chat-openai-api-key "sk-XXXXXXXXXXXXXXXX"))

Usage

For most of the cases, you only need to invoke ancilla-generate-or-rewrite. It will call ancilla-rewrite when there is an active region, and call ancilla-generate otherwise.

Inspect the *ancilla-chat* buffer for the full conversation sent to OpenAI.

Transient menu (ancilla-transient-menu)

./transient_menu.png

Tips

How to disable diff view/confirmation for rewrite?

Set the ancilla-show-confirmation variable to nil:

(setq ancilla-show-confirmation nil)

How to control the context sent to OpenAI?

Ancilla.el generally sends the visible portion of the buffer to OpenAI. You can inspect the content sent to OpenAI in the *ancilla-chat* buffer.

To control the content sent to OpenAI, you need to manage what is displayed on the screen. Here are some helpful tips:

  • Use recenter-top-bottom (usually bound to C-l) to control the position of the current line on the screen.
  • Use text-scale-adjust (usually bound to C-+ and C--) to resize the text, allowing more or less text to be displayed on the screen.
  • Use narrowing to precisely control what is displayed.

Using ChatGPT by default and GPT-4 occasionally

To use ChatGPT by default and GPT-4 occasionally, you can define a function that overrides the ancilla-adaptor-chat-model. Here’s an example:

(defun my/ancilla-generate-or-rewrite (arg)
  (interactive "P")
  (let ((ancilla-adaptor-chat-model (if arg "gpt-4" "gpt-3.5-turbo")))
    (ancilla-generate-or-rewrite)))

Bind this function to a hotkey, such as C-x C-r. To summon GPT-4, use C-u C-x C-r.

Acknowledgments

About

AI assisted code generation/refactory in Emacs

Resources

License

Stars

Watchers

Forks