From 27ee959366ab8b5aebc2d0db6f508ebdc84519b6 Mon Sep 17 00:00:00 2001 From: Martin Bielik Date: Sat, 22 Apr 2023 17:29:58 +0200 Subject: added AINewChat command --- README.md | 11 ++++++++++- autoload/vim_ai.vim | 21 +++++++++++++++++---- doc/vim-ai.txt | 5 +++++ plugin/vim-ai.vim | 1 + 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5d47090..21fee30 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,8 @@ To use an AI command, type the command followed by an instruction prompt. You ca ``` :AI complete text :AIEdit edit text -:AIChat open/continue chat +:AIChat continue or open new chat +:AINewChat open new chat :AIRedo repeat last AI command :help vim-ai @@ -119,6 +120,14 @@ You are a Clean Code expert, I have the following code, please refactor it in a Supported chat roles are **`>>> system`**, **`>>> user`** and **`<<< assistant`** +### `:AINewChat` + +`:AINewChat {preset shortname}?` - start a new conversation + +This command is used when you need to spawn a new chat in a specific way or in situation when `:AIChat` would normally continue conversation instead. + +As a parameter you put an open chat command preset shortcut - `below`, `tab` or `right`. + ### `:AIRedo` `:AIRedo` - repeat last AI command diff --git a/autoload/vim_ai.vim b/autoload/vim_ai.vim index 5d8ee79..a87517d 100644 --- a/autoload/vim_ai.vim +++ b/autoload/vim_ai.vim @@ -69,6 +69,13 @@ function! s:MakePrompt(is_selection, lines, instruction, config) return join([l:instruction, l:delimiter, l:selection], "") endfunction +function! s:OpenChatWindow(open_conf) + let l:open_cmd = has_key(g:vim_ai_open_chat_presets, a:open_conf) + \ ? g:vim_ai_open_chat_presets[a:open_conf] + \ : a:open_conf + execute l:open_cmd +endfunction + " Complete prompt " - is_selection - parameter " - config - function scoped vim_ai_complete config @@ -137,10 +144,7 @@ function! vim_ai#AIChatRun(is_selection, config, ...) range else " open new chat window let l:open_conf = g:vim_ai_chat['ui']['open_chat_command'] - let l:open_cmd = has_key(g:vim_ai_open_chat_presets, l:open_conf) - \ ? g:vim_ai_open_chat_presets[l:open_conf] - \ : l:open_conf - execute l:open_cmd + call s:OpenChatWindow(l:open_conf) endif endif @@ -159,6 +163,15 @@ function! vim_ai#AIChatRun(is_selection, config, ...) range set nopaste endfunction +" Start a new chat +" a:1 - optional preset shorcut (below, right, tab) +function! vim_ai#AINewChatRun(...) + let l:open_conf = a:0 ? "preset_" . a:1 : g:vim_ai_chat['ui']['open_chat_command'] + call s:OpenChatWindow(l:open_conf) + call vim_ai#AIChatRun(0, {}) +endfunction + +" Repeat last AI command function! vim_ai#AIRedoRun() execute "normal! u" if s:last_command == "complete" diff --git a/doc/vim-ai.txt b/doc/vim-ai.txt index d4ce47e..73ce3b4 100644 --- a/doc/vim-ai.txt +++ b/doc/vim-ai.txt @@ -91,6 +91,11 @@ Options: > Check OpenAI docs for more information: https://platform.openai.com/docs/api-reference/chat + *:AINewChat* + +:AINewChat {preset shortname}? spawn a new conversation with a given open + chat preset - below, tab or right. + *:AIRedo* :AIRedo repeat last AI command in order to re-try diff --git a/plugin/vim-ai.vim b/plugin/vim-ai.vim index 0afe72c..1d03177 100644 --- a/plugin/vim-ai.vim +++ b/plugin/vim-ai.vim @@ -7,4 +7,5 @@ endif command! -range -nargs=? AI ,call vim_ai#AIRun(, {}, ) command! -range -nargs=? AIEdit ,call vim_ai#AIEditRun(, {}, ) command! -range -nargs=? AIChat ,call vim_ai#AIChatRun(, {}, ) +command! -nargs=? AINewChat call vim_ai#AINewChatRun() command! AIRedo call vim_ai#AIRedoRun() -- cgit v1.2.3