You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I try running GPTcmd without defining the Open AI API key first, I get the following error.
➜ ~ gptcmd
Traceback (most recent call last):
File "/opt/homebrew/bin/gptcmd", line 8, in <module>
sys.exit(main())
^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/gptcmd/cli.py", line 1273, in main
shell = Gptcmd(config=config)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/gptcmd/cli.py", line 73, in __init__
self.config = config or ConfigManager.from_toml()
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/gptcmd/config.py", line 136, in from_toml
return cls(tomllib.load(fin))
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/gptcmd/config.py", line 81, in __init__
self.accounts = self._configure_accounts(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/gptcmd/config.py", line 153, in _configure_accounts
res[name] = Account(name=name, provider=provider.from_config(conf))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/gptcmd/llm/openai.py", line 47, in from_config
client = openai.OpenAI(**client_opts)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/openai/_client.py", line 105, in __init__
raise OpenAIError(
openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
, in __init__
self.config = config or ConfigManager.from_toml()
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/gptcmd/config.py", line 136, in from_toml
return cls(tomllib.load(fin))
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/gptcmd/config.py", line 81, in __init__
self.accounts = self._configure_accounts(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/gptcmd/config.py", line 153, in _configure_accounts
res[name] = Account(name=name, provider=provider.from_config(conf))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/gptcmd/llm/openai.py", line 47, in from_config
client = openai.OpenAI(**client_opts)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/openai/_client.py", line 105, in __init__
raise OpenAIError(
openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
The text was updated successfully, but these errors were encountered:
This is expected behaviour, though granted the error could be much clearer. I think it makes sense to (either or both):
Catch OpenAIError when initializing a client in gptcmd.llm.OpenAI.from_config and raise a ConfigError from it, which would hide the traceback. Potentially write a Gptcmd-specific message (though I think the default exception message is probably fine).
When starting Gptcmd, if the config can't be read (i.e. if ConfigError is raised when instantiating a ConfigManager), prompt the user whether they'd like to edit their config. If so, use a default editor since we can't read the user's choice from their config (which, in practice, means either whatever is defined in the EDITOR environment variable or a platform-specific best guess).
If I try running GPTcmd without defining the Open AI API key first, I get the following error.
The text was updated successfully, but these errors were encountered: