GithubHelp home page GithubHelp logo

tom-doerr / vim_codex Goto Github PK

View Code? Open in Web Editor NEW
257.0 9.0 28.0 4.95 MB

Supercharge your Vim editor with AI-powered code completion using OpenAI Codex. Boost productivity and save time with intelligent suggestions.

License: MIT License

Python 88.70% Vim Script 11.30%
vim codex ai

vim_codex's Introduction

🤖 Vim Codex

An AI plugin that does the work for you.

Repository's starts Issues License

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

After running :CreateCompletion once, the file ~/.config/openaiapirc is created where you need to enter your OpenAI authentication information. 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 <Leader>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  <C-x> :CreateCompletion<CR>
inoremap  <C-x> <Esc>li<C-g>u<Esc>l:CreateCompletion<CR>

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

Traffic Statistics

vim_codex's People

Contributors

janssen70 avatar oddlama avatar slacksystem avatar tom-doerr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim_codex's Issues

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

Neovim Port

Assuming this doesn't work with Neovim. If it does than close, otherwise any chance of a port?

If not maybe I'll take it on...

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.

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

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?

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?

openaiapirc

Why not use the same openaiapirc file for the auth like it's done on the zsh plugin?

Permission denied

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

returns:

Cloning into 'vim_codex'...
The authenticity of host 'github.com (140.82.121.3)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? y
Please type 'yes', 'no' or the fingerprint: yes
Warning: Permanently added 'github.com,140.82.121.3' (ECDSA) to the list of known hosts.

So I just cloned the repo URL. But for the record, this is what the README says to do.

[ENHANCEMENT] Option for CODEX to ignore certain comments (or code)

Often I put random ideas I have into comments (library ideas, todos, cleanup etc).
While it is nice to use CODEX to also put ideas into the generated code as well I notice the generated code not to be what I want anymore.

It would be great if there is an option to ignore certain comment types (as language agnostic as feasible of course).
E.g. TODO or IDEA lines; maybe a custom one like cignore or something makes sense.
A switch with line comments like # CODEXOFF and # CODEXON might also be helpful - also to "comment out code" you dont want CODEX to see.

Thanks for the great plugin!

How to deal with discontinuation of Codex?

I can see a few options:

  • discontinue in favor of other plugins (no idea if some already exists with chatgpt backend and such)
  • switch underlying model to gpt3-turbo or gpt4 and change prompt structure to improve output
  • switch to gpt3 or similar model and keep the plugin as-is
  • integrate with ChatGPT session token, login challenge if expired, to allow continued free use

What do you think?

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..

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

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?

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

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.

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

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!

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.