Skip to content

Commit ed91962

Browse files
Merge pull request #169 from microsoft/tech-connect-sql
chore: API, APP & doc changes
2 parents ff38401 + ea01ca8 commit ed91962

File tree

11 files changed

+317
-40
lines changed

11 files changed

+317
-40
lines changed

azure.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ hooks:
2323
if ($isWorkshop -eq "true") {
2424
Write-Host "`n=== Run each command one at a time, waiting for completion before proceeding ===" -ForegroundColor Yellow
2525
Write-Host "`n1. Setup Python environment:"
26-
Write-Host " cd scripts" -ForegroundColor Cyan
2726
Write-Host " python -m venv .venv" -ForegroundColor Cyan
2827
Write-Host " .venv\Scripts\activate" -ForegroundColor Cyan
29-
Write-Host " pip install uv && uv pip install -r requirements.txt" -ForegroundColor Cyan
28+
Write-Host " pip install uv && uv pip install -r scripts/requirements.txt" -ForegroundColor Cyan
3029
3130
Write-Host "`n2. Build solution (data processing and agent creation):"
3231
Write-Host " python scripts/00_build_solution.py --from 02" -ForegroundColor Cyan
@@ -55,10 +54,9 @@ hooks:
5554
echo "=== Run each command one at a time, waiting for completion before proceeding ==="
5655
echo ""
5756
echo "1. Setup Python environment:"
58-
echo " cd scripts"
5957
echo " python -m venv .venv"
6058
echo " source .venv/bin/activate"
61-
echo " pip install uv && uv pip install -r requirements.txt"
59+
echo " pip install uv && uv pip install -r scripts/requirements.txt"
6260
6361
echo ""
6462
echo "2. Build solution (data processing and agent creation):"

data/default/config/agent_ids.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
"_comment": "This file is populated when you run 07_create_foundry_agent.py",
33
"chat_agent_id": null,
44
"chat_agent_name": null,
5-
"title_agent_id": null,
6-
"title_agent_name": null,
75
"search_index": null
86
}

scripts/00_build_solution.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
Master script that runs all steps to build the complete solution.
44
55
Usage:
6-
# Full Fabric mode (uses Fabric Lakehouse + AI Search)
6+
# Run all steps from the beginning (uses either Fabric Lakehouse or Azure SQL + AI Search)
77
python scripts/00_build_solution.py
8-
9-
# Azure-only mode (uses Azure SQL + AI Search, no Fabric required)
10-
python scripts/00_build_solution.py --azure-only
118
129
# Start from a specific step
1310
python scripts/00_build_solution.py --from 06
1411
15-
Steps (Full mode):
12+
Steps (Fabric SQL mode):
1613
01 - Generate sample data
1714
02 - Create Fabric Lakehouse
1815
03 - Load data into Fabric
@@ -66,15 +63,11 @@
6663
formatter_class=argparse.RawDescriptionHelpFormatter,
6764
epilog="""
6865
Examples:
69-
python scripts/00_build_solution.py # Full Fabric mode
70-
python scripts/00_build_solution.py --azure-only # Azure SQL mode (no Fabric)
66+
python scripts/00_build_solution.py # Full Fabric mode or SQL mode
7167
python scripts/00_build_solution.py --from 06 # Start from step 06
7268
python scripts/00_build_solution.py --only 07 # Run only specific steps
7369
"""
7470
)
75-
76-
parser.add_argument("--azure-only", action="store_true",
77-
help="Use Azure SQL instead of Fabric Lakehouse")
7871
parser.add_argument("--industry", type=str,
7972
help="Industry for data generation (overrides .env)")
8073
parser.add_argument("--usecase", type=str,
@@ -101,13 +94,20 @@
10194
# Quiet mode is default (verbose must be explicitly requested)
10295
args.quiet = not args.verbose
10396

97+
# Load environment from azd + project .env
98+
from load_env import load_all_env
99+
load_all_env()
100+
101+
# Get azure_only from environment variable (set AZURE_ENV_ONLY=true to use Azure SQL mode)
102+
azure_only = os.getenv("AZURE_ENV_ONLY", "false").lower() in ("true", "1", "yes")
103+
104104
# ============================================================================
105105
# Determine Pipeline
106106
# ============================================================================
107107

108108
if args.only:
109109
pipeline = args.only
110-
elif args.azure_only:
110+
elif azure_only:
111111
pipeline = AZURE_ONLY_PIPELINE.copy()
112112
else:
113113
pipeline = FABRIC_PIPELINE.copy()
@@ -135,10 +135,6 @@
135135
print(f"ERROR: Script not found: {STEPS[step]['script']}")
136136
sys.exit(1)
137137

138-
# Load environment from azd + project .env
139-
from load_env import load_all_env
140-
load_all_env()
141-
142138
# ============================================================================
143139
# Interactive Prompts for Data Generation
144140
# ============================================================================
@@ -180,7 +176,7 @@
180176
# Print Plan
181177
# ============================================================================
182178

183-
mode = "Azure SQL" if args.azure_only else "Fabric"
179+
mode = "Azure SQL" if azure_only else "Fabric"
184180
print("\n" + "="*60)
185181
print(f"Build Solution Pipeline ({mode} Mode)")
186182
print("="*60)
@@ -231,7 +227,7 @@ def run_step(step_id):
231227
if step_id == "02" and args.clean:
232228
cmd.append("--clean")
233229

234-
if step_id == "07" and args.azure_only:
230+
if step_id == "07" and azure_only:
235231
cmd.append("--azure-only")
236232

237233
# Run the script

scripts/03_load_fabric_data.py

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,77 @@ def wait_for_lro(operation_url, operation_name="Operation", timeout=300):
239239
print(" Waiting for tables to be indexed...")
240240
time.sleep(30)
241241

242+
# ============================================================================
243+
# Step 4: Get Fabric SQL Endpoint and Update App Service
244+
# ============================================================================
245+
246+
print(f"\n[4/4] Getting Fabric SQL endpoint...")
247+
248+
def get_fabric_sql_endpoint():
249+
"""Get the SQL analytics endpoint for the Fabric Lakehouse"""
250+
try:
251+
url = f"{FABRIC_API}/workspaces/{WORKSPACE_ID}/lakehouses/{LAKEHOUSE_ID}"
252+
resp = make_request("GET", url)
253+
if resp.status_code == 200:
254+
data = resp.json()
255+
props = data.get("properties", {})
256+
sql_props = props.get("sqlEndpointProperties", {})
257+
return sql_props.get("connectionString")
258+
except Exception as e:
259+
print(f" [WARN] Could not get Fabric SQL endpoint: {e}")
260+
return None
261+
262+
FABRIC_SQL_ENDPOINT = get_fabric_sql_endpoint()
263+
264+
if FABRIC_SQL_ENDPOINT:
265+
print(f" [OK] SQL Endpoint: {FABRIC_SQL_ENDPOINT}")
266+
267+
# Save to fabric_ids.json
268+
fabric_ids["sql_endpoint"] = FABRIC_SQL_ENDPOINT
269+
with open(fabric_ids_path, "w") as f:
270+
json.dump(fabric_ids, f, indent=2)
271+
272+
# Update App Service env vars
273+
subscription_id = os.getenv("AZURE_SUBSCRIPTION_ID")
274+
resource_group = os.getenv("RESOURCE_GROUP_NAME")
275+
app_name = os.getenv("API_APP_NAME")
276+
277+
if subscription_id and resource_group and app_name:
278+
try:
279+
from azure.mgmt.web import WebSiteManagementClient
280+
from azure.identity import DefaultAzureCredential
281+
282+
web_credential = DefaultAzureCredential()
283+
web_client = WebSiteManagementClient(web_credential, subscription_id)
284+
285+
current = web_client.web_apps.list_application_settings(resource_group, app_name)
286+
props = dict(current.properties or {})
287+
288+
# Build full ODBC connection string
289+
if FABRIC_SQL_ENDPOINT:
290+
fabric_conn_string = f"DRIVER={{ODBC Driver 18 for SQL Server}};SERVER={FABRIC_SQL_ENDPOINT};DATABASE={LAKEHOUSE_NAME};Encrypt=yes;TrustServerCertificate=no"
291+
else:
292+
fabric_conn_string = ""
293+
294+
new_settings = {
295+
"FABRIC_SQL_CONNECTION_STRING": fabric_conn_string
296+
}
297+
props.update(new_settings)
298+
299+
web_client.web_apps.update_application_settings(
300+
resource_group,
301+
app_name,
302+
{"properties": props}
303+
)
304+
305+
print(f" [OK] App Service settings updated")
306+
except Exception as e:
307+
print(f" [WARN] Failed to update App Service: {e}")
308+
else:
309+
if FABRIC_SQL_ENDPOINT:
310+
fabric_conn_string = f"DRIVER={{ODBC Driver 18 for SQL Server}};SERVER={FABRIC_SQL_ENDPOINT};DATABASE={LAKEHOUSE_NAME};Encrypt=yes;TrustServerCertificate=no"
311+
print(f" NOTE: Set FABRIC_SQL_CONNECTION_STRING={fabric_conn_string} in App Service")
312+
242313
# ============================================================================
243314
# Summary
244315
# ============================================================================
@@ -249,13 +320,10 @@ def wait_for_lro(operation_url, operation_name="Operation", timeout=300):
249320
print(f"""
250321
Uploaded {len(uploaded_files)} files: {', '.join(uploaded_files)}
251322
Tables loaded: {', '.join(ontology_config['tables'].keys())}
323+
SQL Endpoint: {FABRIC_SQL_ENDPOINT or 'Not available yet'}
252324
253325
Next step - Generate schema prompt:
254326
python scripts/04_generate_agent_prompt.py
255-
256-
To reload data later (e.g., with new/larger dataset):
257-
python scripts/01_generate_sample_data.py --scenario <SCENARIO> --size medium
258-
python scripts/03_load_fabric_data.py
259327
""")
260328

261329

scripts/07_create_agent.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,14 @@ def build_agent_instructions(config, schema_text, use_fabric, config_dir):
367367
print(f" Agent Name: {chat_agent.name}")
368368

369369
# Delete existing title agent if it exists
370-
print(f"\nChecking if title agent '{TITLE_AGENT_NAME}' already exists...")
371370
try:
372371
existing_title_agent = project_client.agents.get(TITLE_AGENT_NAME)
373372
if existing_title_agent:
374-
print(f" Found existing title agent, deleting...")
375373
project_client.agents.delete(TITLE_AGENT_NAME)
376-
print(f"[OK] Deleted existing title agent")
377374
except Exception:
378-
print(f" No existing title agent found")
375+
pass
379376

380377
# Create title agent
381-
print(f"\nCreating title agent...")
382378
title_agent_definition = PromptAgentDefinition(
383379
model=MODEL,
384380
instructions=title_agent_instructions,
@@ -391,8 +387,6 @@ def build_agent_instructions(config, schema_text, use_fabric, config_dir):
391387
)
392388

393389
print(f"\n[OK] Title agent created successfully!")
394-
print(f" Title Agent ID: {title_agent.id}")
395-
print(f" Title Agent Name: {title_agent.name}")
396390

397391
except Exception as e:
398392
print(f"\n[FAIL] Failed to create agent: {e}")
@@ -413,8 +407,6 @@ def build_agent_instructions(config, schema_text, use_fabric, config_dir):
413407
# Save agent-specific info
414408
agent_ids["chat_agent_id"] = chat_agent.id
415409
agent_ids["chat_agent_name"] = chat_agent.name
416-
agent_ids["title_agent_id"] = title_agent.id
417-
agent_ids["title_agent_name"] = title_agent.name
418410
agent_ids["search_index"] = INDEX_NAME
419411
agent_ids["sql_mode"] = "fabric" if USE_FABRIC else "azure_sql"
420412
if not USE_FABRIC:

scripts/deployment_guide.pdf

1.7 KB
Binary file not shown.

scripts/generate_deployment_guide.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,15 @@ def create_guide():
123123

124124
pdf.step(5, 'Build the solution (~5 min)',
125125
'python scripts/00_build_solution.py --from 02',
126-
'No Fabric? Use: python scripts/00_build_solution.py --from 04 --azure-only')
126+
'No Fabric? Use: python scripts/00_build_solution.py --from 04')
127127

128128
pdf.step(6, 'Test the agent',
129129
'python scripts/08_test_agent.py')
130130

131+
pdf.step(7, 'Deploy and launch the application',
132+
'azd env set AZURE_ENV_DEPLOY_APP true\nazd up',
133+
'After deployment completes, open the app URL shown in the output')
134+
131135
# Sample Questions
132136
pdf.section_header('Try These Questions')
133137
pdf.info_text('Structured: "How many outages occurred last month?" | "What is the average resolution time?"')

scripts/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pypdf==5.6.0
2727
azure-search-documents==11.6.0
2828

2929
# Azure SQL Management
30-
azure-mgmt.-web==7.3.1
30+
azure-mgmt-web==7.3.1
3131

3232
# OpenAI SDK (for embeddings)
3333
openai==2.8.1

0 commit comments

Comments
 (0)