Skip to content

Commit da088d0

Browse files
samuel100Copilot
andauthored
Add named regions and tutorial samples for docs externalization (#563)
To ensure that our docs on MS Learn have accurate code samples, we will update the docs so they consume the code from this repo. In this repo, we will run a test to ensure that the samples work - if there is a break in the samples then this should be fix before a PR can be merged in. - Add named regions to 15 existing sample files (CS, JS, Python, Rust) - Create 3 missing Python samples (audio-transcription, web-server, langchain-integration) - Create 16 tutorial sample projects (4 tutorials x 4 languages) - Add samples-integration-test.yml CI workflow --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2a1bf56 commit da088d0

File tree

116 files changed

+4036
-2646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+4036
-2646
lines changed
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
name: Samples Build Check
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'samples/**'
7+
- '.github/workflows/samples-integration-test.yml'
8+
push:
9+
paths:
10+
- 'samples/**'
11+
- '.github/workflows/samples-integration-test.yml'
12+
branches:
13+
- main
14+
workflow_dispatch:
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
# ── Python Samples ──────────────────────────────────────────────────
21+
python-samples:
22+
runs-on: ${{ matrix.platform }}-latest
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
platform: [windows, macos]
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
with:
32+
clean: true
33+
34+
- name: Setup Python
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: '3.12'
38+
39+
- name: Configure pip for Azure Artifacts
40+
run: |
41+
pip config set global.index-url https://pkgs.dev.azure.com/aiinfra/PublicPackages/_packaging/ORT-Nightly/pypi/simple/
42+
pip config set global.extra-index-url https://pypi.org/simple/
43+
pip config set global.pre true
44+
45+
- name: Build and install SDK from source
46+
working-directory: sdk/python
47+
shell: pwsh
48+
run: |
49+
python -m pip install build
50+
echo '__version__ = "0.0.0-dev"' > src/version.py
51+
python -m build --wheel --outdir dist/
52+
$wheel = (Get-ChildItem dist/*.whl | Select-Object -First 1).FullName
53+
pip install $wheel
54+
55+
- name: Install sample dependencies
56+
shell: pwsh
57+
run: |
58+
Get-ChildItem samples/python/*/requirements.txt -ErrorAction SilentlyContinue | ForEach-Object {
59+
Write-Host "Installing dependencies for $($_.Directory.Name)..."
60+
pip install -r $_.FullName
61+
}
62+
63+
- name: Syntax check Python samples
64+
shell: pwsh
65+
run: |
66+
$failed = @()
67+
$samples = Get-ChildItem samples/python/*/src/app.py -ErrorAction SilentlyContinue
68+
foreach ($sample in $samples) {
69+
$name = $sample.Directory.Parent.Name
70+
Write-Host "=== Checking: $name ==="
71+
python -m py_compile $sample.FullName
72+
if ($LASTEXITCODE -ne 0) {
73+
Write-Host "FAILED: $name"
74+
$failed += $name
75+
} else {
76+
Write-Host "OK: $name"
77+
}
78+
}
79+
if ($failed.Count -gt 0) {
80+
Write-Error "Failed syntax checks: $($failed -join ', ')"
81+
exit 1
82+
}
83+
84+
# ── JavaScript Samples ──────────────────────────────────────────────
85+
js-samples:
86+
runs-on: ${{ matrix.platform }}-latest
87+
strategy:
88+
fail-fast: false
89+
matrix:
90+
platform: [windows, macos]
91+
92+
steps:
93+
- name: Checkout repository
94+
uses: actions/checkout@v4
95+
with:
96+
clean: true
97+
98+
- name: Setup Node.js
99+
uses: actions/setup-node@v4
100+
with:
101+
node-version: '20.x'
102+
103+
- name: Setup .NET SDK for NuGet authentication
104+
uses: actions/setup-dotnet@v5
105+
with:
106+
dotnet-version: '10.0.x'
107+
108+
- name: Build SDK from source
109+
working-directory: sdk/js
110+
run: |
111+
npm install
112+
npm run build
113+
npm link
114+
115+
- name: Syntax check JS samples
116+
shell: pwsh
117+
run: |
118+
$failed = @()
119+
# Find all sample app.js files (either in root or src/)
120+
$samples = @()
121+
$samples += Get-ChildItem samples/js/*/app.js -ErrorAction SilentlyContinue
122+
$samples += Get-ChildItem samples/js/*/src/app.js -ErrorAction SilentlyContinue
123+
foreach ($sample in $samples) {
124+
$dir = if ($sample.Directory.Name -eq 'src') { $sample.Directory.Parent } else { $sample.Directory }
125+
$name = $dir.Name
126+
Write-Host "=== Checking: $name ==="
127+
# Link SDK and install dependencies
128+
Push-Location $dir.FullName
129+
npm link foundry-local-sdk 2>$null
130+
if (Test-Path "package.json") { npm install 2>$null }
131+
Pop-Location
132+
# Syntax check
133+
node --check $sample.FullName 2>&1
134+
if ($LASTEXITCODE -ne 0) {
135+
Write-Host "FAILED: $name"
136+
$failed += $name
137+
} else {
138+
Write-Host "OK: $name"
139+
}
140+
}
141+
if ($failed.Count -gt 0) {
142+
Write-Error "Failed syntax checks: $($failed -join ', ')"
143+
exit 1
144+
}
145+
146+
# ── C# Samples ─────────────────────────────────────────────────────
147+
cs-samples:
148+
runs-on: ${{ matrix.platform }}-latest
149+
strategy:
150+
fail-fast: false
151+
matrix:
152+
platform: [windows, macos]
153+
154+
steps:
155+
- name: Checkout repository
156+
uses: actions/checkout@v4
157+
with:
158+
clean: true
159+
160+
- name: Setup .NET SDK
161+
uses: actions/setup-dotnet@v5
162+
with:
163+
dotnet-version: |
164+
8.0.x
165+
10.0.x
166+
167+
- name: Build SDK from source
168+
shell: pwsh
169+
run: |
170+
# Build cross-platform SDK package
171+
# Note: /p:TreatWarningsAsErrors=false avoids failing on SDK doc warnings
172+
dotnet pack sdk/cs/src/Microsoft.AI.Foundry.Local.csproj `
173+
-o local-packages `
174+
/p:Version=0.9.0-dev `
175+
/p:IsPacking=true `
176+
/p:TreatWarningsAsErrors=false `
177+
--configuration Release
178+
179+
# Build WinML SDK package (Windows only)
180+
if ($IsWindows) {
181+
dotnet pack sdk/cs/src/Microsoft.AI.Foundry.Local.csproj `
182+
-o local-packages `
183+
/p:Version=0.9.0-dev-20260324 `
184+
/p:UseWinML=true `
185+
/p:IsPacking=true `
186+
/p:TreatWarningsAsErrors=false `
187+
--configuration Release
188+
}
189+
190+
Write-Host "Local packages:"
191+
Get-ChildItem local-packages/*.nupkg | ForEach-Object { Write-Host " $($_.Name)" }
192+
193+
- name: Build C# samples
194+
shell: pwsh
195+
run: |
196+
$failed = @()
197+
$projects = Get-ChildItem samples/cs -Recurse -Filter "*.csproj"
198+
foreach ($proj in $projects) {
199+
$name = $proj.BaseName
200+
Write-Host "`n=== Building: $name ==="
201+
dotnet build $proj.FullName --configuration Debug 2>&1
202+
if ($LASTEXITCODE -ne 0) {
203+
Write-Host "BUILD FAILED: $name"
204+
$failed += $name
205+
} else {
206+
Write-Host "BUILD PASSED: $name"
207+
}
208+
}
209+
if ($failed.Count -gt 0) {
210+
Write-Error "Failed builds: $($failed -join ', ')"
211+
exit 1
212+
}
213+
214+
# ── Rust Samples ────────────────────────────────────────────────────
215+
rust-samples:
216+
runs-on: ${{ matrix.platform }}-latest
217+
strategy:
218+
fail-fast: false
219+
matrix:
220+
platform: [windows, macos]
221+
222+
steps:
223+
- name: Checkout repository
224+
uses: actions/checkout@v4
225+
with:
226+
clean: true
227+
228+
- name: Install Rust toolchain
229+
uses: dtolnay/rust-toolchain@stable
230+
with:
231+
components: clippy
232+
233+
- name: Cache cargo dependencies
234+
uses: Swatinem/rust-cache@v2
235+
with:
236+
workspaces: samples/rust -> target
237+
238+
- name: Use crates.io directly
239+
shell: pwsh
240+
run: |
241+
# Remove crates-io redirect in SDK (points to Azure Artifacts)
242+
$configPath = "sdk/rust/.cargo/config.toml"
243+
if (Test-Path $configPath) {
244+
Remove-Item $configPath
245+
Write-Host "Removed sdk/rust/.cargo/config.toml"
246+
}
247+
# Remove crates-io redirect in samples
248+
$configPath = "samples/rust/.cargo/config.toml"
249+
if (Test-Path $configPath) {
250+
Remove-Item $configPath
251+
Write-Host "Removed samples/rust/.cargo/config.toml"
252+
}
253+
254+
- name: Build Rust samples workspace
255+
working-directory: samples/rust
256+
run: cargo build --workspace
257+
258+
- name: Clippy check
259+
working-directory: samples/rust
260+
run: cargo clippy --workspace -- -D warnings

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ bin/
3333
obj/
3434
/src/cs/samples/ConsoleClient/test.http
3535
logs/
36+
37+
# Local NuGet packages built from source
38+
local-packages/

samples/cs/GettingStarted/Directory.Packages.props renamed to samples/cs/Directory.Packages.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
<ItemGroup>
88
<PackageVersion Include="Microsoft.AI.Foundry.Local" Version="0.9.0-dev" />
99
<PackageVersion Include="Microsoft.AI.Foundry.Local.WinML" Version="0.9.0-dev-20260324" />
10+
<PackageVersion Include="Betalgo.Ranul.OpenAI" Version="9.1.1" />
1011
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.10" />
12+
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.10" />
13+
<PackageVersion Include="NAudio" Version="2.2.1" />
1114
<PackageVersion Include="OpenAI" Version="2.5.0" />
1215
</ItemGroup>
1316
</Project>

samples/cs/GettingStarted/README.md

Lines changed: 0 additions & 61 deletions
This file was deleted.

samples/cs/GettingStarted/cross-platform/AudioTranscriptionExample/AudioTranscriptionExample.csproj

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)