Giter Club home page Giter Club logo

vim-gpt-commit's Introduction

Preface

Generate proper git commit message using ChatGPT (or Ollama) in Vim:

This plugin provides a :GptCommit command to generate commit message and append in the current buffer.

Usually, it can be used when editing the COMMIT_EDITMSG file, or in a fugitive commit window.

Quick start

For vim-plug:

Plug 'skywind3000/vim-gpt-commit'

let g:gpt_commit_key = 'Your openai apikey'
" uncomment this line below to enable proxy
" let g:gpt_commit_proxy = 'socks5://127.0.0.1:1080'

" uncomment the following lines if you want to use Ollama:
" let g:gpt_commit_engine = 'ollama'
" let g:gpt_commit_ollama_url = 'http://127.0.0.1:11434/api/chat'
" let g:gpt_commit_ollama_model = 'llama2'

For lazy:

{
    'skywind3000/vim-gpt-commit',
    config = function ()
        -- if you don't want to set your api key directly, add to your .zshrc:
        -- export OPENAI_API_KEY='sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
        vim.g.gpt_commit_key = os.getenv("OPENAI_API_KEY")
        -- uncomment this line below to enable proxy
        -- vim.g.gpt_commit_proxy = 'socks5://127.0.0.1:1080'

        -- uncomment the following lines if you want to use Ollama:
        -- vim.g.gpt_commit_engine = 'ollama'
        -- vim.g.gpt_commit_ollama_url = 'http://127.0.0.1:11434/api/chat'
        -- vim.g.gpt_commit_ollama_model = 'llama2'
    end,
},

Requirements:

  • Python: A Python 3 executable binary needs to be located in your $PATH, but vim's +python3 feature is not required.

Command

This plugin provides only one command:

:GptCommit[!] [repo_path]

It will generate git commit message and append to the current cursor position. If the repo_path is omitted, the directory name of the current buffer will be used.

If the bang (!) is included, :GptCommit will not append any text to the current buffer, instead, it will only store the messages in the unnamed register (*). You can use them any time manually by "*p or display the content by:

:echo @*

You will see the result in the command line.

Options

Name Required Default Description
g:gpt_commit_key Yes '' Your openai apikey
g:gpt_commit_proxy - '' proxy
g:gpt_commit_concise - 0 set to 1 to generate less verbose message
g:gpt_commit_lang - '' output language
g:gpt_commit_model - 'gpt-3.5-turbo' ChatGPT model
g:gpt_commit_staged - 1 set to 1 to use staged diff
g:gpt_commit_max_line - 160 max diff lines to reference
g:gpt_commit_url - '' alternative request URL, see #1
g:gpt_commit_python - '' specify the Python executable file explicitly
g:gpt_commit_engine - 'chatgpt' change to 'ollama' to use Ollama
g:gpt_commit_ollama_model Yes '' ollama model
g:gpt_commit_ollama_url - '' explicitly setting ollama URL

Note #1: the default URL is "https://api.openai.com", can be changed by setting g:gpt_commit_url.

Script

For command line usage, you can execute gptcommit.py in the bin directory:

usage: python3 gptcommit.py <options> repo_path
available options:
  --key=xxx       required, your openai apikey
  --staged        optional, use staged diff if present
  --proxy=xxx     optional, proxy support
  --maxline=num   optional, max diff lines to feed ChatGPT, default ot 160
  --model=xxx     optional, can be gpt-3.5-turbo (default) or something
  --lang=xxx      optional, output language
  --concise       optional, generate concise message if present
  --utf8          optional, output utf-8 encoded text if present
  --url=xxx       optional, alternative openai request url

It can be integrated into other editors.

Credit

If you find this plugin amusing, you might also be interested in my other vim plugins, such as:

vim-gpt-commit's People

Contributors

eduardoarandah avatar skywind3000 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

Watchers

 avatar  avatar  avatar

vim-gpt-commit's Issues

Error HTTP Error 429: Too Many Requests

Got this error: urllib.error.HTTPError: HTTP Error 429: Too Many Requests

Idk if there's something else I can provide to debug

