This is a simple plugin for Vim that allows you to use OpenAI Codex.

Overview

đŸ€– Vim Codex

An AI plugin that does the work for you.

Repository's starts Issues License
Latest commit GitHub repository size

This is a simple plugin for Vim that will allow you to use OpenAI Codex. To use this plugin you need to get access to OpenAI's Codex API.

Installation

The easiest way to install the plugin is to install it as a bundle. For example, using Pathogen:

  1. Get and install pathogen.vim. You can skip this step if you already have it installed.

  2. cd ~/.vim/bundle

  3. git clone [email protected]:tom-doerr/vim_codex.git

Bundle installs are known to work fine also when using Vundle. Other bundle managers are expected to work as well.

After installing the plugin, you need to install the openai package::

pip3 install openai

Finally add your OpenAI access information in ~/.vim/bundle/vim_codex/python/AUTH.py. You can find your authentication information on the website.

Usage

The plugin provides a CreateCompletion command which you can call by default using the mapping co . You can give the CreateCompletion command the number of tokens it should produce as an argument, e.g. CreateCompletion 1000. If you want to just complete the current line, run CreateCompletionLine.

To complete the current text from insert and normal mode using Ctrl+x, you can add the following lines to your .vimrc::

nnoremap  
   
     :CreateCompletion
    
     
inoremap  
      
      
       li
       
        u
        
         l:CreateCompletion
          
         
        
       
      
     
    
   

Updating

Manually

In order to update the plugin, go to its bundle directory and use Git to update it:

  1. cd ~/.vim/bundle/vim_codex

  2. git pull

With Vundle

Use the :BundleUpdate command provided by Vundle, for example invoking Vim like this::

