terror / chatgpt.nvim

Query ChatGPT in Neovim
Creative Commons Zero v1.0 Universal
278 stars 15 forks source link

Trailing characters #24

Open Montana opened 1 year ago

Montana commented 1 year ago

Hi everyone,

When I try and run the following:

ChatGPT test

I get the following error:


Trailing characters: test

I've attached a screenshot.

Screenshot 2023-04-05 at 3 54 52 PM

I've followed some feasible solutions @terror, but none of them seem to work.

terror commented 1 year ago

Hmm strange, running this exact command on the following neovim version seems to work for me:

NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3
Montana commented 1 year ago

Hi @terror,

As it turns out @terror, this seems to work (still working out somethings, might be useful to add to your documentation for all the folks using Lazy instead of Packer.) Since I already have @jackMort's ChatGPT.nvim plugin installed, according to Lazy install all, the package is loaded and there's no issues. Maybe we can work on this together so the widely used other ChatGPT.nvim has synergy. I could see foresee this being a problem for people using Lazy. Here's my main core.lua file:

{ 
"jackMort/ChatGPT.nvim",
    event = "VeryLazy",
    config = function()
      require("chatgpt").setup()
    end
},

{
"terror/chatgpt.nvim",
     event = "VeryLazy",
     config = function()
       require("chatgpt").setup()
           run = "pip3 install -r requirements.txt"
    end
  }
}

Here's a screenshot of Lazy install all where it says chatgpt.nvim is loaded via VeryLazy:

Screenshot 2023-04-06 at 7 54 15 AM

So in every sense when I run ChatGPT test this should in theory work, and it shouldn't have to require Packer, as it was installed using Lazy., but to no avail:

Screenshot 2023-04-06 at 2 05 28 PM

Cheers, Montana Mendy

howtotalktogirlsatparties commented 1 year ago

having exact same issue, thanks for laying it out so nice @montana.

@terror maybe a setup video from a-z would be cool for the README, documenation is a bit sparse.

Montana commented 1 year ago

Thanks for the kind words,

It's worth noting - I'm running this instance of AstoNVim on Docker. I spun it up via:

docker run -it alpine:edge
apk add git curl NeoVim 
git clone --depth 1 https://github.com/AstroNvim/AstroNvim ~/.config/nvim
nvim
nvim ~/.config/lua/user/plugins/core.lua
git clone https://github.com/AstroNvim/user_example ~/.config/nvim/lua/user
nvim ~/.config/lua/user/plugins/core.lua
git clone --depth 1 https://github.com/AstroNvim/AstroNvim ~/.config/nvim
git clone https://github.com/AstroNvim/user_example ~/.config/nvim/lua/user
nvim ~/.config/nvim/lua/user/plugins/core.lua
soure .bashrc
echo $OPENAI_API_KEY
nvim .bashrc
source .bashrc
nvim

