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.05k stars 151 forks source link

I have a few of these errors. Am I using a character that I'm supposed to escape or something? If so, which one? #94

Closed JackDinn closed 1 year ago

JackDinn commented 1 year ago
❱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 support@openai.com 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 support@openai.com and include any relevant code you'd like help with.)
1
0xacx commented 1 year ago

After merging https://github.com/0xacx/chatGPT-shell-cli/pull/100, this should work properly now.

$ ./chatgpt.sh 
Welcome to chatgpt. You can quit with 'exit' or 'q'.

Enter a prompt:
in bash how do you split a long line?

chatgpt 

  To split a long line in Bash, you can use the backslash ("\") character at  
  the end of the line to indicate that the line continues on the next line.   
  For example:                                                                

    echo "This is a very long \                                               
    line that I want to split \                                               
    into multiple lines"                                                      

  Alternatively, you can use parentheses to group multiple lines together,    
  like this:                                                                  

    echo "This is a very long" \                                              
         "line that I want to split" \                                        
         "into multiple lines"                                                

  Both of these methods will result in the same output:                       

    This is a very long line that I want to split into multiple lines         

Enter a prompt:

@JackDinn Let me know if it works for you!

JackDinn commented 1 year ago

I will do once it comes through to the arch user repo. Im currently using this:-

❱yay -Si chatgpt-shell-cli-git :: Querying AUR... Repository : aur Name : chatgpt-shell-cli-git Keywords : chat chatgpt cli dali e-dali gpt shell Version : 1.0.r161.ea41590-2 Description : Use OpenAI's ChatGPT and DALL-E from the terminal. URL : https://github.com/0xacx/chatGPT-shell-cli.git AUR URL : https://aur.archlinux.org/packages/chatgpt-shell-cli-git Groups : None Licenses : MIT Provides : chatgpt-shell-cli-git Depends On : jq curl Make Deps : git Check Deps : None Optional Deps : None Conflicts With : chatgpt-shell-cli Maintainer : Zeioth Votes : 1 Popularity : 0.425090 First Submitted : Sun 19 Mar 2023 05:17:10 PM GMT Last Modified : Fri 31 Mar 2023 12:10:22 PM BST Out-of-date : No

I dont really want to mess around with uninstalling this and then using your git, but i will let you know.

Many thx :)

0xacx commented 1 year ago

@Zeioth is the maintainer of the AUR package. In my understanding since the package references the git repo directly, changes should be immediately available, but I haven't confirmed this.

JackDinn commented 1 year ago

well thats kinda what i always thought about the AUR's that point to git but I'm never sure.

The AUR says it was last updated 2023-03-31 11:10 (UTC) so ... i don't know. Im sure i could just download your code and use it directly just to test, but iv got some of my own code that is using it from the AUR binary. I don't want to get in a muddle and mess up what iv got.

0xacx commented 1 year ago

I don't think you need to download the code. If you just reinstalled with paru -S chatgpt-shell-cli I think it should work 🤞 The last updated timestamp on AUR probably refers to the changes made in the AUR file itself. But yes, you know your setup better. I am just curious if the changes are available immediately in the AUR.

Zeioth commented 1 year ago

Try also chatgpt-shell-cli-git.That one is 1:1 with this repo.

JackDinn commented 1 year ago

No, as far as i can tell it still does that same. I have removed chatgpt-shell-cli-git and installed chatgpt-shell-cli ver 0.2.2

2 aur/chatgpt-shell-cli-git 1.0.r161.ea41590-2 (+1 0.43)
Use OpenAI's ChatGPT and DALL-E from the terminal.
1 aur/chatgpt-shell-cli 0.2-2 (+3 1.77) (Installed)
Use OpenAI's ChatGPT and DALL-E from the terminal.

But unfortunately it still does exactly the same

❱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 to indicate that the command continues on the next line. For example:

echo "This is a very long \
line of text that needs to \
be split into multiple lines."

This will output the following on a single line:

This is a very long line of text that needs to be split into 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 contact us through our help center at help.openai.com.)
1
JackDinn commented 1 year ago

Does your not do the same if you use the exact same prompts?

1st prompt :- "in bash how do you split a long line" 2nd prompt :- "demonstrate"

Everything else works fine for me but these two particular prompts throw this error.

0xacx commented 1 year ago

It works fine for me. I also have installed glow for markdown rendering, so the formatting and indentation you see is from glow, but this shouldn't affect the escaping of backslash.

$ ./chatgpt.sh 
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 each line to indicate that the command continues on the next     
  line. For example:                                                          

    $ echo "This is a very long\                                              
    > line that I want to split\                                              
    > into multiple lines\                                                    
    > using the backslash character."                                         

  This will output:                                                           

    This is a very long line that I want to split into multiple lines using   
  the backslash character.                                                    

Enter a prompt:
demonstrate

chatgpt 

  Sure! Here's an example of splitting a long command into multiple lines     
  using the backslash character:                                              

    $ git commit -m "This is a very long commit message that I want \         
    to split into multiple lines for better readability. \                    
    I can use the backslash character at the end of each line \               
    to indicate that the command continues on the next line."                 

  This will commit the changes with the specified commit message, which is    
  split across multiple lines for better readability. Note that when you press
  Enter after the backslash character, there should be no whitespace after the
  backslash character, otherwise it will not work.                            

Enter a prompt:
give me an example with curl

chatgpt 

  Sure! Here's an example of splitting a long URL into multiple lines using   
  the backslash character with curl:                                          

    $ curl -X GET \                                                           
      -H "Content-Type: application/json" \                                   
      -H "Authorization: Bearer token" \                                      
      "https://api.example.com/endpoint?param1=value1&param2=value2"          

  In this example, the curl command is making a GET request to an API endpoint
  with headers and query parameters. The URL is split across multiple lines   
  using the backslash character for better readability. Note that each line   
  after the first starts with a whitespace character, which is optional but   
  can make the command easier to read.                                        

Enter a prompt:
JackDinn commented 1 year ago

well i pass. I have glow as well ^^

I did notice there is no chatgpt --version ?

Its not important to me as it was just something i stumbled across when i was testing. It's not something i'd ever come across again (i hope). I use it every day without any problems, so it really makes no sense to me, sorry :(

0xacx commented 1 year ago

No there is no --version. So far all changes are backwards compatible, meaning we never broke something to add something new. What you get from the repo is always the latest version. Adding versioning would mean that it would require some version and release management and I think this is really not worth it for a simple one file script. But if in the future we need to add breaking changes then we would have to use versions to differentiate.

JackDinn commented 1 year ago

Unless it has something to do with the fact that I use FISH, I can't see how. Other than that, I would have to use your open code, look at the JSON as it's created, and figure out what's going on before it's attempted to be sent. But I'm busy with stuff :).

JackDinn commented 1 year ago

Ok, it was making me scratch my head. I removed all versions (the CLI, CLI- Git, and the Git folder where I had it cloned). Basically, I removed every remnant of it. I rebooted the system and reinstalled ChatGPT-Shell-CLI from the AUR, and it's working! :woozy_face:

Don't ask, but it looks like it was a "me" problem.

Thx for your help :smile: