yuki-yano / ai-review.vim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ai-review.vim

The ai-review.vim plugin harnesses the power of OpenAI's API for conducting code reviews and more.

Dependencies

This plugin relies on denops.vim and ddu.vim.

Instead of ddu.vim, you can use nui.nvim which enables you to use functionality beyond history management with Fuzzy Finder.

Demo

ai-review-demo.mp4

How to Use

First, set your OPENAI_API_KEY environment variable. If you want to use it on a selected range, please set ddu as follows.

call ddu#custom#patch_global({
  \ 'kindOptions': {
  \   'ai-review-request': {
  \     'defaultAction': 'open',
  \   },
  \   'ai-review-log': {
  \     'defaultAction': 'resume',
  \   },
  \ }
  \ })

Then, activate the plugin by executing :AiReview or :'<,'>AiReview.

By default, it is set to use the gpt-3.5-turbo model. If you want to use GPT-4, please call ai_review#config with gpt-4.

call ai_review#config({ 'chat_gpt': { 'model': 'gpt-4' } })

If you want to use with Azure OpenAI Service, you'll need to include an endpoint and an api-version:

call ai_review#config({ 'chat_gpt': { 'model': 'gpt-4', 'azure': { 'use': v:true, 'url': 'https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME', 'api_version': '2023-07-01-preview' } } })

If you want to use nui.nvim instead of ddu, please set as follows:

call ai_review#config({ 'backend': 'nui' })

To get the default value of the setting, please execute ai_review#get_default_config.

Request preset

The request preset is defined as a list of objects of the following type (expressed in TypeScript).

The request and preview can be defined with Vim script's funcref or Lua function, and you can modify it by setting the list of objects to call ai_review#config({ 'chat_gpt': { 'requests': [] } }).

(Ref: https://github.com/yuki-yano/ai-review.vim/blob/main/autoload/ai_review/open_ai/request.vim)

type Request = {
  title: string;
  request: (opts: {
    file_type: string;
    first_line: number;
    last_line: number;
    bufnr: number;
  }) => {
    context: string;
    text: string;
    code: string;
    file_type: string;
  };
  preview: (opts: {
    file_type: string;
    first_line: number;
    last_line: number;
    bufnr: number;
  }) => string;
};

History Management

The commands :AiReviewSave and :AiReviewLoad allow you to easily save and retrieve your chat history.

The log save location is set to call ai_review#config. The default is ~/.cache/vim/ai-review.

call ai_review#config({ 'log_dir': 'path/to/dir' })

Additionally, you can display the history using ddu with the :AiReviewLog command.

Requirements

This plugin requires

Optional

When using nui.nvim instead of ddu.vim:

Acknowledgements

Special thanks to butler.vim contributors.

About

License:Other


Languages

Language:TypeScript 64.9%Language:Vim Script 30.0%Language:Lua 5.1%