% vim +BundleUpdate
Comments
  • cannot seem to get through the pip3 step

    cannot seem to get through the pip3 step

    Downloading/unpacking openai Downloading openai-0.10.2.tar.gz (156kB): 156kB downloaded Running setup.py (path:/tmp/pip_build_root/openai/setup.py) egg_info for package openai /usr/lib/python3.4/distutils/dist.py:260: UserWarning: Unknown distribution option: 'python_requires' warnings.warn(msg) error in openai setup command: 'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers. Complete output from command python setup.py egg_info: /usr/lib/python3.4/distutils/dist.py:260: UserWarning: Unknown distribution option: 'python_requires'

    warnings.warn(msg)

    error in openai setup command: 'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers.


    Cleaning up... Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/openai Storing debug log for failure in /home/feiliu/.pip/pip.log

    opened by feiliuesmf 8
  • Engine

    Engine "code-davinci-001" not found

    Even if the new update changed the model name from 'davinci-codex' to 'code-davinci-001' calls to CreateCompletion still give the error openai.error.InvalidRequestError: Engine not found. I tried a clean install and the problem persists. I am using python 3.8.10, openai version 0.10.2, and vim 8.2

    opened by Andrea-Augello 6
  • Auth error on completion (fresh install)

    Auth error on completion (fresh install)

    The error I get:
    image

    I have put AUTH.py into /codi.vim/python/ - and the content of files is just api key string. Maybe AUTH.py should have other data included? There is no info about format of AUTH.py file...

    btw. vim_codex was installed with nvim packer into: image

    opened by JoseConseco 3
  • Requires multiple calls of create completion command to finish

    Requires multiple calls of create completion command to finish

    great work on this first of all. I'm trying to recreate the ethereum example in the readme. The code gets generated ok however for some reason it stops after a few lines and i have to call the command again for it to continue generating the code. The example in the readme took me about 4 invocations of the command.

    opened by SijanC147 3
  • Error trying to use autocomplete

    Error trying to use autocomplete

    Hello! Nice work!!

    My config:

    vim

    VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep  2 2021 15:35:57)
    CorreçÔes incluídas: 1-3397
    +python3 
    

    OS

    • Debian GNU/Linux 11
    • 5.10.0-8-amd64 SMP Debian 5.10.46-4 (2021-08-03) x86_64 GNU/Linux

    Problem

    I'm trying to use the plugin, but the error below occurs when I call auto complete:

    Traceback (most recent call last):
      File "/home/myUserHere/.vim/plugged/vim_codex/python/plugin.py", line 27, in complete_input
        response = complete_input_max_length(input_prompt, int(2.5 * MAX_SUPPORTED_INPUT_LENGTH), stop=stop)
    
      File "/home/myUserHere/.vim/plugged/vim_codex/python/plugin.py", line 22, in complete_input_max_le
    ngth
        response = openai.Completion.create(engine='davinci-codex', prompt=input_prompt, best_of=1, temperat
    ure=0.5, max_tokens=64, stream=USE_STREAM_FEATURE, stop=stop)
      File "/usr/local/lib/python3.9/dist-packages/openai/api_resources/completion.py", line 31, in create
        return super().create(*args, **kwargs)
      File "/usr/local/lib/python3.9/dist-packages/openai/api_resources/abstract/engine_api_resource.py", li
    ne 66, in create
        response, _, api_key = requestor.request(
      File "/usr/local/lib/python3.9/dist-packages/openai/api_requestor.py", line 129, in request
        resp = self.interpret_response(rbody, rcode, rheaders, stream=stream)
      File "/usr/local/lib/python3.9/dist-packages/openai/api_requestor.py", line 348, in interpret_response
    
        return self.interpret_response_line(rbody, rcode, rheaders, stream)
      File "/usr/local/lib/python3.9/dist-packages/openai/api_requestor.py", line 367, in interpret_response
    _line
        raise self.handle_error_response(
    openai.error.InvalidRequestError: Engine not found
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/myUserHere/.vim/plugged/vim_codex/python/plugin.py", line 43, in create_completion
        response = complete_input(input_prompt, stop=stop)
      File "/home/myUserHere/.vim/plugged/vim_codex/python/plugin.py", line 29, in complete_input
        response = complete_input_max_length(input_prompt, MAX_SUPPORTED_INPUT_LENGTH, stop=stop)
      File "/home/myUserHere/.vim/plugged/vim_codex/python/plugin.py", line 22, in complete_input_max_le
    ngth
        response = openai.Completion.create(engine='davinci-codex', prompt=input_prompt, best_of=1, temperat
    ure=0.5, max_tokens=64, stream=USE_STREAM_FEATURE, stop=stop)
      File "/usr/local/lib/python3.9/dist-packages/openai/api_resources/completion.py", line 31, in create
        return super().create(*args, **kwargs)
      File "/usr/local/lib/python3.9/dist-packages/openai/api_resources/abstract/engine_api_resource.py", li
    ne 66, in create
        response, _, api_key = requestor.request(
      File "/usr/local/lib/python3.9/dist-packages/openai/api_requestor.py", line 129, in request
        resp = self.interpret_response(rbody, rcode, rheaders, stream=stream)
      File "/usr/local/lib/python3.9/dist-packages/openai/api_requestor.py", line 348, in interpret_response
    
        return self.interpret_response_line(rbody, rcode, rheaders, stream)
      File "/usr/local/lib/python3.9/dist-packages/openai/api_requestor.py", line 367, in interpret_response
    _line
        raise self.handle_error_response(
    openai.error.InvalidRequestError: Engine not found
    
    opened by thiago-scherrer 2
  • Make output configurable to only one line at a time

    Make output configurable to only one line at a time

    Right now, even if I just want vim_codex to create a single line of generation, I get a bunch of extra lines as well.

    Otherwise, great plugin and thanks for making it possible for vim users to try this next generation tech!

    opened by abatilo 2
  • fix: replace sample code with specific name for this plugin

    fix: replace sample code with specific name for this plugin

    This replaces two instances of sample_python_plugin with a specific plugin name. Those are probably leftovers from copying a sample python plugin that should be changed.

    opened by oddlama 1
  • refactor: use github asset storage for gifs to cut down on repository size (closes #16)

    refactor: use github asset storage for gifs to cut down on repository size (closes #16)

    This would solve #16 . I am not sure why there were 4 gifs in the folder while only one was used in the repository readme. If desired I can re-add the rest in some form of "SHOWCASE.md", but for now I only replaced the link to the necessary gif.

    opened by oddlama 1
  • Consider removing the screenshot / gifs from the main repository

    Consider removing the screenshot / gifs from the main repository

    By including the screenshot / gif in your main repository, every user will have a copy of these gigantic files for no reason at all, when all they need is the few kilobytes of vimscript / python. Unfortunately a lot of plugins do this and it unnecessarily bloats the whole vim installation.

    A much easier and better alternative is to use a permalink generated by github for these files and use that link in the repo instead. You can generate such a link by simply dropping the file into a new github issue. Even if you discard the issue afterwards, the genereated link will be a permalink to the uploaded file on github's servers.

    Most plugin managers do shallow clones (--depth 1) by default, so changing this now will still benefit all users, as history isn't kept when updating.

    opened by oddlama 1
  • ModuleNotFoundError: No module named 'openai'

    ModuleNotFoundError: No module named 'openai'

    I'm having a weird error. The package was worked fine until a few days ago. Suddenly, it stopped working, and, whenever I launch VIM, I get the following message:

    v@v-2 ~/.vim/bundle/vim_codex$ vim
    Error detected while processing /Users/v/.vim/bundle/vim_codex/plugin/vim_codex.vim:
    line   21:
    Traceback (most recent call last):
      File "<string>", line 7, in <module>
      File "/Users/v/.vim/bundle/vim_codex/python/plugin.py", line 14, in <module>
        import openai
    ModuleNotFoundError: No module named 'openai'
    

    I believe this error started when I installed LLVM on my system. Running pip3 install openai succeeds, but doesn't solve the problem:

    v@v-2 ~/.vim/bundle/vim_codex$ pip3 install openai
    DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
    Requirement already satisfied: openai in /opt/homebrew/lib/python3.9/site-packages (0.10.4)
    Requirement already satisfied: pandas>=1.2.3 in /opt/homebrew/lib/python3.9/site-packages (from openai) (1.3.3)
    Requirement already satisfied: pandas-stubs>=1.1.0.11 in /opt/homebrew/lib/python3.9/site-packages (from openai) (1.2.0.17)
    Requirement already satisfied: requests>=2.20 in /opt/homebrew/lib/python3.9/site-packages (from openai) (2.26.0)
    Requirement already satisfied: tqdm in /opt/homebrew/lib/python3.9/site-packages (from openai) (4.62.3)
    Requirement already satisfied: openpyxl>=3.0.7 in /opt/homebrew/lib/python3.9/site-packages (from openai) (3.0.9)
    Requirement already satisfied: et-xmlfile in /opt/homebrew/lib/python3.9/site-packages (from openpyxl>=3.0.7->openai) (1.1.0)
    Requirement already satisfied: numpy>=1.17.3 in /opt/homebrew/lib/python3.9/site-packages (from pandas>=1.2.3->openai) (1.21.2)
    Requirement already satisfied: python-dateutil>=2.7.3 in /opt/homebrew/lib/python3.9/site-packages (from pandas>=1.2.3->openai) (2.8.2)
    Requirement already satisfied: pytz>=2017.3 in /opt/homebrew/lib/python3.9/site-packages (from pandas>=1.2.3->openai) (2021.1)
    Requirement already satisfied: certifi>=2017.4.17 in /opt/homebrew/lib/python3.9/site-packages (from requests>=2.20->openai) (2021.5.30)
    Requirement already satisfied: charset-normalizer~=2.0.0 in /opt/homebrew/lib/python3.9/site-packages (from requests>=2.20->openai) (2.0.6)
    Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/homebrew/lib/python3.9/site-packages (from requests>=2.20->openai) (1.26.7)
    Requirement already satisfied: idna<4,>=2.5 in /opt/homebrew/lib/python3.9/site-packages (from requests>=2.20->openai) (3.2)
    Requirement already satisfied: six>=1.5 in /opt/homebrew/lib/python3.9/site-packages (from python-dateutil>=2.7.3->pandas>=1.2.3->openai) (1.16.0)
    DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
    

    Moreover, if I create a normal Python file with import openai, it works fine. So, it seems like the Python used by VIM is somehow different, and can't find the openai library anymore. Why could that be?

    opened by VictorTaelin 1
  • Error while processing function CreateCompletion

    Error while processing function CreateCompletion

    Here is the error message when running CreateCompletion

    Error detected while processing function CreateCompletion: Traceback (most recent call last): File "<string>", line 1, in <module> NameError: name 'plugin' is not defined

    opened by User1391 4
  • Extra commands in example mapping

    Extra commands in example mapping

    Can you explain the reasoning for the additional keystrokes in https://github.com/tom-doerr/vim_codex/blame/main/README.md#L71 ? The li<C-g>u<Esc>l.

    For me the initial l causes the command to fail if I am at the end of a line. Removing the blob entirely seemed to fix things up.

    opened by xloem 0
  • MacOS python confusion

    MacOS python confusion

    Hi,

    thanks for this plugin, it works great on Linux on my RasPi but I am having issues on MacOS..

    On MacOS theres a bunch of different python installs. For one theres the one from MacOS itself, then theres one that comes with XCode and then usually people like me like to use the one installed via brew install python3.

    It seems this plugin is always using the system-installed python in /usr/bin/python while the shell and everything else is using the homebrew-installed /usr/local/bin/python. So when I do pip3 install openai it installs fine but doesn't work in the plugin / in vim.

    When I do /usr/bin/pip3 install openai I am getting issues with building, I suppose thats due to the system's python being incompatible with openai or something..

    opened by normen 3
  • More flexibility

    More flexibility

    I have had some success with some prompts, actually.

    Maybe for a smoother workflow you could pass only text highlighted in visual mode to GPT-3. That way you could keep calling it. Right now it seems like you kind of max out if the program reaches a certain length.

    Or, how do you manage to use it continuously within a single file?

    opened by julkhami 2
  • Code completions not useful

    Code completions not useful

    Thanks for making this. I’ve been testing it out and I find the code completions really haven’t been useful. It hasn’t been able to understand any of my code comments.

    I was just curious if this is the norm? Or could the prompt be improved or something?

    opened by julkhami 1
Owner
Tom Dörr
Tom Dörr
đŸ„A PyTorch implementation of OpenAI's finetuned transformer language model with a script to import the weights pre-trained by OpenAI

PyTorch implementation of OpenAI's Finetuned Transformer Language Model This is a PyTorch implementation of the TensorFlow code provided with OpenAI's

Hugging Face 1.4k Jan 5, 2023
BasicRL: easy and fundamental codes for deep reinforcement learning。It is an improvement on rainbow-is-all-you-need and OpenAI Spinning Up.

BasicRL: easy and fundamental codes for deep reinforcement learning BasicRL is an improvement on rainbow-is-all-you-need and OpenAI Spinning Up. It is

RayYoh 12 Apr 28, 2022
Theano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It can use GPUs and perform efficient symbolic differentiation.

============================================================================================================ `MILA will stop developing Theano <https:

null 9.6k Dec 31, 2022
a delightful machine learning tool that allows you to train, test and use models without writing code

igel A delightful machine learning tool that allows you to train/fit, test and use models without writing code Note I'm also working on a GUI desktop

Nidhal Baccouri 3k Jan 5, 2023
Theano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It can use GPUs and perform efficient symbolic differentiation.

============================================================================================================ `MILA will stop developing Theano <https:

null 9.6k Jan 6, 2023
Theano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It can use GPUs and perform efficient symbolic differentiation.

============================================================================================================ `MILA will stop developing Theano <https:

null 9.3k Feb 12, 2021
Simple command line tool for text to image generation using OpenAI's CLIP and Siren (Implicit neural representation network)

Deep Daze mist over green hills shattered plates on the grass cosmic love and attention a time traveler in the crowd life during the plague meditative

Phil Wang 4.4k Jan 3, 2023
A simple command line tool for text to image generation, using OpenAI's CLIP and a BigGAN.

Ryan Murdock has done it again, combining OpenAI's CLIP and the generator from a BigGAN! This repository wraps up his work so it is easily accessible to anyone who owns a GPU.

Phil Wang 2.3k Jan 9, 2023
Simple implementation of OpenAI CLIP model in PyTorch.

It was in January of 2021 that OpenAI announced two new models: DALL-E and CLIP, both multi-modality models connecting texts and images in some way. In this article we are going to implement CLIP model from scratch in PyTorch. OpenAI has open-sourced some of the code relating to CLIP model but I found it intimidating and it was far from something short and simple. I also came across a good tutorial inspired by CLIP model on Keras code examples and I translated some parts of it into PyTorch to build this tutorial totally with our beloved PyTorch!

Moein Shariatnia 226 Jan 5, 2023
Simple Text-Generator with OpenAI gpt-2 Pytorch Implementation

GPT2-Pytorch with Text-Generator Better Language Models and Their Implications Our model, called GPT-2 (a successor to GPT), was trained simply to pre

Tae-Hwan Jung 775 Jan 8, 2023
Transfer style api - An API to use with Tranfer Style App, where you can use two image and transfer the style

Transfer Style API It's an API to use with Tranfer Style App, where you can use

Brian Alejandro 1 Feb 13, 2022
Implementation / replication of DALL-E, OpenAI's Text to Image Transformer, in Pytorch

DALL-E in Pytorch Implementation / replication of DALL-E, OpenAI's Text to Image Transformer, in Pytorch. It will also contain CLIP for ranking the ge

Phil Wang 5k Jan 4, 2023
A containerized REST API around OpenAI's CLIP model.

OpenAI's CLIP — REST API This is a container wrapping OpenAI's CLIP model in a RESTful interface. Running the container locally First, build the conta

Santiago Valdarrama 48 Nov 6, 2022
Plug-n-Play Reinforcement Learning in Python with OpenAI Gym and JAX

coax is built on top of JAX, but it doesn't have an explicit dependence on the jax python package. The reason is that your version of jaxlib will depend on your CUDA version.

null 128 Dec 27, 2022
A PyTorch Lightning solution to training OpenAI's CLIP from scratch.

train-CLIP ?? A PyTorch Lightning solution to training CLIP from scratch. Goal ⚜ Our aim is to create an easy to use Lightning implementation of OpenA

Cade Gordon 396 Dec 30, 2022
Customizable RecSys Simulator for OpenAI Gym

gym-recsys: Customizable RecSys Simulator for OpenAI Gym Installation | How to use | Examples | Citation This package describes an OpenAI Gym interfac

Xingdong Zuo 14 Dec 8, 2022
A Jupyter notebook to play with NVIDIA's StyleGAN3 and OpenAI's CLIP for a text-based guided image generation.

A Jupyter notebook to play with NVIDIA's StyleGAN3 and OpenAI's CLIP for a text-based guided image generation.

Eugenio Herrera 175 Dec 29, 2022