Traceback (most recent call last):
  File "/Users/lalo/.local/share/nvim/lazy/vim-gpt-commit/bin/gptcommit.py", line 441, in <module>
    main()
  File "/Users/lalo/.local/share/nvim/lazy/vim-gpt-commit/bin/gptcommit.py", line 387, in main
    obj = chatgpt_request(msgs, OPTIONS['key'], opts)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/lalo/.local/share/nvim/lazy/vim-gpt-commit/bin/gptcommit.py", line 38, in chatgpt_request
    response = opener.open(req, timeout = timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 525, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 634, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 563, in error
    return self._call_chain(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 429: Too Many Requests

no GptCommit command with neovim 0.9.5 and lazy

any clue?

====

$ nvim --version
NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1703358377

  system vimrc file: "$VIM/sysinit.vim"
 fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.5/share/nvim"

Run :checkhealth for more info

: checkhealth output:

==============================================================================
coc: health#coc#check

- OK nvim version satisfied
- OK Environment check passed
- WARNING pyx command not work, some extensions may fail to work, checkout ":help |pythonx|"
- WARNING Install pynvim by command: `pip install pynvim --upgrade`
- OK Javascript bundle build/index.js found
- OK Service started

==============================================================================
crates: require("crates.health").check()

Checking for required plugins ~
- OK plenary.nvim installed

Checking for external dependencies ~
- OK curl installed

==============================================================================
floaterm: require("floaterm.health").check()

- ERROR Failed to run healthcheck for "floaterm" plugin. Exception:
 function health#check, line 25
 Vim(eval):E5108: Error executing lua ...cal/share/nvim/lazy/vim-floaterm/lua/floaterm/health.lua:25: attempt to index field 'uv' (a nil value)
 stack traceback:
 ...cal/share/nvim/lazy/vim-floaterm/lua/floaterm/health.lua:25: in function 'check_common'
 ...cal/share/nvim/lazy/vim-floaterm/lua/floaterm/health.lua:55: in function 'check'
 [string "luaeval()"]:1: in main chunk

==============================================================================
lazy: require("lazy.health").check()

lazy.nvim ~
- OK Git installed
- OK no existing packages found by other package managers
- OK packer_compiled.lua not found
- WARNING {warden.nvim}: unknown key <line_highlight>
- WARNING {rainbow}: unknown key <enable>

==============================================================================
nvim: require("nvim.health").check()

Configuration ~
- OK no issues found

Runtime ~
- OK $VIMRUNTIME: /opt/homebrew/Cellar/neovim/0.9.5/share/nvim/runtime

Performance ~
- OK Build type: Release

Remote Plugins ~
- OK Up to date

terminal ~
- key_backspace (kbs) terminfo entry: `key_backspace=^H`
- key_dc (kdch1) terminfo entry: `key_dc=\E[3~`
- $TERM_PROGRAM="WezTerm"
- $COLORTERM="truecolor"

==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- OK `tree-sitter` found 0.20.9 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v18.18.2 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
 Version: Apple clang version 15.0.0 (clang-1500.1.0.2.5)
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
 machine = "arm64",
 release = "23.2.0",
 sysname = "Darwin",
 version = "Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000"
} ~

Parser/Features         H L F I J
 - c                   ✓ ✓ ✓ ✓ ✓
 - lua                 ✓ ✓ ✓ ✓ ✓
 - query               ✓ ✓ ✓ ✓ ✓
 - vim                 ✓ ✓ ✓ . ✓
 - vimdoc              x . . . ✓

 Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
        +) multiple parsers found, only one will be used
        x) errors found in the query, try to run :TSUpdate {lang} ~

The following errors have been detected: ~
- ERROR vimdoc(highlights): ...im/0.9.5/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid node type at position 746 for language vimdoc
 vimdoc(highlights) is concatenated from the following files:
 | [ERROR]:"/Users/sangshuduo/.local/share/nvim/lazy/nvim-treesitter/queries/vimdoc/highlights.scm", failed to load: ...im/0.9.5/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid node type at position 746 for language vimdoc

==============================================================================
provider: health#provider#check

Clipboard (optional) ~
- OK Clipboard tool found: pbcopy

Python 3 provider (optional) ~
- Disabled (g:loaded_python3_provider=0).

Python virtualenv ~
- OK no $VIRTUAL_ENV

Ruby provider (optional) ~
- Disabled (g:loaded_ruby_provider=0).

Node.js provider (optional) ~
- Disabled (g:loaded_node_provider=0).

Perl provider (optional) ~
- Disabled (g:loaded_perl_provider=0).

==============================================================================
vim.lsp: require("vim.lsp.health").check()

- LSP log level : WARN
- Log path: /Users/sangshuduo/.local/state/nvim/lsp.log
- Log size: 65 KB

vim.lsp: Active Clients ~
- copilot (id=1, root_dir=nil)

==============================================================================
vim.treesitter: require("vim.treesitter.health").check()

- Nvim runtime ABI version: 14
- OK Parser: lua        ABI: 14, path: /Users/sangshuduo/.local/share/nvim/lazy/nvim-treesitter/parser/lua.so
- OK Parser: c          ABI: 14, path: /opt/homebrew/Cellar/neovim/0.9.5/lib/nvim/parser/c.so
- OK Parser: lua        ABI: 14, path: /opt/homebrew/Cellar/neovim/0.9.5/lib/nvim/parser/lua.so
- OK Parser: query      ABI: 14, path: /opt/homebrew/Cellar/neovim/0.9.5/lib/nvim/parser/query.so
- OK Parser: vim        ABI: 14, path: /opt/homebrew/Cellar/neovim/0.9.5/lib/nvim/parser/vim.so
- OK Parser: vimdoc     ABI: 14, path: /opt/homebrew/Cellar/neovim/0.9.5/lib/nvim/parser/vimdoc.so

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.