jackMort / ChatGPT.nvim

ChatGPT Neovim Plugin: Effortless Natural Language Generation with OpenAI's ChatGPT API
Apache License 2.0
3.64k stars 312 forks source link

using EditAction API to build an "inline prompt" feature #279

Open bcp-dev-ops opened 12 months ago

bcp-dev-ops commented 12 months ago

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

let foo = 'bar';

const HelloWorldMainComponent = (props) => {
  return <h1>Hello</h1>;
};
// 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

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?

jackMort commented 12 months ago

I'm not sure if I understood it correctly, but there is a CodeCompletion feature showcased here: https://youtu.be/7k0KZsheLP4?si=-htsXx8ErRjG62ER&t=387. Is this what you are looking for?

bcp-dev-ops commented 12 months ago

Ah not quite-- unless the CodeCompletion feature also works with prompts?

I'm looking to write a prompt inline and get the result inline (not necessarily write partial code inline and get the result inline)

ben-wall commented 11 months ago

Could this be related to https://github.com/jackMort/ChatGPT.nvim/issues/285 ?