This application is a Flask-based web service that integrates with Azure OpenAI to provide AI consulting services. It offers expert guidance on Azure architecture, cost optimization, security, and best practices.
- Prerequisites
- Project Structure
- Configuration
- Local Development
- Deployment
- CI/CD Pipeline
- Monitoring and Maintenance
- Troubleshooting
- Python 3.10 or higher
- Azure subscription
- Azure OpenAI service instance
- GitHub account
- Azure Web App Service
AzureSmartBot/
├── .github/
│ └── workflows/
│ └── main_webappservice.yml
├── templates/
│ └── index.html
├── .env.example
├── .gitignore
├── app.py
├── requirements.txt
└── README.md
Create a .env file for local development:
AZURE_OPENAI_ENDPOINT=your_azure_openai_endpoint
AZURE_OPENAI_API_KEY=your_azure_openai_api_key
AZURE_OPENAI_DEPLOYMENT_NAME=your_deployment_name
PORT=8000Add these settings in Azure Portal > App Service > Configuration > Application settings:
AZURE_OPENAI_ENDPOINTAZURE_OPENAI_API_KEYAZURE_OPENAI_DEPLOYMENT_NAMEWEBSITES_CONTAINER_START_TIME_LIMIT=600PORT=8000
- Clone the repository:
git clone https://github.com/Curious4Tech/AzureSmartBot.git
cd AzureSmartBot- Create and activate virtual environment:
python -m venv venv
source venv/bin/activate # For Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env with your values- Run the application:
python app.pyThe application will be available at http://localhost:8000
- Create an Azure Web App Service
- Configure application settings in Azure Portal
- Deploy using VS Code Azure Tools or Azure CLI
Set in Azure Portal > Configuration > General settings:
gunicorn --workers=2 --timeout=120 --access-logfile="-" --error-logfile="-" --bind=0.0.0.0:8000 app:appUse the azure portal to configure it by authenticating to your github account and choosing your repo, then Azure will provide a default workflow that will is enough for this demo but you can also costumize your workflows.
-
In Azure Portal:
- Go to your Web App
- Download publish profile
- Copy the content
-
In GitHub:
- Go to repository settings
- Add new secret
AZURE_WEBAPP_PUBLISH_PROFILE - Paste the publish profile content
-
Update workflow file:
- Replace
your-webapp-namewith your actual Azure Web App name
- Replace
The application includes a health check endpoint at /health that verifies:
- Application status
- Azure OpenAI connection
- Application logs available in Azure Portal
- Structured logging format:
%(asctime)s - %(name)s - %(levelname)s - %(message)s
- Enable Application Insights in Azure Portal
- Monitor:
- Response times
- Failed requests
- Server errors
- Container logs
- Container Startup Issues:
Solution: Check startup command and environment variables in Azure Portal
- OpenAI Client Errors:
Solution: Verify Azure OpenAI credentials and endpoint configuration
- Connection Timeouts:
Solution: Adjust timeout settings in startup command or check network configuration
Main application file containing:
- Flask application setup
- Azure OpenAI client initialization
- API endpoints
- Error handling
# Key components
- Flask application initialization
- Azure OpenAI client setup
- System message configuration
- API endpoints for chat and health checkflask>=2.0.0
python-dotenv>=1.0.0
openai>=1.0.0
gunicorn>=20.1.0
httpx>=0.24.0
-
Environment Variables:
- Never commit sensitive data
- Use Azure Key Vault for production secrets
-
API Security:
- Rate limiting implemented
- Input validation on all endpoints
- Error handling to prevent information disclosure
-
Deployment Security:
- HTTPS enabled
- Secure configuration in Azure App Service
For issues or questions:
- Check Azure App Service logs
- Review GitHub Actions workflow runs
- Contact system administrator
