ChatGPT.nvim icon indicating copy to clipboard operation
ChatGPT.nvim copied to clipboard

using EditAction API to build an "inline prompt" feature

Open bcp-dev-ops opened this issue 2 years ago • 3 comments

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?

bcp-dev-ops avatar Sep 01 '23 02:09 bcp-dev-ops

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?

jackMort avatar Sep 01 '23 04:09 jackMort

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)

bcp-dev-ops avatar Sep 02 '23 11:09 bcp-dev-ops

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

ben-wall avatar Sep 30 '23 09:09 ben-wall