feat: move prompts to a separat file
This commit is contained in:
@@ -4,6 +4,7 @@ local context = require('chatgpt_nvim.context')
|
||||
local handler = require('chatgpt_nvim.handler')
|
||||
local config = require('chatgpt_nvim.config')
|
||||
local ui = require('chatgpt_nvim.ui')
|
||||
local prompts = require('chatgpt_nvim.prompts')
|
||||
|
||||
local ok_yaml, lyaml = pcall(require, "lyaml")
|
||||
|
||||
@@ -53,21 +54,13 @@ local function is_directory(path)
|
||||
return stat and stat.type == "directory"
|
||||
end
|
||||
|
||||
-- We now simply count characters instead of estimating tokens.
|
||||
local function handle_step_by_step_if_needed(prompt)
|
||||
local conf = config.load()
|
||||
local length = #prompt
|
||||
if not conf.enable_step_by_step or length <= (conf.prompt_char_limit or 8000) then
|
||||
return { prompt }
|
||||
end
|
||||
|
||||
local step_prompt = [[
|
||||
It appears this request might exceed the model's prompt character limit if done all at once.
|
||||
Please break down the tasks into smaller steps and handle them one by one.
|
||||
At each step, we'll provide relevant files or context if needed.
|
||||
Thank you!
|
||||
]]
|
||||
return { step_prompt }
|
||||
return { prompts["step-prompt"] }
|
||||
end
|
||||
|
||||
local function close_existing_buffer_by_name(pattern)
|
||||
@@ -373,22 +366,7 @@ function M.run_chatgpt_command()
|
||||
|
||||
if conf.enable_debug_commands then
|
||||
table.insert(initial_sections, "\n### Debug Commands Info:\n")
|
||||
table.insert(initial_sections, [[
|
||||
If you need debugging commands, include them in your YAML response as follows:
|
||||
|
||||
```yaml
|
||||
commands:
|
||||
- command: "ls"
|
||||
dir: "some/directory"
|
||||
|
||||
- command: "grep"
|
||||
pattern: "searchString"
|
||||
target: "path/to/file/or/directory"
|
||||
```
|
||||
|
||||
The "ls" command uses the system's 'ls' command to list directory contents.
|
||||
When these commands are present and enable_debug_commands is true, I'll execute them and return the results in the clipboard.
|
||||
]])
|
||||
table.insert(initial_sections, prompts["debug-commands-info"])
|
||||
end
|
||||
|
||||
local prompt = table.concat(initial_sections, "\n")
|
||||
@@ -538,12 +516,8 @@ function M.run_chatgpt_paste_command()
|
||||
ui.debug_log("Returning requested files. Character count: " .. length)
|
||||
|
||||
if length > (conf.prompt_char_limit or 8000) and conf.enable_step_by_step then
|
||||
local step_message = [[
|
||||
It appears this requested data is quite large. Please split the task into smaller steps
|
||||
and continue step by step.
|
||||
Which files would you need for the first step?
|
||||
]]
|
||||
copy_to_clipboard(step_message)
|
||||
local large_step = prompts["step-prompt"]
|
||||
copy_to_clipboard(large_step)
|
||||
print("Step-by-step guidance copied to clipboard!")
|
||||
return
|
||||
elseif length > (conf.prompt_char_limit or 8000) then
|
||||
@@ -630,22 +604,7 @@ function M.run_chatgpt_current_buffer_command()
|
||||
|
||||
if conf.enable_debug_commands then
|
||||
table.insert(initial_sections, "\n### Debug Commands Info:\n")
|
||||
table.insert(initial_sections, [[
|
||||
If you need debugging commands, include them in your YAML response as follows:
|
||||
|
||||
```yaml
|
||||
commands:
|
||||
- command: "list"
|
||||
dir: "some/directory"
|
||||
|
||||
- command: "grep"
|
||||
pattern: "searchString"
|
||||
target: "path/to/file/or/directory"
|
||||
```
|
||||
|
||||
The "list" command uses the system's 'ls' command to list directory contents.
|
||||
When these commands are present and enable_debug_commands is true, I'll execute them and return the results in the clipboard.
|
||||
]])
|
||||
table.insert(initial_sections, prompts["debug-commands-info"])
|
||||
end
|
||||
|
||||
local prompt = table.concat(initial_sections, "\n")
|
||||
|
||||
Reference in New Issue
Block a user