-
Notifications
You must be signed in to change notification settings - Fork 487
Fix API key loading logic to read directly from config file #386
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,10 @@ def __init__(self): | |
| try: | ||
| with open('config.json') as f: | ||
| config = json.load(f) | ||
| if not os.getenv(config['api_key']): | ||
| print(f'{config["api_key"]} environment variable not set.') | ||
| if not config['api_key']: | ||
| print('api_key configuration not set.') | ||
| sys.exit(1) | ||
| api_key = os.getenv(config['api_key']) | ||
| api_key = config['api_key'] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For enhanced security, it's a best practice to avoid storing secrets like API keys in plaintext configuration files, as they can be accidentally committed to version control. Consider loading the key directly from an environment variable instead (e.g., |
||
|
|
||
| self.model = ChatOpenAI( | ||
| model=config['model_name'] or 'gpt-4o', | ||
|
|
||
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.
The validation for
api_keyonly checks for an empty value. The defaultconfig.jsonuses"API_KEY"as a placeholder. It would be more robust to also check for this placeholder value to prevent runtime errors and provide a clearer message to the user if they haven't configured their key.