Then to the rest of the configuration; e.g. (Editing the core.lua file from @jackMort's ChatGPT.nvim client, to add require in there, and add the OPENAI_API_KEY environment variable.) I don't know if that would effect it, (I don't see how it would.)

As far as the API key goes, I've fixed the JSON to double quotes, it now looks like this:

{ "api_key": "<API-KEY>" }

In the chatgpt_nvim.py file, I've defined the following CONFIG_PATHS:

CONFIG_PATH = '~/.chatgpt-nvim.json'
DEFAULT_CONFIG = { 'authorization:'  '', 'session_token': 'My OpenAI API Token'}

I installed the dependencies from the requirements.txt by using the following:

pip3 install -r requirements.txt -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

I also checked by running regular pip3 install -r requirements.txt all requirements are met. Googling my issue is too garden variety to take any of the solutions as a viable one. I appreciate it a lot @terror.

Cheers, Montana Mendy

EvilOtto2 commented 1 year ago

Hi @Montana

I too am getting the "E488 Trailing Characters" issue, the issue for me is i'm not sure how to edit the python file. there's not that much documentation. the video showed was only about 30 seconds and it looked like author had it already installed but I am getting "E488 Trailing Characters" . I even tried doing in nvim :%s/\/apps/log_dir/g this is where string to replace=/apps and replaced string=log_dir

hopefully we can get this resolved! it's such a cool function.

-Otto

Montana commented 1 year ago

Hi @EvilOtto2,

There is a question, on some imports in this Python file, that don't exist in the Python file in the really cool video @terror posted. I'll attach screenshot. In particular Enum.

Screenshot 2023-04-06 at 5 50 32 PM

I've debugged a little, the only thing I can think of is since @jackMort's plugin is called ChatGPT.nvim and this one in particular @terror's is called chatgpt.nvim, is it feasible that there might be some naming collision?

Screenshot 2023-04-06 at 5 54 19 PM

Theoretically it could be just a weird setting in nvim that needs to be changed, but I'm wondering if there is a naming collision issue here at hand? I honestly even question that though given the casing of each plugin.

Cheers, Montana Mendy

terror commented 1 year ago

Hi @EvilOtto2,

There is a question, on some imports in this Python file, that don't exist in the Python file in the really cool video @terror posted. I'll attach screenshot. In particular Enum.

Screenshot 2023-04-06 at 5 50 32 PM

I've debugged a little, the only thing I can think of is since @jackMort's plugin is called ChatGPT.nvim and this one in particular @terror's is called chatgpt.nvim, is it feasible that there might be some naming collision?

Screenshot 2023-04-06 at 5 54 19 PM

Theoretically it could be just a weird setting in nvim that needs to be changed, but I'm wondering if there is a naming collision issue here at hand? I honestly even question that though given the casing of each plugin.

Cheers, Montana Mendy

It seems like you're running an outdated version of the plugin, I'd try either updating or re-installing the plugin entirely -- I've since switched to using the official OpenAI python bindings instead of the reverse-engineered one. Let me know if this works!

Montana commented 1 year ago

Very interesting @terror,

I also have the Enum library being called by Python to be imported in the chatgpt_nvim.py headers, I'll run:

rm -rf chatgpt.nvim
git clone https://github.com/terror/chatgpt.nvim

Then re-install. This is probably the fix. I really appreciate it @terror.

Montana commented 1 year ago

Hi @terror,

To confirm, is the one you show in asciinema the current chat_nvim.py? I only ask that because looking at the current repo, both still have the library Enum being imported to the headers, on both branches that exist.

Screenshot 2023-04-07 at 11 14 30 AM

In the asciinema video, these don't exist. Just wondering, and if so is there any way I could see that configuration instead of the ones pushed up (that is if that's the most current build.) I'd assume since the video was made four months ago, the current build that's in the repo is the most recent, just confused about the Enum statement.

I guess my final question is, in these variables:

CONFIG_PATH = '~/.chatgpt-nvim.json'
DEFAULT_CONFIG = { 'authorization:'  '', 'session_token': 'My OpenAI API Token'}

I understand that CONFIG_PATH is just calling the JSON file with the API token in it, but in DEFAULT_CONFIG what things are expected to be defined here? In my example, from my understanding of REST I do have the syntax right. I'm assuming as this is just using REST and that this is authenticating by sessions, so in turn you must specify the token for the session, in which case would be the OpenAI token.

Thanks again @terror.

Montana commented 1 year ago

Hey everyone,

I've finally got it working, the issue is things like NeoVim, AstroNVim, LunarVim, I could go on are moving away from Packer. I've yet to find a good way to install this through Lazy, which seems to be the new package standard for these templated NeoVim variants and not Packer.

So the current fix is to pull an old version of NeoVim off a older tree, for example:

git clone https://github.com/neovim/neovim/tree/v0.8.0

Then try installing this plugin. For example, once I was using Packer and not Lazy:

Query:

Screenshot 2023-04-09 at 3 31 41 PM

Response:

Screenshot 2023-04-09 at 3 30 52 PM

Cheers, Montana Mendy