aandrew-me / tgpt

AI Chatbots in terminal without needing API keys

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to use my terminal session after quitting the interactive mode since the last update.

dangrenier83 opened this issue · comments

Hello,

Ever since the new update I seem to be unable to use my terminal after starting an interactive mode session of tgpt. It seems to exit normally as no error is displayed (I tried with exit and CTRL-c and the same happens). After this the terminal session is unusable and typing is impossible.

I use it on 3 platforms - on a Pop_OS desktop, a Manjaro laptop and a Raspberry Pi running Debian.

I had this problem on my Pop_OS desktop and Raspberry Pi (to which I ssh from my windows box) ever since the update, before it was working well.

I believe this bug is due to your handling of errors in interactive mode so that it doesn't leave the program. Weirdly, it doesnt seem to be exiting non-gracefully and shows my prompt after using exit or CTRL-c.

Update

The problem seems to be in fact related to the use of the of the go-prompt library we need to learn more about it as it seems to be only affecting bash users..

My typical usage for troubleshooting

  1. Launch tgpt -i
  2. Ask ChatGPT something, response is working and shows a new prompt
  3. Can indefinitely query ChatGPT for something until I am done
  4. Use CTRL-c or exit and the issue happens

What I tried so far

  • Using other terminal emulators to check if it was something broken on their part (I mainly use alacritty)
  • Not updating tgpt on my Manjaro machine and see if the issue was happening -> it wasn't
  • I then updated the tgpt on my Manjaro machine and had the exact problem

More misc infos

  • Currently up to date on all 3 platforms so the go version should be the same for everyone
  • I can provide more information upon request
  • I use a Bash shell which seems to be part of the problem according to the development of this issue (see related info below).

See if you can reproduce the issue yourself, I'm fairly certain there was a bug introduced in your latest update as I tried many other CLI programs that I used, some of which who are providing their own interactive prompt and there was no issue.

I just tried to use the latest amd64 exe version on Windows in a normal powershell environment and cannot reproduce the issue. Therefore, it seems limited to linux environments.

I was wondering also wondering if the problem could be related to specifics in my .bashrc as I customized it quite a bit but I just tried with a default one from /etc/skel and still had the same issue. If anyone running linux can reproduce it this would be very helpful.

Analyzing your previous commits, it seems that the problem resides in the use of the go-prompt library. Multiple users report having this problem on a linux environment and they can work around it by typing stty sane even though they cannot see. I just tested it and it works but having to type this everytime seems like a hassle.

Apparently, there is no issue on windows powershell.

Also, multiple users have reported downgrading to the 0.2.5 version of go-prompt fixes this issue.

From what I gathered, mapping the CTRL-C as a custom function with go-prompt doesn't work the same way as an INTERRUPT signal would from a normal CTRL-C, and by overriding it with the go-prompt function it somehow doesn't return to the expected state.

c-bata/go-prompt#233

Here is the result of the stty -a command which is used to list the parameters of the current tty session. I can write commands during this time but cannot see them.

During the issue (first line is blank but command entered is stty -a)

pi@raspberrypi:~$
speed 9600 baud; rows 46; columns 152; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc

After resolving the issue with the workaround of using stty sane

pi@raspberrypi:~$
pi@raspberrypi:~$ stty -a
speed 9600 baud; rows 46; columns 152; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -ixon -ixoff -iuclc -ixany imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc

From what I see only the last line changes slightly I will analyze what this means tommorow.

I really appreciate you putting so much effort with the issue. I personally use fish shell and for some reason, I don't face this issue, however I encountered it when I switched to bash. I tried some of the solutions but none seem to work, I will see what I can do

Even with downgrading the go-prompt library to 0.2.5? I wanted to try tommorow but I was busy tonight so I couldn't try it right away and I am not the most familiar with Go projects but I will try to replicate that bug with the library.

I will however monitor the issue as anyone with a bash shell should get it if you were able to replicate it...

I think your program is awesome as I value quick AI answers from a terminal without the need for credentials or a browser...

Yes even with downgrading

Ok thank you I will test it and work upstream if I am able to help with the library owner in question. This puzzles me and it makes me mad.

I tested in fish and zsh shells, no problems there with tgpt -i, what shell are you using?

Just regular bash. Someone on the library issue had trouble also with OS X also probably also using with a Bash shell although now I believe they use zsh by default - haven't used a OS X machine in a while. We will get to the bottom of this.

Yeah, well you can switch to some other shell for now if you want

That's for sure but I find it problematic and would love to help resolve this issue. It is nothing that I cannot deal with just annoying. These kind of issues are a big pain in the ass :) I will check what I can do tommorow on my end with compiling your source and trying on my end. If I amount to anything clear I will keep you informed.

In the meantime, I will just make an alias using the stty sane command to regain visual access over my old man bash shell with fewer keystrokes.

