David-Kunz / gen.nvim

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

Error: Unexpected EOF #81

Open Kahitar opened 3 months ago

Kahitar commented 3 months ago

Hi,

this plugin is not working for me and I don't quite understand why (maybe because I'm on windows?).

I don't get a response from ollama when using this plugin, so the response modal is always empty. Enabling debug output, I get these logs:

curl --silent --no-buffer -X POST http://localhost:11434/api/chat -d "{""messages"": [{""role"": ""user"", ""content"": ""Regarding the following text, hi:\n""}], ""model"": ""mistral"", ""stream"": true}"
Response data:
{ '{"error":"unexpected EOF"}' }
Response data:
{ "" }

When I try to run the same curl command in git-bash, the output is this:

$ curl --silent --no-buffer -X POST http://localhost:11434/api/chat -d "{""messages"": [{""role"": ""user"", ""content"": ""Regarding the following text, hi:\n""}], ""model"": ""mistral"", ""stream"": true}"
{"error":"invalid character 'm' looking for beginning of object key string"}

I don't quite understand why the json body contains doubled quotes. When I remove them and surround the body with single quotes, than it works:

curl --silent --no-buffer -X POST http://localhost:11434/api/chat -d '{"messages": [{"role": "user", "content": "Regarding the following text, hi:\n"}], "model": "mis
tral", "stream": true}'
{"model":"mistral","created_at":"2024-03-17T16:18:22.8339767Z","message":{"role":"assistant","content":" Hello"},"done":false}
...

Don't know if this is really the cause of the issue or if the "unexpected EOF" comes from something else. But that's what I was able to figure out so far.

Here's a screenshot of this issue in action: image

Kahitar commented 3 months ago

Seems like my initial hunch with the double quotes "" is wrong, considering this is apparently the way to escape them in windows cmd (according to #4). So I realized from mentioned issue, that neovim executes the curl in windows cmd, instead of git bash, and if I execute the command there I get an empty response:

curl --silent --no-buffer -X POST http://localhost:11434/api/generate -d "{""messages"": [{""role"": ""user"", ""content"": ""Regarding the following text, hi:\n""}], ""model"": ""mistral"", ""stream"": true}"
{"model":"mistral","created_at":"2024-03-17T17:02:41.9377754Z","response":"","done":true}

I guess I will have to debug my setup with ollama in cmd.

Edit: Acutally, the /api/generate command is just not working. But /api/chat is working even in cmd. So I'm still no wiser as to why it's working in cmd but not in neovim when executing with this plugin...

David-Kunz commented 3 months ago

Hi @Kahitar ,

Thanks for opening this issue. Unfortunately, I have no access to a windows machine, therefore I cannot debug this problem. Would you mind modifying the escaping mechanism to investigate?