Robitx / gp.nvim

Gp.nvim (GPT prompt) Neovim AI plugin: ChatGPT sessions & Instructable text/code operations & Speech to text [OpenAI, Ollama, Anthropic, ..]
MIT License
749 stars 65 forks source link

Send multiple files into the chat #206

Open UreshiiPanda opened 1 week ago

UreshiiPanda commented 1 week ago

Looks like an awesome plugin, but after reading through the ReadMe it wasn't apparent to me how I can send whole files into the chat for the chat bot to reference when answering questions. Is this not a feature of gp.nvim?

qaptoR commented 6 days ago

Take a look at this branch of my fork. https://github.com/qaptoR-nvim/gp.nvim/tree/insert_context

I adapted the work done in this PR: https://github.com/Robitx/gp.nvim/pull/174

basically, I felt the PR went too far and overcomplicated itself with by trying to be able to reference a specific function in a code file. A truly amazing feat they accomplished it, but definitely not something I personally need.

I took the basic template of their @code:relative/path/tofile which adds triple backtick fences around the imported code, as well references the file name. Then I added @text:... which does the same thing, but doesn't reference the filename or use backtick fences around the included context.

I also added @codedir and @textdir which basically includes all files in a directory path (all paths are relative to the cwd) using the same strategies as the non 'dir' related commands.

lastly I added an @import:... command, which is a recursive command, the searches the file at the given path for other commands and stiches them together into a single import. So you can create different binders of files to include together for different contexts.

The other thing I did different was make it so that the the imported text always appears IN the message where the command is present AND at the top of the message. so it's always necessary to say 'in the context above', rather than 'in the following context`, although I'm not sure if there are any studies that show which strategy leads to better results, I personally think it generally makes no difference to the LLM where the context is, so long as it is included so it can be referenced. And the current strategy leads to simpler code. In general this means that the conversation remains consistent for each successive query, and past contexts will always be available in future queries. I do recommend using the cheaper models like haiku or gpt4o-mini, or gemini flash because the added contexts really expensive otherwise.

hope this helps! (I will try to keep my fork continually updated with the main repo, but since it's the main branch I use, I may update it with other features occasionally as well, since I'm lazy and don't feel like keeping the different features on separate branches and then merging them into a single production branch)

edit: oh and I forgot to mention that I made it so that each @<command>:path/to/file/ has to end with a / because having a delimiter meant that I could have file-names with spaces. I'm not sure if every valid file-name on windows or linux is supported, so ymmv, but in general this is-a_filename.org is valid for the commands, and that includes intermediary directory path names.

qaptoR commented 4 days ago

I should also note that this pr is adding 'macro' support, which looks like is going to be an extendable feature where we can define new macros easily, and one of the first macros being developed for the system is @context_file or similar which will act like the @code command I mentioned above, and it should therefore be reasonable the rest of my commands will or could be implemented using the same macro system

https://github.com/Robitx/gp.nvim/pull/198

Odie commented 4 days ago

The other thing I did different was make it so that the the imported text always appears IN the message where the command is present...

In general this means that the conversation remains consistent for each successive query, and past contexts will always be available in future queries.

At least with programming, the file being discussed with the LLM and/or other related files might immediately have some changes applied to it as the result of the discussion. This means, if you're not saving and storing the referenced file away in a separate location (like the 'artifacts' directory discussed some time ago), attempts to recreate the exact state of the previous messages using the current state of the files will likely fail. The files could have changed drastically since the time the old message was issued, the file might have been moved, or even deleted altogether.