From: Robin Krens Date: Thu, 2 Jan 2025 16:30:02 +0000 (+0100) Subject: add initial ClaudyBrainstorm X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=f0ae6c63beca48e17943bb15a8d64f25256edb0e;p=vim-claudy add initial ClaudyBrainstorm --- diff --git a/claudy.vim b/claudy.vim index 6e1b83b..6a87498 100644 --- a/claudy.vim +++ b/claudy.vim @@ -64,7 +64,7 @@ function! ClaudyRefactor(user_prompt) let l:end_line = line("'>") let l:selected_text = a:user_prompt . shellescape(join(getline(l:start_line, l:end_line))) - let l:system_prompt = "detect programming language, reply with one function (do not implement other functions) code should be able to copied right into an editor, no explaining text, start always with ```c and end with ```" + let l:system_prompt = "detect programming language, reply with one function (do not implement other functions) code should be able to copied right into an editor, no explaining text, start always with ``` and end with ```" " Prepare the JSON payload let l:json_data = { @@ -86,6 +86,77 @@ function! ClaudyRefactor(user_prompt) put =l:refactored_code endfunction +function! ClaudyBrainstorm() + " Create new window + botright new + setlocal buftype=nofile + setlocal bufhidden=hide + setlocal noswapfile + setlocal nowrap + let b:chat_history = [] + + " Set buffer name + file Claude-Chat + + " Initialize with greeting + call append(0, "=== Claude Chat ===") + call append(1, "Type your message and press Enter to chat. Press q to quit.") + call append(2, "") + + " Set up mappings for this buffer + nnoremap :call SendMessage() + nnoremap q :q + + " Start in insert mode at the bottom + normal! G + startinsert! +endfunction + +function! s:SendMessage() + " Get the last line as user message + let l:user_msg = getline('$') + + " Skip if empty + if empty(l:user_msg) + return + endif + + " Prepare JSON data + let l:json_data = { + \ 'model': 'claude-3-5-sonnet-20241022', + \ 'max_tokens': 1024, + \ 'messages': [ + \ { + \ 'role': 'user', + \ 'content': l:user_msg + \ } + \ ] + \ } + + " Add chat history if exists + if exists('b:chat_history') && len(b:chat_history) > 0 + let l:json_data.messages = b:chat_history + l:json_data.messages + endif + + " Get response + let l:response = ClaudyRequest(l:json_data) + + " Update chat history + call add(b:chat_history, {'role': 'user', 'content': l:user_msg}) + call add(b:chat_history, {'role': 'assistant', 'content': l:response}) + + " Add visual separator + call append('$', repeat('-', 80)) + " Add response + put =l:response + " call append('$', 'Claude: ' . l:response) + call append('$', '') + + " Move cursor to new line + normal! G + startinsert! +endfunction + vnoremap c :call ClaudyRefactor() vnoremap i :call ClaudyImplement() vnoremap b :call ClaudyTest()