marcolardera / chatgpt-cli

Simple yet effective command line client for chatting with ChatGPT using the official API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Auto create config folder and yaml during installation

marcolardera opened this issue · comments

At the moment the config file template is created during the first execution of the script.

It would be a better UX if automatically created when the user pip install the package.

pyproject.toml and setup.cfg do not support data files written outside project directory. A bare bones setup.py. Is there a reason not to keep the config file used located within the package directory instead of writing to ~/.config?

The docs say that the template is automatically created, but I did not see this occur:

ttop@tsudio chatgpt-cli % echo $XDG_CONFIG_HOME
~/.config
ttop@tsudio chatgpt-cli % chatgpt-cli              
ChatGPT CLI                                                                            
Configuration file not found                                                           
ttop@tsudio chatgpt-cli % ls -al ~/.config 
total 0
drwxr-xr-x   4 ttop  staff   128 Jun 25  2022 .
drwxr-x---+ 52 ttop  staff  1664 Dec  2 16:52 ..
drwxr-xr-x   5 ttop  staff   160 Jul  3 10:42 MusicBrainz
drwxr-xr-x   4 ttop  staff   128 Feb 25  2023 qBittorrent
ttop@tsudio chatgpt-cli % 

Okay, interesting… when I just ran chatgpt.py in a VS code debugger, the directory and config file were created as expected. I erased the directory and config file and ran chatgpt-cli directly and again it failed Configuration file not found . So it seems like something about running it via the script is making it fail.

I think the issue is this:

    if not Path(config_file).exists():
        with open(config_file, "w") as file:

the directory doesn't exist, so the open() throws an exception.

Oh ha, I went to fix this and realized it had been fixed since my last pull.