0xacx / chatGPT-shell-cli

Simple shell script to use OpenAI's ChatGPT and DALL-E from the terminal. No Python or JS required.
https://gptshell.cc
MIT License
1.07k stars 152 forks source link

Cannot prompt api key #2

Closed LaikaSerrano closed 1 year ago

LaikaSerrano commented 1 year ago

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 :)

0xacx commented 1 year ago

Hi, Assuming that you have installed curl and jq in your machine, running the install script should work for Ubuntu. You can install curl using sudo apt-get install curl and jq in the same way.

Once you have curl, you can download and run the install script with this command curl -sS https://raw.githubusercontent.com/0xacx/chatGPT-shell-cli/main/install.sh | sudo -E bash, which will ask for your OpenAI API key and set it as an environment variable.

If want to install it manually, all you have to do is:

  1. Download the chatgpt.sh file in a directory you want
  2. Add the path of chatgpt.sh to your $PATH. You do that by adding this to your shell profile.export PATH=$PATH:/path/to/chatgpt.sh. If you use zsh, your shell profile is ~/.zprofile, if you're using bash it's ~/.profile in Ubuntu.
  3. Add the OpenAI API token to your shell profile by adding this line export OPENAI_TOKEN=your_token_here

Hope that helps!

LaikaSerrano commented 1 year ago

I am still having the same problem even though i'm installing it manually. I have an error from jq saying "jq: error (at :8): Cannot iterate over null (null)". I am not familiar with JQ, could you help me to fixe this error ? Prompt the api key directly in ~/.profile worked but I cannot have response from the chat.

0xacx commented 1 year ago

What prompt are you using? Using " quotation marks in the prompt can cause this error.

LaikaSerrano commented 1 year ago

Basically none in the cli and in profile I tried " and ' but nothing change.

0xacx commented 1 year ago

Prompt is the question you ask to chatGPT, you don't need to set it anywhere, you just type it when the script is running, the same way you would do when chatting in https://chat.openai.com/chat.

I just added the quotation marks escape, so now you can use quotation marks in the prompt.

In your ~/.profile, it shouldn't matter if you add the export statements with or without quotation marks, it should work both ways.

Try to curl the API from your terminal to see if you get a correct response. Just replace YOUR_TOKEN with your OpenAI token.

curl https://api.openai.com/v1/completions \
                -sS \
                -H 'Content-Type: application/json' \
                -H "Authorization: Bearer YOUR_TOKEN" \
                -d '{
                        "model": "text-davinci-003",
                        "prompt": "How to make an HTTP request in javascript?",
                        "max_tokens": 1000,
                        "temperature": 0.7
        }'

If that works and you have set your OpenAI key correctly in your shell profile, the script should work.

LaikaSerrano commented 1 year ago

It works like that. I tried to reinstall everything from the script and it seems working now. I'll come back to you if it doesn't work anymore. Thanks !