It would seemingly help some of the users of go-prompt if I manage to find the reason for this comportment for Bash which after all is still used by a lot of people...

I am glad that you were able to replicate it. We will find the problem.

It's not like this project hasn't already faced some hardships with API calls isn't it?

Indeed, appreciate your help!

Okay I was able to fix it with

	reinitialization := exec.Command("reset")
	_ = reinitialization.Run()

Oh yeah? I was reading about my tty flags related to ISIG the other changes and wasn't having much success for the moment. That is really good news for everyone using the bash shell!

Indeed, this one is also working

Great to know there is a workaround as using an outdated version of a library sucks. Be sure to take your time for the next release nothing about this is stressful and I'm sure the user community will be greatly happy.

Yes, there is a newer forked version, but the problem is still there for me

Thank you for your quick response time, it is greatly appreciated, your tool is useful for some of us!

Do you want to do a quick test to confirm that it works on your side?

Unfortunately, I cannot compile a new version from scratch tonight it is currently 7 am and I need some sleep. I will however try tommorow.

As I said earlier, I am not too familiar with Go projects so I am not able to help right now.

No problems, when you wake up, you will have the new version to update to. Good night!

You too friend, I will try to learn more about Go so I can help more effectively if another issue arises.

Everything working perfectly on my end cheers man!

Awesome!

I have been trying to install tgpt on my M2 Mac mini for over an hour and haven't had any luck. I've tried a variety of approaches including the curl -sSL link, installing Go, downloading the .zip and running the install file, and I continue to run into the same error message:
"mv: rename /tmp/tgpt to /usr/local/bin: Permission denied"

The very first time I tried the curl -sSL link it gave me a message saying to type tgpt -h for help, but when I did I immediately got the following error.
"-bash: tgpt: command not found"

I've run the uninstall script each time I've been unsuccessful. Any ideas why I can't get this to install properly?

I have been trying to install tgpt on my M2 Mac mini for over an hour and haven't had any luck. I've tried a variety of approaches including the curl -sSL link, installing Go, downloading the .zip and running the install file, and I continue to run into the same error message: "mv: rename /tmp/tgpt to /usr/local/bin: Permission denied"

The very first time I tried the curl -sSL link it gave me a message saying to type tgpt -h for help, but when I did I immediately got the following error. "-bash: tgpt: command not found"

I've run the uninstall script each time I've been unsuccessful. Any ideas why I can't get this to install properly?

Well to install with go you need to have ~/go/bin in path. Now I see you had permission problems, do you have admin privileges on your mac? The install script installs the program to /usr/local/bin because its usually in PATH

@calibers16 And if you don't have admin privilages, you can download tgpt-mac-arm64 from Releases, then give it execution permission with chmod +x and then execute it. You can move it to some directory which is in PATH and rename it

Thanks @aandrew-me for the speedy reply! Updates:

  1. I downloaded the Mac installer, used chmod +x to install, and can now open it with "./tgpt-mac-arm64." When run I am greeted with "Hello! How can I assist you today?", but I can't reply without first being in /Downloads and typing "./tgpt" first.
  2. Secondly, I once again used your curl -sSL URL agin but changed the install path (see below) and was successful.
    curl -sSL https://raw.githubusercontent.com/aandrew-me/tgpt/main/install | bash -s /usr/local/tgpt
  3. This is where my inexperience with Terminal is coming in (I'm just a few steps above novice at this point). The notification I get mentions PATH like you did above:
Make sure your file is in PATH
Run tgpt -h for help

I don't know what path I'm supposed to move it to, or how to link it so that when I type "tgpt" in Terminal it points to the app. I'm looking online but not immediately getting helpful info yet. Could you give me an example (or a URL to an explanation) for where I'm supposed to put the "tgpt-mac-arm64" file for the app to run properly?

Thank you for your help and your patience while I learn! I can't wait to use this tool :D

What I am referring to is PATH variable. If a directory is in PATH, then if any executable is inside the directory, you can execute it without specifying the full path of the executable. For example, lets suppose, /usr/local/bin is in PATH (it usually is on Mac), then if you put any executable in it, for example tgpt, you wouldn't need to do /usr/local/bin/tgpt to execute it or go to that directory each time like you are doing by going to Downloads. That's why the install script tried to put the tgpt executable there. But to put something to /usr/local/bin you need admin privileges (sudo).

You said that you installed to /usr/local/tgpt. Now to execute tgpt normally, you would need to add /usr/local to PATH, but I don't think its a proper place to put tgpt but whatever.

Here you can find more about PATH - https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them

If you have admin privilages, do this (you have to be in the directory where the file is located)
mv tgpt-mac-arm64 tgpt && sudo mv tgpt /usr/local/bin/tgpt

It will rename the executable to tgpt and move it to /usr/local/bin which is most likely in PATH.

The command will prompt you for your password, enter it and it should be done

Thanks! Got it working - appreciate the help!