create custom prompt for AI chat
This commit is contained in:
parent
6e2a88508c
commit
75cfaf54a4
1 changed files with 99 additions and 50 deletions
|
|
@ -24,52 +24,76 @@ return {
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
opts = function()
|
opts =
|
||||||
local user = vim.env.USER or "User"
|
---@type CopilotChat.config
|
||||||
user = user:sub(1, 1):upper() .. user:sub(2)
|
{
|
||||||
|
---@type table<string, CopilotChat.config.prompt>
|
||||||
|
prompts = {
|
||||||
|
HowDoI = {
|
||||||
|
system_prompt = [[
|
||||||
|
> /COPILOT_EXPLAIN
|
||||||
|
|
||||||
return {
|
You are gonna be asked for guidance about how to solve a problem or archeive a goal. For that your answers need to follow these rules:
|
||||||
prompts = {
|
|
||||||
Explain = {
|
|
||||||
prompt = '> /COPILOT_EXPLAIN\n\nWrite an explanation for the selected code as paragraphs of text.',
|
|
||||||
},
|
|
||||||
Review = {
|
|
||||||
prompt = '> /COPILOT_REVIEW\n\nReview the selected code.',
|
|
||||||
-- see config.lua for implementation
|
|
||||||
},
|
|
||||||
Fix = {
|
|
||||||
prompt =
|
|
||||||
'> /COPILOT_GENERATE\n\nThere is a problem in this code. Rewrite the code to show it with the bug fixed.',
|
|
||||||
},
|
|
||||||
Optimize = {
|
|
||||||
prompt = '> /COPILOT_GENERATE\n\nOptimize the selected code to improve performance and readability.',
|
|
||||||
},
|
|
||||||
Docs = {
|
|
||||||
prompt = '> /COPILOT_GENERATE\n\nPlease add documentation comments to the selected code.',
|
|
||||||
},
|
|
||||||
Tests = {
|
|
||||||
prompt = '> /COPILOT_GENERATE\n\nPlease generate tests for my code.',
|
|
||||||
},
|
|
||||||
Commit = {
|
|
||||||
prompt =
|
|
||||||
'> #git:staged\n\nWrite commit message for the change with commitizen convention. Make sure the title has maximum 50 characters and message is wrapped at 72 characters. Wrap the whole message in code block with language gitcommit.',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
question_header = " " .. user .. " ",
|
|
||||||
answer_header = " Copilot ",
|
|
||||||
window = {
|
|
||||||
layout = 'float', -- 'vertical', 'horizontal', 'float', 'replace'
|
|
||||||
width = 0.8, -- fractional width of parent, or absolute width in columns when > 1
|
|
||||||
height = 0.8, -- fractional height of parent, or absolute height in rows when > 1
|
|
||||||
-- Options below only apply to floating windows
|
|
||||||
relative = 'editor', -- 'editor', 'win', 'cursor', 'mouse'
|
|
||||||
border = 'rounded', -- 'none', single', 'double', 'rounded', 'solid', 'shadow'
|
|
||||||
title = ' ', -- title of chat window
|
|
||||||
zindex = 1, -- determines if window is on top or below other floating windows
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
|
|
||||||
|
1. Provide brief, consice and unambiguos responses.
|
||||||
|
2. You need to response with an step by step list of actions needed to complete the task.
|
||||||
|
3. **You never have to give an explicit answer**, instead provide a high level overview of how to complete the task.
|
||||||
|
4. Unless explicity asked by the user, **you never have to provide code snippets** in your responses. Only provide code snippets when the user says so in each question.
|
||||||
|
5. If the user ask for a code snippet, **prefer to respond in pseudo code**, unless the user explicity asked for a concrete language.
|
||||||
|
6. You need to have into consideration good and clean code practices, code performance and other standards, comunicate in your response this considerations and common pitfalls to avoid.
|
||||||
|
7. If possible, include how the user can test the task is completed successfully with the title "## Testing".
|
||||||
|
8. Use markdawn syntax highlighting when possible.
|
||||||
|
9. You are allowed to reference the following elements but without giving examples of usage (unless the user ask for it):
|
||||||
|
- Elements from the language syntaxis.
|
||||||
|
- Standard library of the lenguage.
|
||||||
|
- External libraries and/or frameworks.
|
||||||
|
- The idiomatic way of acomplish something in the language.
|
||||||
|
- Data structures and algorithms that could help complete the task.
|
||||||
|
|
||||||
|
If you have multiple aproaches of how the task can be solved, insert the title "## Options", then generate separate list of task, each in the form of "### Option A", "### Option B", etc so he/her can have it into consideration.
|
||||||
|
The numbering of each list needs to be independen of each other, also provide only 1 list per aproach.
|
||||||
|
|
||||||
|
The user can ask follow up question, which needs to follow the same rules.
|
||||||
|
]]
|
||||||
|
},
|
||||||
|
Explain = {
|
||||||
|
prompt = '> /COPILOT_EXPLAIN\n\nWrite an explanation for the selected code as paragraphs of text.',
|
||||||
|
},
|
||||||
|
Review = {
|
||||||
|
prompt = '> /COPILOT_REVIEW\n\nReview the selected code.',
|
||||||
|
-- see config.lua for implementation
|
||||||
|
},
|
||||||
|
Fix = {
|
||||||
|
prompt =
|
||||||
|
'> /COPILOT_GENERATE\n\nThere is a problem in this code. Rewrite the code to show it with the bug fixed.',
|
||||||
|
},
|
||||||
|
Optimize = {
|
||||||
|
prompt = '> /COPILOT_GENERATE\n\nOptimize the selected code to improve performance and readability.',
|
||||||
|
},
|
||||||
|
Docs = {
|
||||||
|
prompt = '> /COPILOT_GENERATE\n\nPlease add documentation comments to the selected code.',
|
||||||
|
},
|
||||||
|
Tests = {
|
||||||
|
prompt = '> /COPILOT_GENERATE\n\nPlease generate tests for my code.',
|
||||||
|
},
|
||||||
|
Commit = {
|
||||||
|
prompt =
|
||||||
|
'> #git:staged\n\nWrite commit message for the change with commitizen convention. Make sure the title has maximum 50 characters and message is wrapped at 72 characters. Wrap the whole message in code block with language gitcommit.',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
question_header = " " .. vim.env.USER or "User" .. " ",
|
||||||
|
answer_header = " Copilot ",
|
||||||
|
window = {
|
||||||
|
layout = 'float', -- 'vertical', 'horizontal', 'float', 'replace'
|
||||||
|
width = 0.8, -- fractional width of parent, or absolute width in columns when > 1
|
||||||
|
height = 0.8, -- fractional height of parent, or absolute height in rows when > 1
|
||||||
|
-- Options below only apply to floating windows
|
||||||
|
relative = 'editor', -- 'editor', 'win', 'cursor', 'mouse'
|
||||||
|
border = 'rounded', -- 'none', single', 'double', 'rounded', 'solid', 'shadow'
|
||||||
|
title = ' ', -- title of chat window
|
||||||
|
zindex = 1, -- determines if window is on top or below other floating windows
|
||||||
|
},
|
||||||
|
},
|
||||||
keys = {
|
keys = {
|
||||||
{
|
{
|
||||||
"<leader>at",
|
"<leader>at",
|
||||||
|
|
@ -82,14 +106,31 @@ return {
|
||||||
{
|
{
|
||||||
"<leader>aa",
|
"<leader>aa",
|
||||||
function()
|
function()
|
||||||
local input = vim.fn.input("Quick Chat: ")
|
local input = vim.fn.input(" Quick Chat: ")
|
||||||
if input ~= "" then
|
if input == "" then
|
||||||
require("CopilotChat").ask(input)
|
return
|
||||||
end
|
end
|
||||||
|
require("CopilotChat").ask(input)
|
||||||
end,
|
end,
|
||||||
desc = "Quick chat",
|
desc = "Quick chat",
|
||||||
mode = { "n", "v" },
|
mode = { "n", "v" },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"<leader>ah",
|
||||||
|
function()
|
||||||
|
local input = vim.fn.input(" How do I...")
|
||||||
|
if input == "" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local chat = require("CopilotChat")
|
||||||
|
|
||||||
|
local promptConfig = chat.prompts()["HowDoI"]
|
||||||
|
chat.ask(input, promptConfig)
|
||||||
|
end,
|
||||||
|
desc = "How do I...",
|
||||||
|
mode = { "n", "v" },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"<leader>aA",
|
"<leader>aA",
|
||||||
function()
|
function()
|
||||||
|
|
@ -97,9 +138,10 @@ return {
|
||||||
local actions = require("CopilotChat.actions")
|
local actions = require("CopilotChat.actions")
|
||||||
|
|
||||||
-- Pick prompt actions
|
-- Pick prompt actions
|
||||||
actions.pick(actions.prompt_actions({
|
actions.pick(actions.prompt_actions({}), {
|
||||||
selection = require("CopilotChat.select").visual,
|
prompt = " Prompts:",
|
||||||
}))
|
}
|
||||||
|
)
|
||||||
end,
|
end,
|
||||||
desc = "Select action",
|
desc = "Select action",
|
||||||
mode = { "n", "v" },
|
mode = { "n", "v" },
|
||||||
|
|
@ -112,5 +154,12 @@ return {
|
||||||
desc = "Clear chat",
|
desc = "Clear chat",
|
||||||
mode = { "n", "v" },
|
mode = { "n", "v" },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"<leader>al",
|
||||||
|
function()
|
||||||
|
return require("CopilotChat").log_level("debug")
|
||||||
|
end,
|
||||||
|
desc = "Set debug level",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue