FR: option to set the default system prompt
Hi,
I tried modifying the default system prompt to something different than "You are a helpful assistant" by modifying system_windows.lua but it doesn't seem to work and stops LazyNvim from updating your package.
Is there a way to set the default systeme prompt system wide? I would really like something more concise and truthful.
Thanks!
Still nothing?
I got fed up with this so I made a dirty workaround.
Here's a lua function to put in lazy.lua to launch :ChatGPT while replacing the system prompt, adding a shortcut ctrl+alt+s to replace automatically the prompt
function openChatGPT()
-- load and open ChatGPT
vim.cmd("lua require('chatgpt')")
vim.cmd("exe \"normal :ChatGPT\\<CR>\"")
local default_prompt = [[You are my best assistant. You answer my questions using as few words as possible while still remaining friendly and helpful. This is very important to me as I am in a hurry and a bit stressed.
Guidelines:
* If you are certain my question is too vague, ask me first a few clarification questions but answer directly anyway as best as you can.
* Prefer answering using indented markdown format.
* Use code blocks for code but not to wrap your entire answer.
* Answer in the same language as the question.
* Don't acknowledge those rules and answer straight away.
* It is really important that you remain EXTREMELY concise, don't even start your answer by a useless polite sentence.
* If my question is about computer science, know that I'm good at python, running linux, want to understand stuff. I'm not a noob.
* If I'm not asking a question but just writing a concept, write me a summary about it.
Thank you.]]
function setDefaultPrompt()
vim.cmd("exe \"normal \\<Esc>\\<C-S>ggVGx\"")
for line in default_prompt:gmatch("([^\n]*)\n?") do
vim.api.nvim_put({line}, 'l', false, true)
end
vim.cmd("sleep 5ms")
vim.cmd("exe \"normal \\<C-S>\"")
end
-- replace the current system prompt directly
-- setDefaultPrompt()
-- make sure that :q actually quits the terminal instead of just the chat window
vim.api.nvim_set_keymap('n', 'Q', ':normal :qa!<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', ':q', ':normal :qa!<CR>', { noremap = true, silent = true })
-- add shortcut alt+shift+s to populate the prompt, so that it's easy to do after creating a new session
vim.api.nvim_set_keymap('n', '<A-s>', '<Cmd>lua setDefaultPrompt()<CR>', { noremap = true, silent = true })
-- workaround so that resizing the window reloads the UI
vim.api.nvim_create_autocmd("VimResized", {
pattern = "*",
callback = function()
vim.cmd("exe \"normal \\<C-S>\"")
vim.cmd("sleep 5ms")
vim.cmd("exe \"normal \\<C-S>\"")
end,
})
-- create a new session and reuse the current prompt
function newSessionReusePrompt()
vim.cmd("exe \"normal \\<C-S>\"")
vim.cmd("sleep 10ms")
vim.cmd('normal gg0vG$"ay')
vim.cmd("exe \"normal \\<C-S>\"")
vim.cmd("sleep 10ms")
vim.cmd('normal ') -- <- this appears in nvim as ^N but means ctrl+N to type it in the editor do ctrl+v then ctrl+N
vim.cmd("sleep 10ms")
vim.cmd("exe \"normal \\<C-S>\"")
vim.cmd("sleep 10ms")
vim.cmd('normal gg0vG$x"ap')
vim.cmd("sleep 10ms")
vim.cmd("exe \"normal \\<C-S>\"")
end
---- create a new session with the default prompt
function newSessionDefaultPrompt()
vim.cmd("sleep 10ms")
vim.cmd('exe \"normal \\<C-n>\"')
vim.cmd("sleep 10ms")
setDefaultPrompt()
end
-- Choose one or the other
--vim.api.nvim_set_keymap('n', '<A-n>', '<Cmd>lua newSessionReusePrompt()<CR>', { noremap = true, silent = true })
-- OR
vim.api.nvim_set_keymap('n', '<A-n>', '<Cmd>lua newSessionDefaultPrompt()<CR>', { noremap = true, silent = true })
-- optionnal start directly a new session
--newSessionReusePrompt()
-- shift+enter should enter the message
function pressEnter()
vim.cmd("exe \"normal \\<Esc>\"")
vim.cmd("sleep 10ms")
vim.cmd("exe \"normal \\<CR>\"")
print("done")
end
vim.api.nvim_set_keymap('i', '<S-Enter>', '<Cmd>lua pressEnter()<CR>', { noremap = true, silent = true })
end
To try :
nvim /dev/null -c "lua openChatGPT()"
My i3 shortcut:
kitty --title="windowed terminal" -- nvim /dev/null -c "lua openChatGPT()"
Is this feature request still being considered? Is pull request #431 solving this is a way that is acceptable or can something be done to make it acceptable?
Personally I think the default system prompt makes the model way too verbose and I usually replace it with something that tells it to be concise and not over explain examples unless asked to clarify. That's why I would like to be able to edit the default prompt.
Hi, I took a look at my code and noticed that I'm still using my workaround instead of my PR, I don't remember at all if it's because there's something wrong with my PR or if it's just because having my own uncommited code to my local repo is causing issue with lazy vim updates. I encourage you to try it for yourself!
Yeah, that is what I did. I've been running the pull request since yesterday (merged into main) and it works well. My questions were mostly directed at the repo owner to see what their plans with this feature/pull request are. Ideally I don't have to maintain a fork with this feature and instead it gets merged into upstream in some way.