ChatGPT from command-line

Hi all, :wave:

if anyone might be interested: I´d like to share my findings for running ChatGPT from the command-line. :blush:

Reading an article called “Bavarder: ChatGPT ohne Account” (Bavarder: ChatGPT without an account) on
Bavarder: ChatGPT ohne Account - GNU/Linux.ch (in German though) I stumbled upon tgpt (GitHub - aandrew-me/tgpt: AI Chat in terminal without needing API keys)
which should make it possible to use ChatGPT using the terminal. :smile:

So I took a closer look at it:

Being as cautious as possible for the first time I try out something new I did it this way:

  • downloaded the latest release (1.2.1) of tgpt from Release tgpt 1.2.1 · aandrew-me/tgpt · GitHub
  • this one can be used as a standalone executable
  • scanned it with clamav (everything´s O.K)
  • logged into Debian (virtual machine)
  • put the file there in a dedicated directory
  • had to make it executable with chmod +x tgpt-linux-amd64
  • ran it in a sandbox (firejail) to further add to safety :wink:
  • you have to provide a search term or expression to it when running the command

I took the example given by the github-page. It is: “Write a simple programme in golang”.

So this is the terminal-output it came up with
(complete output includig firejail status messages; fish syntax):

rosika2@debian ~/D/E/zu_ChatGPT>
firejail --private=(pwd) ./tgpt-linux-amd64 'Write a simple programme in golang'

Reading profile /etc/firejail/default.profile
Reading profile /etc/firejail/disable-common.inc
Reading profile /etc/firejail/disable-passwdmgr.inc
Reading profile /etc/firejail/disable-programs.inc
Warning: networking feature is disabled in Firejail configuration file

** Note: you can use --noprofile to disable default.profile **

Parent pid 2017, child pid 2018
Child process initialized in 87.62 ms
Write a simple programme in golang

Sure, here's a simple program in Go that prints "Hello, world!" to the console:


package main

import "fmt"

func main() {
    fmt.Println("Hello, world!")
}


To run this program, save it to a file with a .go extension (e.g. hello.go) and then run the following command from the terminal:


go run hello.go


This will compile and execute the program, and you should see the output Hello, world! printed to the console.

Parent is shutting down, bye...

rosika2@debian ~/D/E/zu_ChatGPT> echo $status
0

The advantage of running tgpt in a terminal (according to the author)is :

