David-Kunz / gen.nvim

Neovim plugin to generate text using LLMs with customizable prompts
The Unlicense
992 stars 64 forks source link

Prompt wont work in it has quote in it #4

Closed JoseConseco closed 9 months ago

JoseConseco commented 9 months ago

eg. this wont work

David-Kunz commented 9 months ago

Seems to work for me, which OS do you use?

Screenshot 2023-10-02 at 09 10 05
David-Kunz commented 9 months ago

Note: ' characters are already escaped.

This is the resulting command:

ollama run mistral 'Summarize the following text:
Add \'aa_\' prefix to module names
I think they should be escaped for command line with ` ?'
David-Kunz commented 9 months ago

Did you maybe override require('gen').command since you couldn't set the model?

alaaibrahim commented 9 months ago

Ok, did some debugging on this, as this is happening with me too.

The issue is in escaping the ' character, for shell it needs to be '\''

see :h shellescape

the fix is pretty simple, I can open a pr for it

        text = string.gsub(text, "'", "'\\''")
David-Kunz commented 9 months ago

Fixed with https://github.com/David-Kunz/gen.nvim/pull/5, thank you again @alaaibrahim !

sch-28 commented 7 months ago

I still have this issue for some reason 🤔

this is a 'test' - works this is a test - works this is a "test" - doesn't work

DanielEliasib commented 7 months ago

i have this issue too, also happening with double quotes, for example calling :Gen Review_Code on the following input:

"test"

generates the following query:

curl --silent --no-buffer -X POST http://localhost:11434/api/generate -d "{""model"": ""zephyr"", ""stream"": true, ""prompt"": ""Review the following code and make concise suggestions:\n```cpp\n\""test\""\n```""}"

but calling it with the code:

'test'

generates:

curl --silent --no-buffer -X POST http://localhost:11434/api/generate -d "{""model"": ""zephyr"", ""stream"": true, ""prompt"": ""Review the following code and make concise suggestions:\n```cpp\n'test'\n```""}"

my OS is windows

alaaibrahim commented 7 months ago

Unfortunately I don't have a windows machine to test, but just ran the same tests above, and both works

Input: "test" command

curl --silent --no-buffer -X POST http://localhost:11434/api/generate -d '{"model": "codellama", "stream": true, "prompt": "Review the following code and make concise suggestions:\n```cpp\n\"test\"\n```"}' 

Input: 'test' command

curl --silent --no-buffer -X POST http://localhost:11434/api/generate -d '{"model": "codellama", "stream": true, "prompt": "Review the following code and make concise suggestions:\n```cpp\n'\''test'\''\n```"}'

Although cannot say for sure, but it might be that neovim doesn't recognize your shell that you are using, or it's mis-configured somewhere. see help 'shell' help 'shellquote' and help 'shellxquote'

DanielEliasib commented 6 months ago

it seems to be a windows only problem, it has to do with the fact that the commands are being called with cmd so [vim.fn.shellescape()](https://neovim.io/doc/user/builtin.html#shellescape()) has to substitute every double quote with two double quotes, but vim.fn.json_encode() already tries to escape double quotes like \".

so when the command is called the json is all messed up and doesn't have consistent escaping.

i think I've already fixed it on my end, I'll open a PR.