jackMort / jackMort/ChatGPT.nvim
using EditAction API to build an "inline prompt" feature
- Dominant language
- Lua
- Stars
- 4k
- Forks
- 317
- PR merge metrics
- No merged PRs in 30d
Description
Looking for some help building out a feature. Basically looking for a way to be able to write prompts "inline" and then iteratively execute the whole file, using the current line as a prompt. (I think this could be a workflow gamechanger.)
For example, if I wanted to write a prompt on line 6 (to insert the result after line 6), I could write a comment like: "// Write a function that prints "Hello, World!" to the console"
_example.js_
```javascript
let foo = 'bar';
const HelloWorldMainComponent = (props) => {
return
Hello
;};
// Write a function that prints "Hello, World!" to the console
// (And then ChatGPT response would be injected here)
export default HelloWorldMainComponent;
```
Here is my lua function, but getting stuck trying to figure out how to use the EditAction
```lua
local function run_with_context()
local current_line = vim.api.nvim_get_current_line()
local current_line_number = vim.api.nvim_win_get_cursor(0)[1]
local extended_prompt = current_line
.. ". Insert at line "
.. current_line_number
.. "."
local EditAction = require("chatgpt.flows.actions.edits")
local opts = {
params = {
model = "gpt-3.5-turbo",
stop = {
"```",
},
},
template = extended_prompt,
variables = {},
strategy = "edit",
}
local action = EditAction.new(opts)
action:run()
end
```
Spinning my wheels a bit here-- getting an API error on the result:
// API ERROR: 'instruction' is a required property
Been playing around for an hour but have run out of time, will continue to experiment over the upcoming days. Any ideas on how to help?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading chatgpt.flows.actions.edits and the EditAction.new/run entry points, then compare the supplied opts with the API error that instruction is required. Determine how an inline comment should become an edit instruction and how the response should be inserted at the current line. Done means the workflow can execute the current-line prompt and insert its result without the reported API error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, neovim
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100