tgpt is a cross-platform cli (commandline) tool that lets you use ChatGPT 3.5 in Terminal without API KEYS.
It communicates with the Backend of Bai chatbot (https://chatbot.theb.ai/).
Its written in Go.

Well, I´m glad I tried it. It seems to work just fine. :+1:
Yet I haven´t done any further experimenting so far.

Many greetings to all
Rosika :slightly_smiling_face:

2 Likes

Thanks for sharing your experience, sadly my German language skills are limited (to ordering beer) so missed some of the dialogue.
Think this could be a path towards the future so will become more important.

1 Like

Hi Rosika,
I tried it
Did all your steps


    downloaded the latest release (1.2.1) of tgpt from Release tgpt 1.2.1 · aandrew-me/tgpt · GitHub 2
    this one can be used as a standalone executable
    scanned it with clamav (everything´s O.K)
    logged into Debian (virtual machine)
    put the file there in a dedicated directory
    had to make it executable with chmod +x tgpt-linux-amd64
    ran it in a sandbox (firejail) to further add to safety :wink:
    you have to provide a search term or expression to it when running the command

Tried the following

nevj@trinity:~
$ firejail ~/bin/tgpt-linux-amd64 'Write an R function to convert integers to character strings'
Reading profile /etc/firejail/default.profile
Reading profile /etc/firejail/disable-common.inc
Reading profile /etc/firejail/disable-passwdmgr.inc
Reading profile /etc/firejail/disable-programs.inc
Warning: networking feature is disabled in Firejail configuration file

** Note: you can use --noprofile to disable default.profile **

Parent pid 7764, child pid 7765
Child process initialized in 44.61 ms
Write an R function to convert integers to character strings

Here's an R function that takes an integer as input and returns a character string:


int_to_char <- function(x) {
  return(as.character(x))
}


You can use this function to convert integers to character strings. For example:


> int_to_char(123)
[1] "123"

> int_to_char(-456)
[1] "-456"
 

This function simply uses the as.character() function to convert the input integer to a character string.

Parent is shutting down, bye...
nevj@trinity:~

Yes that may be useful. I usually ask google when I want to find out how to do something in R. What you dont get with tgpt is all the authors comments that go along with the solution.

Regards
Neville

1 Like

Hi again, :wave:

I´m glad you consider my finding to be at least somewhat interesting. :blush:

@callpaul.eu :

You´re welcome

Sorry for that, Paul.
By “dialogue”, did you mean the gnulinux.ch-site I was referring to?
Yes, that´s in German. If you´re using firefox as a browser you could use the TranslateLocally addon, if you´re interested.

see: TranslateLocally as firefox add-on and
TranslateLocally for Firefox – Get this Extension for 🦊 Firefox (en-US)

Among other languages French, English and German are supported.

It either redraws the entire page using the desired language or you can translated specified parts of the page only… :wink:.

Thanks for your comments. :heart:

@nevj :

Thanks, Neville for trying it out. :heart:

That´s great.

I just might add that the firejail part was just for security reasons on my part. Of course running the executable in a terminal would´ve worked without sandboxing as well. :wink:

I´ve made it a habit of running untrusted or unknown programmes in the sandbox first, just to be sure. Once I know it´s all right I may skip sandboxing it in the future.

I have to add that firejail ueses the default profile whenever there´s no dedicated profile for a certain programme available.
The default.profile doesn´t really provide a huge amount of security, but it´s better than nothing.

That said you can create your own profile for any application which may improve security dramatically.

Right. It seems that way.

Thanks a lot.

Many greetings to you all.
Rosika :slightly_smiling_face:

1 Like

Yes I use translate a great deal, but sometimes you get really funny results.
Thanks to you both I gain so much varied knowledge in areas I know nothing

1 Like

Hi again, Paul, :wave:

Yes, you´re right. I noticed that, too on occasions.

Well, that might be blamed on the Bergamot project, I guess.
But it´s a convenient way for quickly getting the desired page to use your favourite language (provided it´s available).

For better quality translations there´s the trans shell available.

GitHub - soimort/translate-shell: 💬 Command-line translator using Google Translate, Bing Translator, Yandex.Translate, etc. and Translate Shell .

I use it a lot e.g. for practising Hungarian grammar.

The best thing (to me at least) is you don´t have to install it. You can run it as a standalone executable as well.

Of course it´s not quite as convenient to use as the firefox addon, as you have to fire up a terminal.
But it delivers good results, I think. :wink:

Thanks for the compliment, Paul.
But I´m sure you know a great deal more than I do.

Many greetings from Rosika :slightly_smiling_face:

How do you know it is all right? If it is in firejail and misbehaving, would there be messages logged?

1 Like

Hi Neville, :wave:

Yes, but normally the messages firejail writes out to the terminal are enough for me.
Well, I guess I haven´t come across any misbehaving processes yet (which is a good thing :wink: ).

There are other logs, too.
I know that firejail writes to /var/log/syslog. Yet I took a closer look at the man pages and also involved ChatGPT in my quest:

Yes, Firejail does log messages about processes that are running inside it, including any misbehavior or errors that may occur.

By default, Firejail logs to the system log, which is usually located at /var/log/syslog. You can view the Firejail logs by running the following command in the terminal:

sudo grep firejail /var/log/syslog

This will show you all the log messages related to Firejail.
You can also filter the logs by process name, using the --name option. For example, to show logs only for Firefox running in Firejail, you can use the following command:

sudo grep --name="firefox" /var/log/syslog

This command will display all log messages for the process named firefox. You can replace firefox with the name of any other process that you want to filter the logs for.

Alternatively, you can also configure Firejail to log to a separate file instead of the system log.
To do this, you need to edit the Firejail configuration file /etc/firejail/firejail.config and add the following line:

nolog = false

This will enable logging to a file named firejail.log in the user’s home directory.
You can change the log file name and location by modifying the log option in the configuration file.

Ah, the latter one was new to me. :wink:
I haven´t tried it out yet but surely will do so in the near future.

Many greetings from Rosika. :slightly_smiling_face:

1 Like

We need to see if we can make one. Just for testing firejail of course.

Thank you for the detail on firejail. I think it is worth me exercising it for a while, just to develop a proper work pattern.

1 Like

You´re welcome, Neville. :wave:

I guess it´s best to use a virtual machine for that and before doing any tests/experiments create a snapshot of the VM first.

Many greetings
Rosika :slightly_smiling_face:

Very wise. I dont want any damage.

Me neither, Neville. :blush:

I used to take VM snapshots with virt-manager more or less regularly but I´ve forgotten about it a few times as of late.
I guess it must be old age. :wink:

I´ll try to remeber that in future.

Many greetings from Rosika :slightly_smiling_face: