Giter Club home page Giter Club logo

codeium.el's Introduction

Codeium


Discord Twitter Follow License built with Codeium

Visual Studio JetBrains Open VSX Google Chrome

codeium.el

Free, ultrafast, extensible AI code completion tool for Emacs

Codeium autocompletes your code with AI in all major IDEs. We launched this implementation of the Codeium plugin for Emacs to bring this modern coding superpower to more developers. Check out our playground if you want to quickly try out Codeium online.

codeium.el provides a completion-at-point-functions backend. It is designed to be use with a front-end, such as company-mode, corfu, or the built-in completion-at-point.

codeium.el is an open source client and (mostly) written by Alan Chen. It uses a proprietary language server binary, currently downloaded (automatically, with confirmation) from here. Use M-x codeium-diagnose to see apis/fields that would be sent to the local language server, and the command used to run the local language server. Customize codeium-api-enabled, codeium-fields-regexps and codeium-command to change them.

Contributions are welcome! Feel free to submit pull requests and issues related to the package.


Emacs Demo - Final


๐Ÿš€ Getting started

  1. Install Emacs

  2. Install a text-completion frontend of your choice. (We recommend company-mode or corfu).

  3. Install Exafunction/codeium.el using your emacs package manager of choice, or manually. See Installation Options below.

  4. Run M-x codeium-install to set up the package.

  5. Add codeium-completion-at-point to your completion-at-point-functions.

  6. Start seeing suggestions!

๐Ÿ› ๏ธ Configuration

You can see all customization options via M-x customize. (better documentation coming soon!)

Here is an example configuration:

;; we recommend using use-package to organize your init.el
(use-package codeium
    ;; if you use straight
    ;; :straight '(:type git :host github :repo "Exafunction/codeium.el")
    ;; otherwise, make sure that the codeium.el file is on load-path

    :init
    ;; use globally
    (add-to-list 'completion-at-point-functions #'codeium-completion-at-point)
    ;; or on a hook
    ;; (add-hook 'python-mode-hook
    ;;     (lambda ()
    ;;         (setq-local completion-at-point-functions '(codeium-completion-at-point))))

    ;; if you want multiple completion backends, use cape (https://github.com/minad/cape):
    ;; (add-hook 'python-mode-hook
    ;;     (lambda ()
    ;;         (setq-local completion-at-point-functions
    ;;             (list (cape-super-capf #'codeium-completion-at-point #'lsp-completion-at-point)))))
    ;; an async company-backend is coming soon!

    ;; codeium-completion-at-point is autoloaded, but you can
    ;; optionally set a timer, which might speed up things as the
    ;; codeium local language server takes ~0.2s to start up
    ;; (add-hook 'emacs-startup-hook
    ;;  (lambda () (run-with-timer 0.1 nil #'codeium-init)))

    ;; :defer t ;; lazy loading, if you want
    :config
    (setq use-dialog-box nil) ;; do not use popup boxes

    ;; if you don't want to use customize to save the api-key
    ;; (setq codeium/metadata/api_key "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")

    ;; get codeium status in the modeline
    (setq codeium-mode-line-enable
        (lambda (api) (not (memq api '(CancelRequest Heartbeat AcceptCompletion)))))
    (add-to-list 'mode-line-format '(:eval (car-safe codeium-mode-line)) t)
    ;; alternatively for a more extensive mode-line
    ;; (add-to-list 'mode-line-format '(-50 "" codeium-mode-line) t)

    ;; use M-x codeium-diagnose to see apis/fields that would be sent to the local language server
    (setq codeium-api-enabled
        (lambda (api)
            (memq api '(GetCompletions Heartbeat CancelRequest GetAuthToken RegisterUser auth-redirect AcceptCompletion))))
    ;; you can also set a config for a single buffer like this:
    ;; (add-hook 'python-mode-hook
    ;;     (lambda ()
    ;;         (setq-local codeium/editor_options/tab_size 4)))

    ;; You can overwrite all the codeium configs!
    ;; for example, we recommend limiting the string sent to codeium for better performance
    (defun my-codeium/document/text ()
        (buffer-substring-no-properties (max (- (point) 3000) (point-min)) (min (+ (point) 1000) (point-max))))
    ;; if you change the text, you should also change the cursor_offset
    ;; warning: this is measured by UTF-8 encoded bytes
    (defun my-codeium/document/cursor_offset ()
        (codeium-utf8-byte-length
            (buffer-substring-no-properties (max (- (point) 3000) (point-min)) (point))))
    (setq codeium/document/text 'my-codeium/document/text)
    (setq codeium/document/cursor_offset 'my-codeium/document/cursor_offset))

Here is an example configuration for company-mode.

(use-package company
    :defer 0.1
    :config
    (global-company-mode t)
    (setq-default
        company-idle-delay 0.05
        company-require-match nil
        company-minimum-prefix-length 0

        ;; get only preview
        company-frontends '(company-preview-frontend)
        ;; also get a drop down
        ;; company-frontends '(company-pseudo-tooltip-frontend company-preview-frontend)
        ))

You can also access codeium.el from elisp; here is a snippet that returns the full response of a GetCompletions request:

(cl-letf*
    (
        ;; making a new codeium-state (thus a new local language server process)
        ;; takes ~0.2 seconds; avoid when possible
        (state (codeium-state-make :name "example"))
        ((codeium-config 'codeium/document/text state) "def fibi(n):")
        ((codeium-config 'codeium/document/cursor_offset state) 12)
        ((codeium-config 'codeium-api-enabled state) (lambda (api) (eq api 'GetCompletions))))
    (unwind-protect
        (progn
            (codeium-init state)
            ;; make async requests using codeium-request
            (cdr (codeium-request-synchronously 'GetCompletions state nil)))
        ;; cleans up temp files, kill process. Scheduled async requests on this state will be dropped.
        (codeium-reset state)))

Note that, among other things, you get probabilities for each token! We would love to see a PR or your own package that uses those!

๐Ÿ’พ Installation Options

โžก๏ธ straight.el

(straight-use-package '(codeium :type git :host github :repo "Exafunction/codeium.el"))

๐Ÿ’€ Doom Emacs

In packages.el add the following:

(package! codeium :recipe (:host github :repo "Exafunction/codeium.el"))

Add the example configuration to your config.el file.

๐Ÿ’ช Manual

Run the following.

git clone --depth 1 https://github.com/Exafunction/codeium.el ~/.emacs.d/codeium.el

Add the following to your ~/.emacs.d/init.el file.

(add-to-list 'load-path "~/.emacs.d/codeium.el")

Do you have a working installation for another Emacs environment (Spacemacs)? Submit a PR so we can share it with others!

codeium.el's People

Contributors

fortenforge avatar alan-chen99 avatar njiang747 avatar khou22 avatar pqn avatar alessandrow avatar aunch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.