This guide explains how to properly configure the environment variables for the automated code update system.
-
Copy the template file:
cp env.template .env
-
Edit the
.envfile: Replace the placeholder values with your actual configuration:nano .env # or use your preferred editor
AZURE_OPENAI_API_KEY: Your Azure OpenAI API keyAZURE_OPENAI_ENDPOINT: Your Azure OpenAI endpoint URL
AZURE_OPENAI_API_VERSION: API version (default: 2024-02-01)AZURE_OPENAI_DEPLOYMENT_NAME: Deployment name (default: gpt-4o)
OPENAI_API_KEY: Your OpenAI API key (for backward compatibility)OPENAI_MODEL: OpenAI model to use (default: gpt-4)REGION: Azure region (default: swedencentral)
-
Never commit
.envfiles to version control- The
.envfile is already in.gitignore - Double-check with:
git status(should not show.env)
- The
-
Use different
.envfiles for different environments:.env.development.env.staging.env.production
-
Rotate API keys regularly
- Update your Azure OpenAI keys periodically
- Test the new keys before deploying
The application automatically validates required environment variables on startup. If any required variables are missing, you'll see specific error messages indicating which variables need to be set.
Run the validation manually:
from config import Config
errors = Config.validate_config()
if errors:
for error in errors:
print(f"Error: {error}")
else:
print("Configuration is valid!")Your .env file should look like this:
# Azure OpenAI Configuration
AZURE_OPENAI_API_KEY=your_actual_api_key_here
AZURE_OPENAI_ENDPOINT=https://your-endpoint.openai.azure.com/
# Optional configurations...
AI_MAX_TOKENS=4000
AI_TEMPERATURE=0.1- Import Error: Make sure you've activated your virtual environment
- Missing Variables: Check that all required variables are set in your
.envfile - Permission Issues: Ensure the
.envfile has appropriate read permissions
For Azure Functions, set environment variables in the Azure portal:
- Go to your Function App
- Navigate to Configuration > Application settings
- Add each environment variable manually
- Don't forget to save and restart the function app