kardolus/chatgpt-cli

Fallback to Default Config When OPENAI_CONFIG_HOME is Set and YAML Configuration is missing.

Closed this issue Β· 6 comments

When the environment variable OPENAI_CONFIG_HOME is set, and the corresponding YAML configuration file does not exist, the chatgpt-cli application falls back to its default configuration silently without throwing an error. This behavior can lead to confusion as users may expect an error to be raised when the specified configuration is not found.

I know this sounds silly, but out of habit, I name all my yaml files with the extension .yml. It took me more than an hour to realize that that was the problem. I decided to build, log and everything in order to find that it was my fault. In any case, since I'm biased, I think that if somebody sets the variable OPENAI_CONFIG_HOME, it's because he/she wishes to use that directory, and it should not fallback to the default configuration file.

Nice library btw.

Thank you! I'm wondering if it would make sense to just create the file for a user if it doesn't exist. Including any new keys that may be introduced in future versions.

Because right now the CLI works perfectly fine without the config file. But it is kinda error prone as you point out to leave this up to the user.

In my case, I set explicitly the environmental variable. I really think that an error code should be fine. Or as you mentioned, if you create the file, maybe you can put a warning. However, I strongly believe that if the person is trying to do that, it's because he/she knows what he/she's doing.
In a side comment, I actually created another configuration because I wanted to pass another role. However, I strongly believe that if you have some kind of storage and select, it could be really nice. I can imagine even an extension to select the type of response you want, either specific to your user or generated some crowdsource (like: https://github.com/f/awesome-chatgpt-prompts/blob/main/prompts.csv). Again, in my case, I wanted with the variable, to play the role of a programmer, because most of the time I don't need the explanations in the code.
In any case, it's not my call, and unfortunately, I do not have the time to contribute to your code. Kudos again to you πŸ˜‰

@silgon That's fair. I will implement something. Printing a warning should be sufficient indeed.

Sorry, I have been busy rolling out other features. Including the prompt flag. You should give it a go! :)

git diff | ./bin/chatgpt -n -p ../prompts/write_pull-request.md

or

cat README.md | chatgpt -n --prompt ../prompts/summarize.md

More info here: https://github.com/kardolus/chatgpt-cli?tab=readme-ov-file#prompt-support

I implement something :)

See the test below:

 2024-10-12 08:13:53 ⌚ (☸️ |kind:N/A) Guillermos-MacBook-Pro in ~/workspace/chatgpt-cli
Β± |main {6} U:1 βœ—| β†’ mkdir -p /tmp/confighome

 2024-10-12 08:14:17 ⌚ (☸️ |kind:N/A) Guillermos-MacBook-Pro in ~/workspace/chatgpt-cli
Β± |main {6} U:1 βœ—| β†’ export OPENAI_CONFIG_HOME=/tmp/confighome

 2024-10-12 08:14:36 ⌚ (☸️ |kind:N/A) Guillermos-MacBook-Pro in ~/workspace/chatgpt-cli
Β± |main {6} U:1 βœ—| β†’ ./bin/chatgpt hi
Warning: config.yaml doesn't exist in /tmp/confighome, create it
Hello again! How can I assist you today?

 2024-10-12 08:14:42 ⌚ (☸️ |kind:N/A) Guillermos-MacBook-Pro in ~/workspace/chatgpt-cli
Β± |main {6} U:1 βœ—| β†’ unset OPENAI_CONFIG_HOME

 2024-10-12 08:14:55 ⌚ (☸️ |kind:N/A) Guillermos-MacBook-Pro in ~/workspace/chatgpt-cli
Β± |main {6} U:1 βœ—| β†’ ./bin/chatgpt hi
Hello! How can I assist you today?

 2024-10-12 08:14:59 ⌚ (☸️ |kind:N/A) Guillermos-MacBook-Pro in ~/workspace/chatgpt-cli
Β± |main {6} U:1 βœ—| β†’ export OPENAI_CONFIG_HOME=/tmp/confighome

 2024-10-12 08:15:07 ⌚ (☸️ |kind:N/A) Guillermos-MacBook-Pro in ~/workspace/chatgpt-cli
Β± |main {6} U:1 βœ—| β†’ touch /tmp/confighome/config.yaml

 2024-10-12 08:15:16 ⌚ (☸️ |kind:N/A) Guillermos-MacBook-Pro in ~/workspace/chatgpt-cli
Β± |main {6} U:1 βœ—| β†’ ./bin/chatgpt hi
Hello! How can I assist you today?

You can find the commit here: cc2c209

I expect to cut a new release somewhere within the next two weeks.

Nice. It's really nice work you are doing =). Concerning the prompt, I think it is really cool. I personally use a lot the pipe command to pass a context.
Thanks again! πŸŽ‰

You got it! Thank's for the kind words. Glad you are enjoying the CLI.