0xacx / chatgpt-shell-cli Goto Github PK
View Code? Open in Web Editor NEWSimple shell script to use OpenAI's ChatGPT and DALL-E from the terminal. No Python or JS required.
Home Page: https://gptshell.cc
License: MIT License
Simple shell script to use OpenAI's ChatGPT and DALL-E from the terminal. No Python or JS required.
Home Page: https://gptshell.cc
License: MIT License
❱chat
Welcome to chatgpt. You can quit with 'exit' or 'q'.
Enter a prompt:
in bash how do you split a long line
chatgpt
In Bash, you can split a long line by using the backslash (\) character at the end of a line to indicate that the
command continues on the next line. Alternatively, you can use parentheses () or curly braces {} to group commands
together and split them onto multiple lines.
Enter a prompt:
demonstrate
Your request to Open AI API failed: invalid_request_error
We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what wassent was not valid JSON. If you have trouble figuring out how to fix this, please send an email to [email protected] and include any relevant code you'd like help with.)
1
❱chat
Welcome to chatgpt. You can quit with 'exit' or 'q'.
Enter a prompt:
in bash how do you split a long line
chatgpt
In Bash, you can split a long line using the backslash (\) character at the end of the line, indicating that the
command continues on the next line. For example:
echo "This is a very long \
line that needs to be split \
into multiple lines for clarity."
Alternatively, you can also use parentheses to group commands and split them across multiple lines. For example:
( command1 arg1 arg2 \
&& command2 arg1 arg2 \
&& command3 arg1 arg2 )
Enter a prompt:
"can you use parentheses () or curly braces {} to group commands together and split them onto multiple lines? if so please demonstrate."
Your request to Open AI API failed: invalid_request_error
We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what wassent was not valid JSON. If you have trouble figuring out how to fix this, please send an email to [email protected] and include any relevant code you'd like help with.)
1
First off this is a Great tool! Thank you for developing and sharing this!
I've seen an error for sed option during install on pop-os/ubuntu, so raising this issue. Could be an easy fix(?)
direster@pop-os:~$ curl -sS https://raw.githubusercontent.com/0xacx/chatGPT-shell-cli/main/install.sh | sudo -E bash sed: invalid option -- 'h' Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]... -n, --quiet, --silent suppress automatic printing of pattern space --debug annotate program execution -e script, --expression=script add the script to the commands to be executed -f script-file, --file=script-file add the contents of script-file to the commands to be executed --follow-symlinks follow symlinks when processing in place -i[SUFFIX], --in-place[=SUFFIX] edit files in place (makes backup if SUFFIX supplied) -l N, --line-length=N specify the desired line-wrap length for the `l' command --posix disable all GNU extensions. -E, -r, --regexp-extended use extended regular expressions in the script (for portability use POSIX -E). -s, --separate consider files as separate rather than as a single, continuous long stream. --sandbox operate in sandbox mode (disable e/r/w commands). -u, --unbuffered load minimal amounts of data from the input files and flush the output buffers more often -z, --null-data separate lines by NUL characters --help display this help and exit --version output version information and exit If no -e, --expression, -f, or --file option is given, then the first non-option argument is taken as the sed script to interpret. All remaining arguments are names of input files; if no input files are specified, then the standard input is read. GNU sed home page: <https://www.gnu.org/software/sed/>. General help using GNU software: <https://www.gnu.org/gethelp/>. Installed chatgpt script to /usr/local/bin/chatgpt OpenAI key and chatgpt path added to ~/.profile Installation complete
Just filing this here even though we spoke about it in the PR.
A raw mode similar to jq -r, pass the question via arguments and have the answer returned to stdout.
I cloned the repo, ran the install.sh, and added my api key.
When I try to enter anything after the prompt, I receive this error message:
"jq: error (at :8): Cannot iterate over null (null)"
I am running Ubuntu 22.10 and I have curl and jq already installed.
Changing user/system profiles not a good idea and can create a mess, use own config instead
Example install.sh
:
if [[ $EUID -eq 0 ]]; then
mkdir -p /etc/chatgpt/chatgpt.txt
echo "OPENAI_KEY=$key" > /etc/chatgpt/chatgpt.conf
else
mkdir -p "$HOME/.config/chatgpt/chatgpt.conf"
echo "OPENAI_KEY=$key" > "$HOME/.config/chatgpt/chatgpt.conf"
fi
Example chatgpt.sh
:
if [[ -f "$HOME/.config/chatgpt/chatgpt.conf" ]]; then
. "$HOME/.config/chatgpt/chatgpt.conf"
elif [[ -f "/etc/chatgpt/chatgpt.conf" ]]; then
. "/etc/chatgpt/chatgpt.conf"
fi
# If OPENAI_KEY empty warn user
if [ -z $OPENAI_KEY ]; then
echo "OPENAI_KEY not set, please add to your env or config file"
fi
if [[ $EUID -eq 0 ]]; then
CHATGPT_BIN="/usr/local/bin/"
else
CHATGPT_BIN="$HOME/local/bin"
# Warn user about PATH
echo 'Add $HOME/local/bin to your PATH environment'
echo 'Example: PATH=$PATH:$HOME/local/bin' # Don't use double-quote to not expand $PATH
fi
# Create path of not exist
mkdir -p "$CHATGPT_BIN"
# Then install to CHATGPT_BIN
curl -sS https://raw.githubusercontent.com/0xacx/chatGPT-shell-cli/main/chatgpt.sh -o "$CHATGPT_BIN/chatgpt"
# Same with imgcat
curl -sS https://iterm2.com/utilities/imgcat -o "$CHATGPT_BIN/imgcat"
Thanks for creating the script.
However, I am failing with
because I do not have a pay OpenAI account it tells me
me@localhost:~$ chatgpt.sh
Welcome to chatgpt. You can quit with 'exit' or 'q'.
Enter a prompt:
what is the radius of earth
Your request to Open AI API failed: insufficient_quota
You exceeded your current quota, please check your plan and billing details.
Getting the following jq
error:
[dave@void ~]$ chatgpt
Welcome to chatgpt. You can quit with 'exit'.
Enter a prompt:
write a hello world script in brainfuck
jq: error (at <stdin>:8): Cannot iterate over null (null)
chatgpt
Enter a prompt:
chatgpt -p 'Hey here is a backslash \ '
Your request to Open AI API failed: invalid_request_error
This is related #96 and will be solved together.
I have several "bugs"
First the most important one:
Your request to Open AI API failed: server_error
The server had an error while processing your request. Sorry about that!
This happens about every 10 th time.
Second. Image creation
When chatGPT replies mathematical expression in
Enter a prompt:
What is the Maclaurin formula of
chatgpt The Maclaurin series formula for
$arcsin(x)=\sum_{n=0}^{\infty}
rac{(2n)!}{4^n(n!)^2(2n+1)}x^{2n+1}$
While "\frac" is the correct response.
Enter a prompt:
chatgpt Without additional information or an equation to solve for a specific value of
While "\theta" is the correct response.
Additionally, I tried to make chatGPT answer in single quotation marks. But that does not work at all either.
curl: (7) Failed to connect to api.openai.com port 443: Operation timed out
Your request to Open AI API failed:
I made two PRs to solve issues I ran into while installing on my machine. Basically, the install script does not check for .zshrc, which is actually the place to put anything related to interactive sessions, such as this package. I do not have a .zprofile on m debian machine, and this is common.
I also did not want /usr/local/bin prepended to my path. It is already therem but is located after conda
/ mambaforge
bin for virtual environment purposes, which is the standard conda install. So the install script should not prepend it.
I made two PRs that solve the issues. #63 and #64
Hope they are useful. Let me know if you have any questions.
Why is root needed?
Would be best to stick to user space and request the user to add PATH to bash_profile
It would be handy to have a separate codehistory file, where anything between in the code block (i.e between and
) is also sent to a second codehistory file.
Am I missing something or why can't I ask follow up questions?
I see that this application is developed by a Mac user and for Mac users, so there's some problems with it running on GNU/Linux.
So in line 263 you have the command "open".
In GNU/Linux there is no such command, but its counterpart is "xdg-open".
You can easily make the script check the system and then use "xdg-open" or "open" depending on the system.
Can the output result increase the effect of character-by-character output, similar to the effect of the web version?
Table output support is not very good, hope it can be optimized
咖啡种类 | 咖啡 | 牛奶 | 糖 | 其他 |
---|---|---|---|---|
拿铁 | 浓缩咖啡 | 牛奶 | 可选 | - |
卡布奇诺 | 浓缩咖啡 | 牛奶 | 可选 | 泡沫奶 |
美式咖啡 | 浓缩咖啡 | 可选 | 可选 | - |
摩卡咖啡 | 浓缩咖啡 | 牛奶 | 巧克力 | - |
香草拿铁 | 浓缩咖啡 | 牛奶 | 香草糖浆 | - |
卡布奇诺玛奇朵 | 浓缩咖啡 | 牛奶 | 可选 | 一层巧克力酱和泡沫奶 |
冰咖啡 | 浓缩咖啡 | 可选 | 可选 | 冰块 |
浓缩咖啡 | 浓缩咖啡 | 可选 | 可选 | - |
注意,这个表格只是一个示例,并不代表所有咖啡店都会使用相同的成分。成分可能因品牌、制作方式、地区和个人口味而异。
A similar project (gpt-chatbot-cli) is on the AUR. But not this one.
hej @0xacx love your chatgpt project!👏
How about integrating getitAI's open Plugin Store for easy plugin installs? (https://www.getit.ai/gpt-plugins) Let's chat for 15 mins: https://calendly.com/d/z4j-cb5-h2y/getitai-devs
Hi could I suggest an uninstall script or instructions to undo everything the install script did?
thanks
Hello !
I've seen your repo and wanted to use it in a Ubuntu Multipass vm but I basically cannot prompt my api key so nothing want to start when I try starting it and there's error.
Could you help me ?
Thanks :)
Please help solve this error in step by step explanation, after got the key:
$ chatgpt
Welcome to chatgpt. You can quit with 'exit' or 'q'.
Enter a prompt:
tesla
Your request to Open AI API failed: invalid_request_error
You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY)
Using a format such as JSON, or COMMAND:
and DESCRIPTION:
could be useful to both teach the user about command lines and also help to detect errors.
It is ok to ask the user to define the env vars, but it is a bad idea to touch the .profile file ourselves from the installer.
❯ ./repos/bin/chatGPT-shell-cli/chatgpt.sh
Welcome to chatgpt. You can quit with 'exit'.
Enter a prompt:
write any python function
chatgpt Here's an example of a Python function that takes two arguments (a and b) and returns their sum:
def add_numbers(a, b):
sum = a + b
return sum
Once defined, you can call this function with two numbers as arguments:
result = add_numbers(5, 7)
print(result)
This would output 12
because the function adds 5 and 7 together.
Enter a prompt:
history
16/03/2023 20:58 write any python function
Here's an example of a Python function that takes two arguments (a and b) and returns their sum: def add_numbers(a, b): sum = a + b return sum
Once defined, you can call this function with two numbers as arguments: result = add_numbers(5, 7) print(result)
This would output 12
because the function adds 5 and 7 together.
$ chatgpt -p 'How many newlines in the following string: "
>
> "'
There are no newlines in the string " ". It consists of two spaces.
Indeed literal newlines are converted into spaces the actual message sent is:
{"role": "user", "content": "How many newlines in the following string: \" \""}
Current escaping has other limitations, I'm making a PR.
Would you consider to add an interactive command execution feature.
This feature should allow users to input a command prompt, and then receive a suggestion for a command to execute based on their input. The application should then ask the user whether they would like to execute the suggested command.
I tried something like this:
Enter a prompt:
show current folder contents
chatgpt Execute 'ls'? (Yes/No, Enter=Yes)
chatgpt.sh install.sh LICENSE README.md test
This feature will make the application more intuitive and user-friendly, and will help users who are not familiar with command-line interfaces to use the application more easily.
Currently, interactive mode only allows for single-line input. This can be
inconvenient when working with longer prompts, especially when copy/pasting code blocks from a code editor. Therefore, I suggest considering allowing multi-line input in interactive mode, perhaps by a distinction between Enter and Shift+Enter.
I believe this enhancement would make the CLI more user-friendly.
Thank you for your consideration.
Ciaran
PROBLEM
Defining OPENAI_KEY as an env var, makes your chatgpt KEY available to any program.
SOLUTION
If instead we store the key in ~/chatgpt-shell-cli.apikey, the user will be able to manage file permissions.
Optionally, having a --update-key options could be a user friendly way to set the api key.
would be great if the tool could understand when a rate limit is hit and wait for the suggested seconds (seems to be always 20s) and try again.
maybe allow max retires in the cmd line.
Cheers
our request to Open AI API failed:
Rate limit reached for default-gpt-3.5-turbo in organization org-OtZ--removed-- on requests per min.
Limit: 3 / min. Please try again in 20s. Contact us through our help center at help.openai.com if you continue to have issues.
Please add a payment method to your account to increase your rate limit.
Visit https://platform.openai.com/account/billing to add a payment method.
here is my terminal output:
paul@laptop ~ % curl -sS https://raw.githubusercontent.com/0xacx/chatGPT-shell-cli/main/install.sh | sudo -E bash
Password:
zsh: done curl -sS |
zsh: suspended (tty input) sudo -E bash
paul@laptop ~ %
For example, If I input the following into ChatGPT web
write a poem:
Beneath the starry sky so bright,
I stand alone in the quiet night.
The moon above shines down on me,
And in its light, my thoughts run free.The gentle breeze that stirs the trees,
Whispers secrets to the leaves.
The crickets' song a symphony,
That fills the air with melody.The world around is hushed and still,
As if in awe of nature's thrill.
The beauty here is plain to see,
And in this moment, I am free.So let my heart and spirit soar,
On wings of wonder evermore.
For in this peaceful, quiet place,
I find my soul has found its grace.
The same in ChatGPT-shell-cli:
Enter a prompt:
write a poem
chatgpt about a treeA tree so tall and greenIt stands so proud and tallIt's leaves so green and freshA sight to behold for allIt's branches reach so highTo the sky, so grand and blueThe trunk so strong and sturdyA sight so old and trueIt's roots so deep and hiddenThe secret to its strengthIt stands through wind and weatherSo tall and vast and lengthA tree so strong and gracefulIt's beauty so sublimeIt stands like a symbolof hope throughout all time
Is it possible for new lines to be used? and what about code blocks?
After commit 752d7b3 I get the following error
❯ ~/repos/bin/chatGPT-shell-cli/chatgpt.sh -p "hello"
goroutine 1 [running]:
runtime/debug.Stack(0x46, 0x0, 0x0)
/usr/lib/go-1.16/src/runtime/debug/stack.go:24 +0x9f
runtime/debug.PrintStack()
/usr/lib/go-1.16/src/runtime/debug/stack.go:16 +0x25
github.com/charmbracelet/bubbletea.(*Program).Start.func2(0xc00058de80)
/root/go/pkg/mod/github.com/charmbracelet/[email protected]/tea.go:294 +0xd3
panic(0xc3ae40, 0x11e48e0)
/usr/lib/go-1.16/src/runtime/panic.go:965 +0x1b9
strings.Repeat(0xdf0bc0, 0x1, 0xffffffffffffffff, 0xc3ae40, 0xc00025b980)
/usr/lib/go-1.16/src/strings/strings.go:529 +0x5e5
github.com/charmbracelet/bubbles/viewport.Model.View(0x0, 0x0, 0x0, 0x0, 0x1, 0xc0002daa80, 0xa6, 0xa6, 0x1619d80, 0x4)
/root/go/pkg/mod/github.com/charmbracelet/[email protected]/viewport/viewport.go:361 +0x225
github.com/charmbracelet/glow/ui.pagerModel.View(0xc00030fba0, 0x0, 0x0, 0x0, 0x0, 0x1, 0xc0002daa80, 0xa6, 0xa6, 0x0, ...)
/home/ed/gh/glow/ui/pager.go:337 +0x8a
github.com/charmbracelet/glow/ui.model.View(0xc00030fba0, 0x1, 0x0, 0x0, 0x0, 0xc00030fba0, 0x0, 0x0, 0x1619d80, 0x4, ...)
/home/ed/gh/glow/ui/ui.go:444 +0x79
github.com/charmbracelet/bubbletea.(*Program).Start(0xc00058de80, 0x0, 0x0)
/root/go/pkg/mod/github.com/charmbracelet/[email protected]/tea.go:419 +0x72c
main.runTUI(0x0, 0x0, 0x0, 0x0, 0x0)
/home/ed/gh/glow/main.go:327 +0x293
main.execute(0x161d540, 0x166b630, 0x0, 0x0, 0x0, 0x0)
/home/ed/gh/glow/main.go:190 +0x1d6
github.com/spf13/cobra.(*Command).execute(0x161d540, 0xc000020210, 0x0, 0x0, 0x161d540, 0xc000020210)
/root/go/pkg/mod/github.com/spf13/[email protected]/command.go:852 +0x472
github.com/spf13/cobra.(*Command).ExecuteC(0x161d540, 0x0, 0x15c6b08, 0xc000028118)
/root/go/pkg/mod/github.com/spf13/[email protected]/command.go:960 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
/root/go/pkg/mod/github.com/spf13/[email protected]/command.go:897
main.main()
/home/ed/gh/glow/main.go:337 +0x2d
Caught panic:
strings: negative Repeat count
Restoring terminal...
Thanks for using Glow!
I can use the cli week ago, but now when I try to prompt in the shell, it show above error.
It look like the curl error itself, and I try "curl https://api.openai.com/v1/chat/completions" in the shell, it show the same error.
How I can try to debug the error. Or the opneAi api alread change something to block the access from "curl"?
Some shells don't have the COLUMNS defined in certain cases.
This makes fold error: fold: invalid number of columns: ‘’
A sane default would be appreciated. Either really big or a standard width 80.
Simply changing $COLUMNS
-> ${COLUMNS:-80}
would be an improvement.
❯ chatgpt
Provide a prompt for ChatGPT, or type /help or ? to list commands.
1> /login
Enter username or email: [email protected]
AttributeError("'NoneType' object has no attribute 'password'")```
1>
Obviously I'm trying to use it, tried installing from AUR and from pip.
uname -a:
Linux mjolnir 6.2.8-zen1-1-zen
python version
❯ python --version
Python 3.10.10
zsh shell.
Reported on discord:
Running chatgpt in pipe mode:
cat /test_playbook.yml | ./chatgpt.sh --init-prompt-from-file ../prompts/documentation_instructions_and_format.txt
results in
fold: illegal width value
Assumption: The $COLUMNS variable probably is not initialized or updated properly when using pipe mode.
The command I run:
~/repos/bin/chatGPT-shell-cli/chatgpt.sh -m gpt-4 --init-prompt-from-file ~pr/tutor
The init file is json:
https://raw.githubusercontent.com/JushBJJ/Mr.-Ranedeer-AI-Tutor/main/Mr_Ranedeer.json
The full error:
Your request to Open AI API failed: invalid_request_error
We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)
$ chatgpt
Welcome to chatgpt. You can quit with 'exit'.
Enter a prompt:
hello
Your request to Open AI API failed: insufficient_quota
You exceeded your current quota, please check your plan and billing details.
Observe the return pi
line, where it seems a * was expanded into the contents of my home directory.
chatgpt Sure! Here's an implementation of the Leibniz formula for calculating pi in Python:
```python
def calculate_pi():
pi = 0
sign = 1
denominator = 1
precision = 1e-10 # 10 decimal places
while True:
term = sign / denominator
if abs(term) < precision:
break
pi += term
sign = -sign
denominator += 2
return pi Applications Desktop Documents Downloads Dropbox (Work) Dropbox (Personal) Library Movies Music Pictures Public PycharmProjects X-Plane 11 bin dotfiles go myapi sendKindle venvs 4
print(calculate_pi())
This algorithm uses an infinite series to calculate pi, adding and subtracting terms alternately to converge on the value. The precision
variable determines how close the result needs to be to the true value of pi, and the loop continues until the absolute value of the next term is smaller than that precision. The result is then multiplied by 4 since the series actually calculates pi/4.
Enter a prompt:
Bito AI offers code explanations. And It has been implementated in this project . I think there may need to add extra API endpoints but it would great to have code explanation.
The script is still small enough to migrate to /bin/sh without much effort, leading to a more portable script. I would suggest you do so.
Any idea why AI reply here different to official homepage https://chat.openai.com/chat
, what actually makes it so and how to obtain the one in that site?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.