add code context for implement
authorRobin Krens <robin@robinkrens.nl>
Thu, 2 Jan 2025 14:59:08 +0000 (15:59 +0100)
committerRobin Krens <robin@robinkrens.nl>
Thu, 2 Jan 2025 14:59:08 +0000 (15:59 +0100)
claudy.vim

index ab39d57..6e1b83b 100644 (file)
@@ -30,7 +30,9 @@ endfunction
 
 function! ClaudyImplement(user_prompt)
     
-       let system_prompt = "reply with an implementation of one function in C should be able to copied right into an editor, no explaining text, start always with ```c and end with ```"
+    let system_prompt = "detect programming language, reply only with new functions, no explaining text, start always with ``` and end with ```"
+
+    let l:code_context = shellescape(join(getbufline(bufnr('%'), 1, '$')))
 
     let json_data = {
         \ 'model': 'claude-3-5-sonnet-20241022',
@@ -39,6 +41,14 @@ function! ClaudyImplement(user_prompt)
         \ 'messages': [
         \   {
         \     'role': 'user',
+        \     'content': l:code_context
+        \   },
+        \   {
+        \     'role': 'assistant',
+        \     'content': "I see your existing code. What would you like to add or modify?"
+        \   },
+        \   {
+        \     'role': 'user',
         \     'content': a:user_prompt
         \   }
         \ ]