diff --git a/lua/gp/config.lua b/lua/gp/config.lua index a120c29..7f79c4d 100644 --- a/lua/gp/config.lua +++ b/lua/gp/config.lua @@ -36,11 +36,11 @@ local config = { -- agents = { { name = "ChatGPT4" }, ... }, agents = { { - name = "ChatGPT4", + name = "ChatGPT4o", chat = true, command = false, -- string with model name or table with model name and parameters - model = { model = "gpt-4-1106-preview", temperature = 1.1, top_p = 1 }, + model = { model = "gpt-4o", temperature = 1.1, top_p = 1 }, -- system prompt (use this to specify the persona/role of the AI) system_prompt = "You are a general AI assistant.\n\n" .. "The user provided the additional info about how they would like you to respond:\n\n" @@ -53,39 +53,11 @@ local config = { .. "- Take a deep breath; You've got this!\n", }, { - name = "ChatGPT3-5", - chat = true, - command = false, - -- string with model name or table with model name and parameters - model = { model = "gpt-3.5-turbo-1106", temperature = 1.1, top_p = 1 }, - -- system prompt (use this to specify the persona/role of the AI) - system_prompt = "You are a general AI assistant.\n\n" - .. "The user provided the additional info about how they would like you to respond:\n\n" - .. "- If you're unsure don't guess and say you don't know instead.\n" - .. "- Ask question if you need clarification to provide better answer.\n" - .. "- Think deeply and carefully from first principles step by step.\n" - .. "- Zoom out first to see the big picture and then zoom in to details.\n" - .. "- Use Socratic method to improve your thinking and coding skills.\n" - .. "- Don't elide any code from your output if the answer requires coding.\n" - .. "- Take a deep breath; You've got this!\n", - }, - { - name = "CodeGPT4", - chat = false, - command = true, - -- string with model name or table with model name and parameters - model = { model = "gpt-4-1106-preview", temperature = 0.8, top_p = 1 }, - -- system prompt (use this to specify the persona/role of the AI) - system_prompt = "You are an AI working as a code editor.\n\n" - .. "Please AVOID COMMENTARY OUTSIDE OF THE SNIPPET RESPONSE.\n" - .. "START AND END YOUR ANSWER WITH:\n\n```", - }, - { - name = "CodeGPT3-5", + name = "CodeGPT4o", chat = false, command = true, -- string with model name or table with model name and parameters - model = { model = "gpt-3.5-turbo-1106", temperature = 0.8, top_p = 1 }, + model = { model = "gpt-4o", temperature = 0.8, top_p = 1 }, -- system prompt (use this to specify the persona/role of the AI) system_prompt = "You are an AI working as a code editor.\n\n" .. "Please AVOID COMMENTARY OUTSIDE OF THE SNIPPET RESPONSE.\n" @@ -158,12 +130,26 @@ local config = { -- templates template_selection = "I have the following from {{filename}}:" .. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}", - template_rewrite = "I have the following from {{filename}}:" + template_rewrite = "I have the following awesome stuff from {{filename}}:" .. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}" .. "\n\nRespond exclusively with the snippet that should replace the selection above.", + template_rewrite_with_file = "I have the following file {{filename}}:" + .. "\n\n```{{filetype}}\n{{file_content}}\n```" + .. "\n\n I want to update the following code block" + .. "\n\n```{{filetype}}\n{{selection}}\n```" + .. "\n\nInstructions: " + .. "\n- {{command}}" + .. "\n- Respond exclusively with the snippet that should replace the selection above.", template_append = "I have the following from {{filename}}:" .. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}" .. "\n\nRespond exclusively with the snippet that should be appended after the selection above.", + template_append_with_file = "I have the following file {{filename}}:" + .. "\n\n```{{filetype}}\n{{file_content}}\n```" + .. "\n\n I want to append after the following code block" + .. "\n\n```{{filetype}}\n{{selection}}\n```" + .. "\n\nInstructions: " + .. "\n- {{command}}" + .. "\n- Respond exclusively with the snippet that should be appended after the selection above.", template_prepend = "I have the following from {{filename}}:" .. "\n\n```{{filetype}}\n{{selection}}\n```\n\n{{command}}" .. "\n\nRespond exclusively with the snippet that should be prepended before the selection above.", diff --git a/lua/gp/init.lua b/lua/gp/init.lua index aea59a9..a198901 100644 --- a/lua/gp/init.lua +++ b/lua/gp/init.lua @@ -603,6 +603,15 @@ _H.find_git_root = function() return "" end +_H.repo_instruct_file = function() + local git_root = _H.find_git_root() + + if git_root == "" then + return "" + end + + return git_root .. "/.gp.md" +end -- tries to find an .gp.md file in the root of current git repo ---@return string # returns instructions from the .gp.md file M.repo_instructions = function() @@ -628,6 +637,7 @@ M.template_render = function(template, command, selection, filetype, filename) ["{{selection}}"] = selection, ["{{filetype}}"] = filetype, ["{{filename}}"] = filename, + ["{{file_content}}"] = vim.api.nvim_buf_get_lines(0, 0, -1, false) } return _H.template_render(template, key_value_pairs) end @@ -916,6 +926,8 @@ M.Target = { append = 1, -- for appending after the selection, range or the current line prepend = 2, -- for prepending before the selection, range or the current line popup = 3, -- for writing into the popup window + rewriteWithFile = 4, -- for replacing the selection, range or the current line with the full file as context + appendWithFile = 5, -- for appending after the selection, range or the current line with the full file as context -- for writing into a new buffer ---@param filetype nil | string # nil = same as the original buffer @@ -966,11 +978,13 @@ M.prepare_commands = function() -- rewrite needs custom template if target == M.Target.rewrite then template = M.config.template_rewrite - end - if target == M.Target.append then + elseif target == M.Target.rewriteWithFile then + template = M.config.template_rewrite_with_file + elseif target == M.Target.append then template = M.config.template_append - end - if target == M.Target.prepend then + elseif target == M.Target.appendWithFile then + template = M.config.template_append_with_file + elseif target == M.Target.prepend then template = M.config.template_prepend end end @@ -2494,6 +2508,7 @@ end M.Prompt = function(params, target, prompt, model, template, system_template, whisper) -- enew, new, vnew, tabnew should be resolved into table + print(template) if type(target) == "function" then target = target() end @@ -2665,7 +2680,6 @@ M.Prompt = function(params, target, prompt, model, template, system_template, wh local user_prompt = M.template_render(template, command, selection, filetype, filename) table.insert(messages, { role = "user", content = user_prompt }) - -- cancel possible visual mode before calling the model M._H.feedkeys("", "xn") @@ -2680,6 +2694,11 @@ M.Prompt = function(params, target, prompt, model, template, system_template, wh vim.api.nvim_buf_set_lines(buf, start_line - 1, end_line - 1, false, {}) -- prepare handler handler = M.create_handler(buf, win, start_line - 1, true, prefix, cursor) + elseif target == M.Target.rewriteWithFile then + -- delete selection + vim.api.nvim_buf_set_lines(buf, start_line - 1, end_line - 1, false, {}) + -- prepare handler + handler = M.create_handler(buf, win, start_line - 1, true, prefix, cursor) elseif target == M.Target.append then -- move cursor to the end of the selection vim.api.nvim_win_set_cursor(0, { end_line, 0 }) @@ -2687,6 +2706,13 @@ M.Prompt = function(params, target, prompt, model, template, system_template, wh vim.api.nvim_put({ "" }, "l", true, true) -- prepare handler handler = M.create_handler(buf, win, end_line, true, prefix, cursor) + elseif target == M.Target.appendWithFile then + -- move cursor to the end of the selection + vim.api.nvim_win_set_cursor(0, { end_line, 0 }) + -- put newline after selection + vim.api.nvim_put({ "" }, "l", true, true) + -- prepare handler + handler = M.create_handler(buf, win, end_line, true, prefix, cursor) elseif target == M.Target.prepend then -- move cursor to the start of the selection vim.api.nvim_win_set_cursor(0, { start_line, 0 })