From 12aae5adeaa393eecb424e9ffdc458616b2083f1 Mon Sep 17 00:00:00 2001 From: Martin Bielik Date: Sat, 22 Apr 2023 16:00:43 +0200 Subject: custom commands documentation --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index c008081..91808de 100644 --- a/README.md +++ b/README.md @@ -289,6 +289,41 @@ let g:vim_ai_complete = chat_engine_config let g:vim_ai_edit = chat_engine_config ``` +## Custom commands + +To create a custom command, you can call `AIRun`, `AIEditRun` and `AIChatRun` functions. See examples below: + +```vim +" custom command suggesting git commit message, takes no arguments +function! AIPromptCommitMessageFn() + let l:diff = system('git diff --staged') + let l:prompt = "generate a short commit message from the diff below:\n" . l:diff + let l:range = 0 + let l:config = { + \ "engine": "chat", + \ "options": { + \ "model": "gpt-3.5-turbo", + \ "initial_prompt": ">>> system\nyou are a code assistant", + \ "temperature": 1, + \ }, + \} + call vim_ai#AIRun(l:range, l:config, l:prompt) +endfunction +command! AIPromptCommitMessage call AIPromptCommitMessageFn() + +" custom command that provides a code review for selected code block +function! AIPromptCodeReviewFn(range) range + let l:prompt = "programming syntax is " . &filetype . ", review the code below" + let l:config = { + \ "options": { + \ "initial_prompt": ">>> system\nyou are a clean code expert", + \ }, + \} + '<,'>call vim_ai#AIChatRun(a:range, l:config, l:prompt) +endfunction +command! -range AIPromptCodeReview ,call AIPromptCodeReviewFn() +``` + ## Important Disclaimer **Accuracy**: GPT is good at producing text and code that looks correct at first glance, but may be completely wrong. Be sure to thoroughly review, read and test all output generated by this plugin! -- cgit v1.2.3