Educational demonstrations of Microsoft Foundry, Azure OpenAI, fine-tuning, Retrieval-Augmented Generation (RAG), tool calling, and lightweight RAG evaluation.
Important
This repository is for educational and demonstration purposes. It is not production-ready guidance. Running azd up, model inference, fine-tuning, Azure AI Search, Storage, and related Azure services can incur real charges in your subscription. Review the generated resources and current Azure pricing, then run azd down --force --purge when the environment is no longer needed.
0_concept_demo.py- Local fine-tuning and RAG concept walkthrough; no Azure required2c_rag_api_demo.py- Azure OpenAI On Your Data pattern with Azure AI Search3b_chat_client.py- Keyless Microsoft Foundry SDK chat client3c_chat_api_comparison.py- Chat Completions versus Responses API state handling4_comparison_demo.py- Base model, RAG, and fine-tuned-model comparison5_agentic_rag_tool_demo.py- Application-orchestrated RAG with tool calling6_rag_quality_eval_demo.py- Lightweight golden-set RAG quality checks
1a_fine_tuning_portal_guide.md- Portal-based fine-tuning walkthrough1b_fine_tuning_code_first.py- Programmatic fine-tuning implementation1_fine_tuning_demo.py- Legacy fine-tuning workflow example
2a_rag_portal_guide.md- Portal RAG wizard (UI-based)2b_rag_code_first.py- Manual RAG pipeline (full control)2d_rag_keyvault_demo.py- Key Vault-backed RAG configuration with.envfallback2_rag_pattern_demo.py- Legacy end-to-end RAG pattern example
- Azure Subscription with permissions to create resources
- Azure Developer CLI (
azd) - Install here - Azure CLI - Install here
- Python 3.10+
# 1. Login to Azure
az login
# 2. Deploy everything (8-12 minutes)
azd up
# 3. Create and activate the Python environment
python setup_venv.py
.\activate_env.ps1
# 4. Run the search setup and smoke tests
python setup_search_index.py
python 0_concept_demo.py
python 2c_rag_api_demo.py
python 3_chat_client_demo.py --once "What is Microsoft Foundry?"
python 4_comparison_demo.py --once "What is the refund policy for credit cards?"For manual configuration without azd, copy .env.example to .env, replace the placeholders, and run az login when using Microsoft Entra authentication. Never commit .env.
azd up creates:
- Microsoft Foundry (
AIServices) with GPT-4o andtext-embedding-ada-002deployments - Microsoft Foundry Project connected to the Foundry resource
- Azure AI Search (Basic tier) with a vector index
- Storage Account with the RAG source documents
- Azure Key Vault and required role assignments
- An auto-generated local
.envfile; OpenAI clients use Microsoft Entra ID when a usable API key is unavailable
The default location is swedencentral; supported locations are defined in infra/main.bicep. Availability, quota, and pricing vary by subscription and region.
# 1. Start with concepts (no Azure needed)
python 0_concept_demo.py
# 2. Create or refresh the search index
python setup_search_index.py
# 3. Show RAG in action
python 2c_rag_api_demo.py
# 4. Compare client-side and service-side conversation state
python 3c_chat_api_comparison.py
# 5. Compare base, RAG, and fine-tuned approaches
python 4_comparison_demo.py --once "What is the refund policy for credit cards?"
# 6. Demonstrate tool calling and evaluation
python 5_agentic_rag_tool_demo.py
python 6_rag_quality_eval_demo.py
# 7. Validate the fine-tuning workflow without starting a paid job
python 1b_fine_tuning_code_first.py --dry-run --initials demo2c_rag_api_demo.py runs two fixed banking questions. Use 5_agentic_rag_tool_demo.py --question "..." or 4_comparison_demo.py --once "..." for custom one-shot questions.
# Delete all Azure resources (saves money!)
azd down --force --purgeImportant: This removes all resources and stops billing. Re-run azd up before your next class.
ai3016/
βββ 0_concept_demo.py # Start here - no Azure needed
βββ 1b_fine_tuning_code_first.py # Code-first fine-tuning workflow
βββ 2b_rag_code_first.py # Manual retrieval and generation
βββ 2c_rag_api_demo.py # Azure OpenAI data_sources RAG
βββ 2d_rag_keyvault_demo.py # Key Vault configuration example
βββ 3_chat_client_demo.py # Interactive OpenAI SDK chat
βββ 3b_chat_client.py # Microsoft Foundry SDK chat
βββ 3c_chat_api_comparison.py # Chat Completions vs Responses
βββ 4_comparison_demo.py # Base vs RAG vs fine-tuning
βββ 5_agentic_rag_tool_demo.py # Tool-calling RAG workflow
βββ 6_rag_quality_eval_demo.py # RAG evaluation harness
βββ 1a_fine_tuning_portal_guide.md
βββ 2a_rag_portal_guide.md
βββ bank-dataset-generator.py # Generates training data
βββ setup_search_index.py # Builds and populates the search index
βββ azure_openai_auth.py # Shared key/Entra client helper
βββ azure.yaml # Azure Developer CLI config
βββ .env.example # Placeholder-only configuration reference
βββ infra/ # Infrastructure as Code
β βββ main.bicep # Main Bicep template
β βββ main.parameters.json # Deployment parameters
β βββ modules/ # Resource modules
β βββ hooks/ # Post-deployment scripts
βββ RAG-sources/ # Banking documents
β βββ bank_policies.txt
β βββ customer_service.txt
β βββ investment_products.txt
βββ activate_env.ps1/.sh/.bat # Environment activation
βββ requirements.txt # Python dependencies
βββ .env # Generated locally and ignored by Git
- Banking domain specialization
- Multi-turn conversation training
- 50 high-quality training examples
- Cost-optimized hyperparameters
- Real banking documents in
RAG-sources/ - Hybrid search (keyword + semantic)
- Source attribution and citations
- Production-oriented patterns presented as educational samples
- Keyless authentication with
DefaultAzureCredential - Chat Completions with application-managed history
- Responses API with
previous_response_id - Streaming and standard response modes in the OpenAI SDK client
# Full deployment
azd up
# View current environment
azd env get-values
# Check deployment status
azd monitor
# Complete teardown
azd down --force --purge- Provisions Azure resources using Bicep templates
- Deploys GPT-4o model to Microsoft Foundry
- Deploys text-embedding-ada-002 to the same Foundry resource
- Uploads RAG documents to storage
- Creates search index with vector embeddings
- Generates an ignored
.envfile with endpoints and available local credentials - Assigns RBAC permissions for seamless access
- Deploy only when needed:
azd upbefore class - Delete after class:
azd down --force --purge - Monitor costs: Use Azure Cost Management
- Estimate before deploying: Prices, quotas, and free grants change; use the Azure pricing calculator and your subscription's Cost Management view
| Issue | Solution |
|---|---|
| Module not found | Run .\activate_env.ps1 and pip install -r requirements.txt |
| Azure credentials | Run az login |
| .env missing | Re-run azd up or .\infra\hooks\postprovision.ps1 |
| Search index missing | Run python setup_search_index.py |
| Quota exceeded | Check model availability and quota in another supported region |
| RAG not working | Verify search index exists in Azure Portal |
- View deployment logs:
azd provision --debug - Verify environment:
azd env get-values - Rebuild the search index:
python setup_search_index.py
1a_fine_tuning_portal_guide.md- Portal fine-tuning walkthrough2a_rag_portal_guide.md- Portal RAG walkthroughTRAINING_DATA_GUIDE.md- Fine-tuning data format referenceprompt_engineering.md- Prompt-engineering examples
- Installed Azure Developer CLI (
azd) - Logged into Azure (
az login) - Ran
azd upsuccessfully - Verified
.envfile exists with embeddings config - Confirmed search index created (check Azure Portal)
- Activated Python environment
- Ran
python setup_search_index.py - Tested the selected demos
- Reviewed Azure Cost Management and planned cleanup
After completing the demos, you will understand:
- β Fine-tuning workflow and best practices
- β RAG architecture and implementation patterns
- β Azure AI services integration
- β Production deployment considerations
- β
Modern Azure developer workflows with
azd
Use these samples to learn and teach the patterns, then apply your organization's security, reliability, evaluation, and governance requirements before adapting them for production.