Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't copy-paste code without getting indent/line breaks errors and tons of blank spaces messing around the code #13

Closed
roperi opened this issue Mar 20, 2023 · 10 comments

Comments

@roperi
Copy link

roperi commented Mar 20, 2023

When presenting ChatGPT a piece of code to refactor it, GPT answers back the refactored code inside a black colored block. It looks fine but If i were to copy the code and paste it in a text editor or IDE, it will look something like this:

 if __name__ ==
 "__main__":                                                                                                                                                                                                      
          main()   

Not only it breaks it down in three rows when it should be only one two but also it will be filled with blank spaces everywhere. Editing/cleaning it takes a lot of time.

EDIT:
Using Gnome terminal version 0.54.2 +GNUTLS

@evilpan
Copy link
Owner

evilpan commented Mar 21, 2023

Seems that this is caused by rich text, you may try copy and paste as plaintext to see if it solves the problem.

@evilpan
Copy link
Owner

evilpan commented Mar 21, 2023

I've update the code to add .save command to save conversation to file, by copying the content in the json file you may get the original results. I am also planing to add options to save/load conversation file as text file (markdown), and it would be more friendly for human reading.

@roperi
Copy link
Author

roperi commented Mar 21, 2023

Seems that this is caused by rich text, you may try copy and paste as plaintext to see if it solves the problem.

I just tried it and looks fine but still has tons of blank spaces surrounding the code.

Also, paste it as plaintext is not available for some editors. I had to open it in Writer Document in Libre Office to be able to paste it as Unformatted Text (and blank spaces are still everywhere).

The idea of saving it is great though! Thanks, @evilpan . You are not so evil after all ;)

@roperi
Copy link
Author

roperi commented Mar 21, 2023

I just git pulled but i don't get how to use .save.

This is what I do:

~/workspace/gptcli$ ./gptcli.py 
Loading config from /home/user/workspace/gptcli/config.json
Response in prompt: True
Stream mode: True
Input: 

I don't see the gptclip> as shown in README . Then in the input prompt I type .save and get back:

I'm sorry, I cannot perform file operations such as saving a file. However, I can still help you with any questions or information you need.

@roperi
Copy link
Author

roperi commented Mar 21, 2023

Also tried this:

./gptcli.py .save
usage: gptcli.py [-h] [-c CONFIG]
gptcli.py: error: unrecognized arguments: .save

@evilpan
Copy link
Owner

evilpan commented Mar 21, 2023

Seems you are not using the latest code, are you sure the git pull command returns successfully?

@roperi
Copy link
Author

roperi commented Mar 21, 2023

@evilpan

Sorry, i thought I was git pulling but didn't notice I was getting an error back, so I wasn't really pulling anything.

Anyway, I fixed the error and git pulled your latest commits but now it fails with FileNotFoundError: [Errno 2] No such file or directory /home/user/gptcli/config.json. I see the default config file is config.json in code, but in the repo you have it named as demo_config.json. So it fails when starting it up. So i had to start it with ./gptcli.py -c demo_config.json (which i didn't want to as i wanted to run on defaults without any arg flag).

Now, since i deleted the OpenAi key from the config (so it can it read from the environment) it fails with :

OpenAIError: You didn't provide an API key...

@roperi
Copy link
Author

roperi commented Mar 21, 2023

Anyway! I can save the chat!

[
  {
    "role": "user",
    "content": "write a python script that prints 'hello, world!' and the time."
  },
  {
    "role": "assistant",
    "content": "Here's a Python script that prints 'Hello, World!' and the current time:\n\n```python\nimport datetime\n\ncurrent_time = datetime.datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\")\nprint(\"Hello, World!\")\nprint(\"Current Time:\", current_time)\n```\n\nJust copy and paste the code above into a Python file, save it, and run the file to see the output."
  }
]

Now it's a matter of just parsing the json file. I'm gonna ask it to write a python script to parse it and get the python script from it.

Oh wait. :/

@evilpan
Copy link
Owner

evilpan commented Mar 22, 2023

Hi! Now we can save/load from both JSON and Markdown file, using the following command:

.save [-m {json, md}] file
.load [-m {json, md}] file

And we use the md (markdown) format by default now.

See: 0777a45

@roperi
Copy link
Author

roperi commented Mar 22, 2023

Hi! Now we can save/load from both JSON and Markdown file, using the following command:

.save [-m {json, md}] file
.load [-m {json, md}] file

And we use the md (markdown) format by default now.

See: 0777a45

Ah, amazing! Now the tool is super useful. Thanks so much!

@evilpan evilpan closed this as completed Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants