You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update setup script and skills for Azure AI Content Understanding (#46512)
* Add setup script and GitHub Copilot skills for Azure AI Content Understanding SDK
- Created setup_user_env.sh for environment setup, including virtual environment creation, SDK installation, and .env configuration.
- Added sdk-common-knowledge skill for domain knowledge reference on Content Understanding concepts and SDK usage.
- Introduced sdk-py-sample-run skill to guide users in running specific samples interactively.
- Implemented run_sample.sh script to facilitate running sync and async samples with user prompts and error handling.
- Updated README.md to include information about new skills and usage instructions for GitHub Copilot.
* Update REST API Reference link in SKILL.md
* Rename skill from sdk-py-setup to cu-sdk-setup and update script path in SKILL.md
* Update SKILL.md and run_sample.sh to reference cu-sdk-setup instead of sdk-py-setup
* Update SKILL.md files to enhance clarity and detail for SDK setup and usage
Co-authored-by: Copilot <copilot@github.com>
* Update SKILL.md to remove outdated sections and add related skills for improved guidance
Co-authored-by: Copilot <copilot@github.com>
* Add SKILL.md files for cu-sdk-common-knowledge and cu-sdk-py-sample-run with detailed guidance and sample execution instructions
Co-authored-by: Copilot <copilot@github.com>
* Update skill references in README.md for consistency and clarity
* Add cu-sdk-sample-run skill and update related documentation
- Introduced `cu-sdk-sample-run` skill to guide users in running specific samples interactively.
- Updated `SKILL.md` for `cu-sdk-common-knowledge` and `cu-sdk-setup` to include references to the new skill.
- Corrected skill name in README and adjusted example prompts accordingly.
Co-authored-by: Copilot <copilot@github.com>
* Enhance setup scripts for Azure AI Content Understanding SDK with Python version checks and model deployment probing
Co-authored-by: Copilot <copilot@github.com>
* Enhance Python environment setup guidance for Windows users in SKILL.md and setup_user_env.ps1
Co-authored-by: Copilot <copilot@github.com>
* Enhance Python installation prompts and dependency checks in setup scripts for Azure AI Content Understanding SDK
Co-authored-by: Copilot <copilot@github.com>
* Soften runtime wording for sample_analyze_url.py per PR feedback
* Add inline cspell:ignore directive in setup_user_env.sh for pyver/esac
---------
Co-authored-by: Changjian Wang <v-changjwang@microsoft.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: aluneth <wangchangjian1130@163.com>
@@ -17,11 +17,55 @@ Before starting, ensure you have:
17
17
- An **Azure subscription** ([create one for free](https://azure.microsoft.com/free/))
18
18
- A **Microsoft Foundry resource** in a [supported region](https://learn.microsoft.com/azure/ai-services/content-understanding/language-region-support)
19
19
20
+
> **[COPILOT] Probe Python runtime first (before asking):**
21
+
> Do not take the user's word for it — run these checks, then report. This prevents silent failures later in `python -m venv`.
>|`Python 3.9+` and `venv: ok` and `pip` present | ✓ Good to go. Proceed to Step 1. |
42
+
>| Python missing or `< 3.9`| Report the finding, then go to the **[ASK USER] Python install choice** block below. |
43
+
>|`venv: MISSING` (common on Debian/Ubuntu base images) | Report the finding, then go to the **[ASK USER] Python install choice** block below. |
44
+
>| Windows resolves to a `WindowsApps\python*.exe` stub | Report the finding, then go to the **[ASK USER] Python install choice** block below (auto-install cannot fix this — user must disable App Execution Aliases). |
45
+
>
46
+
>**[ASK USER] Python install choice (only when probe fails):**
47
+
> Ask the user: "Python is missing / too old / the `venv` module is unavailable. How would you like to proceed?"
48
+
> - **Option A: Install it for me** — Agent runs the platform-appropriate install command (see below), verifies, and continues. Requires elevated privileges on Linux (`sudo`). Not available for the Windows App Execution Alias case — that requires manual UI action.
49
+
> - **Option B: I'll install it myself** — Agent prints the install command for the user's platform and stops. User runs it, re-opens the terminal, and tells the agent to resume.
50
+
>
51
+
>**Default install commands (Option A):**
52
+
> - **macOS** → `brew install python@3.12` (requires Homebrew;if not installed, fall back to Option B)
> - **Windows** → `winget install Python.Python.3.12` (run in an elevated PowerShell if needed)
56
+
>
57
+
>**Before running Option A, confirm with the user one more time** by restating the exact command that will execute, then proceed. After install, re-run the probe to verify `Python 3.9+` and `venv: ok` before continuing.
58
+
>
59
+
>**Windows gotcha — App Execution Aliases:** Even after uninstalling the Store Python stub, the `python.exe` / `python3.exe` entries under `C:\Users\<you>\AppData\Local\Microsoft\WindowsApps\` may persist as **App Execution Aliases** and shadow a real install. If the probe still reports a stub after the user confirms they installed real Python:
60
+
> 1. Point them to **Settings → Apps → Advanced app settings → App execution aliases**, and toggle **off**`python.exe` and `python3.exe`.
61
+
> 2. As a fallback, suggest invoking Python via the `py` launcher (`py -3 -m venv .venv`) or the explicit install path (e.g. `%LOCALAPPDATA%\Programs\Python\Python312\python.exe`). The companion `setup_user_env.ps1` script already probes well-known install paths automatically.
62
+
>
63
+
> Report the detected version + venv status back to the user in one sentence before the `[ASK USER]` block below.
64
+
20
65
>**[ASK USER] Prerequisites Check:**
21
-
> Before proceeding, ask the user to confirm their prerequisites:
22
-
> 1. "Do you have **Python 3.9+** installed?" — If no, guide them to install Python first.
23
-
> 2. "Do you already have a **Microsoft Foundry resource** set up in Azure?" — If no, jump to **Step 5** (Azure Resource Setup) first, then return here.
24
-
> 3. "Have you already deployed the required **AI models** (GPT-4.1, GPT-4.1-mini, text-embedding-3-large) in Microsoft Foundry?" — If no, include Step 5.3 and Step 6 in the workflow.
66
+
> After the probe above, confirm the remaining items:
67
+
> 1. "Do you already have a **Microsoft Foundry resource** set up in Azure?" — If no, jump to **Step 5** (Azure Resource Setup) first, thenreturn here.
68
+
> 2. "Have you already deployed the required **AI models** (GPT-4.1, GPT-4.1-mini, text-embedding-3-large) in Microsoft Foundry?" — If no, include Step 5.3 and Step 6 in the workflow.
25
69
26
70
## Package Directory
27
71
@@ -59,6 +103,9 @@ else
59
103
fi
60
104
```
61
105
106
+
>**[COPILOT] Existing `.venv` behavior:**
107
+
> If `.venv` already exists, prefer reusing it. If the existing virtual environment was created with a different Python minor version than the interpreter selected in the prerequisite probe, or if the environment is incomplete/corrupted, recreate `.venv` before continuing. This avoids subtle failures when the machine later upgrades from one supported Python version to another (for example, 3.9 → 3.12).
108
+
62
109
**Activate virtual environment:**
63
110
64
111
| Platform | Command |
@@ -97,6 +144,9 @@ pip install -e .
97
144
pip install -r dev_requirements.txt
98
145
```
99
146
147
+
>**[COPILOT] Repeated-run behavior:**
148
+
> On repeated runs, if the required SDK/sample dependencies are already importable from the active virtual environment, the setup scripts may skip the `pip install` step instead of reinstalling everything. Only rerun the install commands when dependencies are missing or the virtual environment was recreated.
149
+
100
150
This also installs all dependencies needed to run samples:
101
151
- `aiohttp` - Required for async operations
102
152
- `python-dotenv` - For loading `.env` files
@@ -167,13 +217,55 @@ Open `.env` in your editor and set the following **required** variables:
167
217
168
218
**For running `sample_update_defaults.py` (one-time model configuration):**
169
219
170
-
> **[ASK USER] Model deployment names:**
171
-
> Ask the user: "Do you want to configure **model deployment names** now? These are needed for `sample_update_defaults.py` (one-time setup)."
172
-
> - If yes, ask for each deployment name one by one with sensible defaults:
220
+
>**[COPILOT] Probe existing model defaults on the Foundry resource:**
221
+
> Before asking the user fordeployment names, probe what the resource already has configured. The venv is active and the SDK is installed, so call `get_defaults()` via a short inline Python snippet. Export `CONTENTUNDERSTANDING_ENDPOINT` (and `CONTENTUNDERSTANDING_KEY` if Option A)in the shell first so the snippet can read them.
222
+
>
223
+
>```bash
224
+
> python - <<'PY'
225
+
> import os, sys
226
+
> from azure.ai.contentunderstanding import ContentUnderstandingClient
227
+
> from azure.core.credentials import AzureKeyCredential
228
+
> from azure.identity import DefaultAzureCredential
229
+
> from azure.core.exceptions import HttpResponseError, ClientAuthenticationError
230
+
>
231
+
> ep = os.environ["CONTENTUNDERSTANDING_ENDPOINT"]
232
+
> key = os.environ.get("CONTENTUNDERSTANDING_KEY") or None
233
+
> cred = AzureKeyCredential(key) if key else DefaultAzureCredential()
234
+
> try:
235
+
> d = ContentUnderstandingClient(ep, cred).get_defaults().model_deployments or {}
236
+
> except ClientAuthenticationError:
237
+
> sys.exit(3)
238
+
> except HttpResponseError as e:
239
+
> sys.exit(3 if e.status_code in (401, 403) else 1)
> print(";".join(f"{k}={v}" for k, v in zip(keys, vals)))
246
+
> sys.exit(0 if all(vals) else (2 if not any(vals) else 10))
247
+
> PY
248
+
> ```
249
+
>
250
+
> Branch on the exit code:
251
+
>
252
+
> | Exit | Meaning | Action |
253
+
> |------|---------|--------|
254
+
> | `0` | **ALL_SET** — all 3 deployments already mapped on the resource | Show the detected values and ask *"Detected existing defaults: gpt-4.1=`<A>`, gpt-4.1-mini=`<B>`, text-embedding-3-large=`<C>`. Use these? (Y/n)"*. On Y, prefill the 3 env vars and **skip Step 6** (defaults already configured). On n, fall through to the per-model prompts below. |
255
+
> | `10` | **PARTIAL** — some mapped, some missing | Prefill the ones that are set. For missing models, ask per-item with the default shown below. After Step 4 completes, run Step 6 to fill the gaps. |
256
+
> | `2` | **NONE** — resource has no defaults yet | Fall through to the per-model prompts below. Step 6 will configure them. |
257
+
> | `3` | **AUTH_ERROR** (401/403) | Print a one-line warning: *"Probe unavailable (auth failed). If you're using DefaultAzureCredential, run `az login` and ensure the Cognitive Services User role is assigned. Continuing with manual entry."* Fall through to per-model prompts. |
258
+
> | other | Unexpected error | Print *"Probe failed: `<error>`. Continuing with manual entry."* Fall through. |
259
+
>
260
+
> Only proceed to the per-model prompts below when the probe outcome requires it.
261
+
262
+
> **[ASK USER] Model deployment names (only when probe did not yield all values):**
263
+
> For each model not already prefilled from the probe, ask with a sensible default:
173
264
> - "What is your **GPT-4.1** deployment name?" (default: `gpt-4.1`)
174
265
> - "What is your **GPT-4.1-mini** deployment name?" (default: `gpt-4.1-mini`)
175
266
> - "What is your **text-embedding-3-large** deployment name?" (default: `text-embedding-3-large`)
176
-
> - If no, let them know they can configure these later before running `sample_update_defaults.py`.
267
+
>
268
+
> If the user prefers to configure these later, let them know they can run `sample_update_defaults.py` (Step 6) anytime before using prebuilt analyzers.
177
269
178
270
| Variable | Description | How to Get It |
179
271
|----------|-------------|---------------|
@@ -203,7 +295,7 @@ Open `.env` in your editor and set the following **required** variables:
# Optional: API key (if not set, DefaultAzureCredential is used)
206
-
CONTENTUNDERSTANDING_KEY=abc123...
298
+
CONTENTUNDERSTANDING_KEY=
207
299
208
300
# Required for sample_update_defaults.py (model configuration)
209
301
GPT_4_1_DEPLOYMENT=gpt-4.1
@@ -261,6 +353,9 @@ This role is required even if you own the resource:
261
353
262
354
### Step 6: Configure Model Defaults (One-Time Setup)
263
355
356
+
> **[COPILOT] Skip condition:**
357
+
> If the Step 4.2 probe returned **ALL_SET** and the user accepted the detected values, defaults are already configured on the Foundry resource — skip this step and tell the user *"Your Foundry resource already has model defaults configured; skipping Step 6."* Otherwise continue below.
358
+
264
359
> **[ASK USER] Run model defaults?:**
265
360
> Ask: "Would you like to run `sample_update_defaults.py` now to configure model defaults? This is a **one-time setup** per Microsoft Foundry resource. (Yes / Skip for now)"
266
361
> - If yes, ensure deployment name env vars are set, then run the script.
@@ -279,13 +374,15 @@ This is a **one-time setup per Microsoft Foundry resource**.
279
374
280
375
> **[ASK USER] Which samples?:**
281
376
> Ask: "Which sample would you like to run first?" with options:
282
-
> -`sample_analyze_url.py` — Analyze content from a URL (recommended start)
283
-
> -`sample_analyze_binary.py` — Analyze a local file
377
+
> - `sample_analyze_binary.py` — Analyze a local PDF (quickest; completes in under a minute)
378
+
> - `sample_analyze_url.py` — Full demo: document + video + audio + image from URLs (runs several analyses; takes a few minutes, please be patient)
> If the user picks "Other", list available samples from the `samples/` directory.
384
+
>
385
+
> **[COPILOT] Timing note (do not parrot verbatim to user):** `sample_analyze_url.py` runs 14 sequential LROs (document + video + audio + image, with multiple content-range variants). Video/audio chapter generation is slow on the service side, so total runtime can be on the order of 15+ minutes today. Do not interpret quiet periods (no stdout for several minutes during a video/audio LRO) as a hang. Only consider killing if there is **no new stdout for 5+ minutes** AND no active HTTP traffic. When talking to the user, prefer phrasing like "takes a few minutes" or "please be patient" rather than citing exact large minute counts.
0 commit comments