-
Notifications
You must be signed in to change notification settings - Fork 30
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
fix: exit the goose and show the error message when provider environment variable is not set #103
fix: exit the goose and show the error message when provider environment variable is not set #103
Conversation
@@ -87,11 +87,6 @@ def default_model_configuration() -> Tuple[str, str, str]: | |||
break | |||
except Exception: | |||
pass | |||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need this message. The error message (env var is not set) will be thrown when the provider is loaded while creating the session.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so in this case, the provider value that is returned below will be whatever is last in the list of providers, and then be used to set the default profile. It will later error like you say.
Should we do
else:
provider = RECOMMENDED_DEFAULT
so that we don't set it to something niche?
tests/cli/test_session.py
Outdated
def test_create_exchange_exit_when_env_var_does_not_exist(create_session_with_mock_configs, mock_sessions_path): | ||
session = create_session_with_mock_configs() | ||
expected_error = MissingProviderEnvVariableError(env_variable="OPENAI_API_KEY", provider="openai") | ||
with patch("goose.cli.session.build_exchange", side_effect=expected_error), patch( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:nit: we can make this easier to read by forcing ruff format
to newline with trailing command and parenthesis
with (
patch("goose.cli.session.build_exchange", side_effect=expected_error),
patch("goose.cli.session.print") as mock_print,
patch("sys.exit") as mock_exit,
):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I prefer the separated lines too. However, I had a look, it seems that ruff format is unable to do it as it only supports some light formatting rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, sorry I missed the extra brackets. I've updated and it works now!
…ey-not-specified * main: chore: setup workspace for exchange (#105)
…ovider/moderator is unknown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Much clearer
from typing import List | ||
|
||
|
||
class LoadExchangeAttributeError(Exception): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe InvalidChoice
@@ -43,3 +29,7 @@ def from_env(cls: Type["AzureProvider"]) -> "AzureProvider": | |||
timeout=httpx.Timeout(60 * 10), | |||
) | |||
return cls(client) | |||
|
|||
@classmethod | |||
def _get_env_variable(cls: Type["AzureProvider"], key: str) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: i'd just call the helper directly instead of adding the new method?
@@ -326,3 +322,7 @@ def tools_to_bedrock_spec(tools: Tuple[Tool]) -> Optional[dict]: | |||
tools_added.add(tool.name) | |||
tool_config = {"tools": tool_config_list} | |||
return tool_config | |||
|
|||
@classmethod | |||
def _get_env_variable(cls: Type["BedrockProvider"], key: str) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: same comment as above
@@ -87,11 +87,6 @@ def default_model_configuration() -> Tuple[str, str, str]: | |||
break | |||
except Exception: | |||
pass | |||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so in this case, the provider value that is returned below will be whatever is last in the list of providers, and then be used to set the default profile. It will later error like you say.
Should we do
else:
provider = RECOMMENDED_DEFAULT
so that we don't set it to something niche?
* main: fix: exit the goose and show the error message when provider environment variable is not set (#103) fix: Update OpenAI pricing per https://openai.com/api/pricing/ (#110) fix: update developer tool prompts to use plan task status to match allowable statuses update_plan tool call (#107) fix: removed the panel in the output so that the user won't have unnecessary pane borders in the copied content (#109) docs: update links to exchange to the new location (#108) chore: setup workspace for exchange (#105)
…ent variable is not set (#103)
* main: (41 commits) chore: Add goose providers list command (#116) docs: working ollama for desktop (#125) docs: format and clean up warnings/errors (#120) docs: update deploy workflow (#124) feat: Implement a goose run command (#121) feat: saved api_key to keychain for user (#104) docs: add callout plugin (#119) chore: add a page to docs for Goose application examples (#117) fix: exit the goose and show the error message when provider environment variable is not set (#103) fix: Update OpenAI pricing per https://openai.com/api/pricing/ (#110) fix: update developer tool prompts to use plan task status to match allowable statuses update_plan tool call (#107) fix: removed the panel in the output so that the user won't have unnecessary pane borders in the copied content (#109) docs: update links to exchange to the new location (#108) chore: setup workspace for exchange (#105) fix: resolve uvx when using a git client or IDE (#98) ci: add include-markdown for mkdocs (#100) chore: fix broken badge on readme (#102) feat: add global optional user goosehints file (#73) docs: update docs (#99) chore(release): release 0.9.3 (#97) ...
Why
Currently it throws a runtime error and print the stack trace when
This make it hard for users to understand what is going.
What
Exchange
provider
,env_variable
. When providers fetch the environment variable for api key, it will raise this error if the environment variable is not availableWith the above custom erross we can construct user friendly messages in goose
goose
screenshots
Please give feedback including the content and presentation of these error message. Thank you!