-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Content Understanding GA SDK #54117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yungshinlintw
wants to merge
107
commits into
main
Choose a base branch
from
yslin/cu_ga_sdk_tsp_client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+35,714
−2
Open
Content Understanding GA SDK #54117
Changes from 77 commits
Commits
Show all changes
107 commits
Select commit
Hold shift + click to select a range
c753924
SDK-GEN: Generate SDK with tsp-client on CU GA TypeSpec
yungshinlintw f826e7e
SDK-FIX: Suppress specific warnings in project file for Azure.AI.Cont…
yungshinlintw 2925453
MIGRATION: Migrate Project related files
yungshinlintw cc89698
SDK-FIX: Update AnalyzeRequest1 initialization to handle null modelDe…
yungshinlintw 36f29fe
SAMPLE: Migrate Analyze* Samples
yungshinlintw 3d84e07
SAMPLE: Update .gitignore to include sample output directories genera…
yungshinlintw 94fb012
SDK-EXT: ContentField.Value
yungshinlintw fc447f2
SDK-EXT: Extension methods for ArrayField and ObjectField to enhance …
yungshinlintw 5a3e07a
SDK-EXT: Add extension methods for DocumentContent to retrieve fields…
yungshinlintw 473739e
SDK-FIX: Enhance deserialization logic in ContentAnalyzer and Support…
yungshinlintw db6724b
SDK-EXT: Add extension methods for ContentUnderstandingClient to upda…
yungshinlintw 9af7c76
SAMPLE: Add new samples for CreateAnalyzer, AnalyzeUrlPrebuiltInvoice…
yungshinlintw 3d8dd78
SDK-FIX: Improve serialization logic in AnalyzeRequest1 and AnalyzeRe…
yungshinlintw e6b37b3
SDK-FIX: Update deserialization logic in AudioVisualContent to handle…
yungshinlintw 533029c
SDK-EXT: Add OperationExtensions class with GetOperationId method to …
yungshinlintw b54f662
SAMPLE: Add GetResultFile sample demonstrating how to retrieve keyfra…
yungshinlintw be5e285
Add comprehensive tests for Azure.AI.ContentUnderstanding
45aad16
Include shared source file in test project
d108858
SERVICE-FIX: Allow 201/202 in copy. SDK-FIX: copy request
yungshinlintw e125b08
SAMPLE: Add new samples for Classifier, AnalyzeBinaryFeatures, Analyz…
yungshinlintw aa1c560
Merge branch 'yslin/cu_ga_sdk_tsp_client' of https://github.com/Azure…
yungshinlintw 352b31e
SAMPLE-MD: Add AnalyzeBinary.md and also add sample test infra
yungshinlintw 6fb5844
SAMPLE: Add Sample01_AnalyzeBinary demonstrating PDF analysis using p…
yungshinlintw bb7d68d
SAMPLE: Add Sample02_AnalyzeUrl demonstrating document analysis from …
yungshinlintw c43e556
SAMPLE: Add Sample00_ConfigureDefaults demonstrating model deployment…
yungshinlintw 97324c9
SDK: Introduce customization for ContentUnderstandingClient to manage…
yungshinlintw da9e4ac
SAMPLE: Add Sample03_AnalyzeInvoice demonstrating invoice analysis us…
yungshinlintw f9193fd
SAMPLE: Add Sample04_CreateAnalyzer
yungshinlintw 0942535
SAMPLE: Add multiple new samples for analyzer management and classifi…
yungshinlintw 09ca40e
SAMPLE: Add new samples for analyzing documents and retrieving results
yungshinlintw f84da89
SAMPLE: Add new samples for deleting analysis results and copying ana…
yungshinlintw c00719f
SAMPLE: Remove deprecated samples for document analysis and management
yungshinlintw 479980f
SAMPLE: Update appsettings.json.sample and remove outdated UpdateAnal…
yungshinlintw ec32410
TEST: Add AssemblyInfo and include AzureResourceProviderNamespaceAttr…
yungshinlintw 746c135
SAMPLE-TEST: Remove AnalyzeBinaryTest and enhance Sample01_AnalyzeBin…
yungshinlintw 5c6332b
Enhance tests for Content Understanding SDK
2887b93
Remove obsolete test helper and update analyzer tests for improved fu…
653060a
Restore the deleted test csproj, and code cleanup
yungshinlintw 9938246
TEST: Clean up
yungshinlintw 5461273
SAMPLE: Add runnable GrantCopyAuth
yungshinlintw cf775cf
README: Update Sample README.md
yungshinlintw ca3cebe
SAMPLE: Delete duplicated samples
yungshinlintw 5c52620
SDK-GEN: Re-generate SDK and add customization for return AnalyzeResu…
yungshinlintw 10cc0f4
SDK-EXT: Address OperationId timing issue
yungshinlintw e01ac56
SAMPLE: Update samples to use byte arrays directly instead of BinaryD…
yungshinlintw d195a2d
SDK-EXT: Use BinaryData for AnalyzeBinary
yungshinlintw aabe91d
SAMPLE: Sample Update to use BinaryData for AnalyzeBinary
yungshinlintw b919cce
SDK-EXT: Change AnalyzeResultOperation constructor access modifier to…
yungshinlintw 75d2bfd
SDK-EXT: Update AnalyzeResultOperation to expose operation ID via Id …
yungshinlintw 8e94dca
SDK-EXT: Remove redundant XML documentation for the AnalyzeResultOper…
yungshinlintw 8e8032a
SAMPLE: Update samples to use operation ID from Id property instead o…
yungshinlintw 29a35a8
Update Sample Readme (#54129)
chienyuanchang 30c3169
SDK-GEN: Update Content Understanding SDK to reflect changes in model…
yungshinlintw 0ab9b95
SDK-EXT: Remove suppression of AZC0034 warning in Content Understandi…
yungshinlintw a280d88
SDK-EXT: Add suppression for AZC0034 warnings in Suppression.cs to ha…
yungshinlintw f118dcc
SDK-GEN: Update Content Understanding SDK to correct SupportedModels …
yungshinlintw d43bb07
SDK-FIX: Fix known emitters (copyAnalyzer path, result) and serivce i…
yungshinlintw bb8d80b
SAMPLE: Sample update for ContentCategory renaming
yungshinlintw 0e11caa
TEST: Enable GrantCopyAuth test
yungshinlintw 2fb0ab1
TEST: Migrate recording to test asset repo
yungshinlintw 3e179db
API and README
yungshinlintw b4a85f9
CI: Fix broken links and remove en-US in the link
yungshinlintw 8965069
CI: Make sure that samples are not packable
yungshinlintw 85a92df
CI: Fix broken link and remove en-US in link
yungshinlintw b3c6e3a
CI: CHANGELOG: Update version to 1.0.0-beta.1 (Unreleased) and clarif…
yungshinlintw feff9d9
CI: Update sample documentation links to point to the correct GitHub …
yungshinlintw 9575d74
CI: Update azure-cognitive-services
yungshinlintw 76960a3
CI: Address cspell issue
yungshinlintw f1138c2
CI: Address cspell.json issue
yungshinlintw f29bb58
CI: Updaet assets.json
yungshinlintw 27b9561
SAMPLE: Delete dupe line
yungshinlintw 064afdd
SDK-FIX: Re-implement the required CU service workaround and emitter…
yungshinlintw 553b29d
SDK-FIX: Fix CI issues due to blank lines
yungshinlintw 48cbfac
CI: Update for sample code snippets consistency between MD and sample…
yungshinlintw 3965d1b
CI: Fix relative link to MD to be URL
yungshinlintw c6d405e
Enhance test assertions and logging for Content Understanding SDK sam…
7ae31e7
Merge remote-tracking branch 'origin/main' into yslin/cu_ga_sdk_tsp_c…
yungshinlintw 6a86545
SDK-GEN: Regenerate SDK after mergeing from main
yungshinlintw a16a282
use mixed_financial_docs for classifier (#54175)
chienyuanchang 677a712
SAMPLE: Removed snippets not used in MD file
yungshinlintw a966bde
Update assets.json for Sample05_CreateClassifier test recordings
yungshinlintw cc2437f
Update assets.json tag to include new Sample05_CreateClassifier recor…
yungshinlintw 6b27c19
SAMPLE: Update classifier test sample file
yungshinlintw ddcbe32
TEST: Update assets.json tag to reflect latest changes in the Content…
yungshinlintw 18e972d
CI: Update samples to include file path and document URL placeholders…
yungshinlintw df42a40
CI: Fix MD file link
yungshinlintw aaadc7d
PR: Remove local editconfig
yungshinlintw 356cbce
Merge branch 'yslin/cu_ga_sdk_tsp_client' of https://github.com/Azure…
9839e9c
PR: Feedback to add CODEOWNERS and better nuget description
yungshinlintw 60d491c
TEST: Enhance console output for analysis operation verification in S…
89d8126
PR: Remove runnable samples per PR feedback.
yungshinlintw ba58a99
PR: Move cspell.yaml from .github/ to CU project
yungshinlintw f6f4290
CI: Fixed broken md file links
yungshinlintw 37df33a
Merge remote-tracking branch 'origin/changjian-wang/improve_tests_for…
yungshinlintw c757c16
SAMPLE: Update messages
yungshinlintw 3650d7c
TEST: update assets.json for extended test cases
yungshinlintw 7bcda26
CI: Fix incorrect cspell.json path
yungshinlintw e48e2ed
TEST: Add client tests
yungshinlintw 12661ba
CI: Fix snippet issue
yungshinlintw 276f9c3
TEST: Fix incorrect media file used in GetResultFile sample test
yungshinlintw 2af7ade
TEST: Extend client test cases
yungshinlintw 05db1d3
SAMPLE: Extend client test cases
yungshinlintw f6b3cb3
CI: Update sample snippet
yungshinlintw dd8b75a
CI: Fix incorrect sample test cod
yungshinlintw 70ae5b9
SAMPLE: Remove asserstions in GrantCopyAuth sample
yungshinlintw fb23811
CODEOWNERS: Fix formatting
yungshinlintw 62771d5
CODEOWNERS: Remove alias that does not meet req
yungshinlintw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
sdk/contentunderstanding/Azure.AI.ContentUnderstanding/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Local-only files and temporary scripts (not committed to git) | ||
| __local_only/ | ||
|
|
||
| # User-specific configuration files (never commit appsettings.json - they may contain secrets) | ||
| **/appsettings.json | ||
| !**/appsettings.json.sample | ||
|
|
||
| # EditorConfig file (SDK-specific, not committed) | ||
yungshinlintw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .editorconfig | ||
|
|
||
| # Sample output directories (generated by sample execution) | ||
| **/sample_output/ | ||
|
|
||
| # Test recordings (SessionRecords) - should not be committed | ||
| **/SessionRecords/ | ||
|
|
||
30 changes: 30 additions & 0 deletions
30
sdk/contentunderstanding/Azure.AI.ContentUnderstanding/Azure.AI.ContentUnderstanding.sln
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 17 | ||
| VisualStudioVersion = 17.0.31903.59 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.AI.ContentUnderstanding", "src\Azure.AI.ContentUnderstanding.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{C2E8EBF5-F05A-22ED-9231-040E2E2D8446}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {C2E8EBF5-F05A-22ED-9231-040E2E2D8446}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {C2E8EBF5-F05A-22ED-9231-040E2E2D8446}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {C2E8EBF5-F05A-22ED-9231-040E2E2D8446}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {C2E8EBF5-F05A-22ED-9231-040E2E2D8446}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} | ||
| EndGlobalSection | ||
| EndGlobal |
14 changes: 14 additions & 0 deletions
14
sdk/contentunderstanding/Azure.AI.ContentUnderstanding/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Release History | ||
|
|
||
| ## 1.0.0-beta.1 (Unreleased) | ||
|
|
||
| ### Features Added | ||
| - Initial release of Azure AI Content Understanding client library for .NET | ||
| - Added `ContentUnderstandingClient` for analyzing documents, audio, and video content | ||
| - Added `AnalyzeResultOperation` class that extends `Operation<AnalyzeResult>` and provides access to the operation ID via the `Id` property | ||
|
|
||
| ### Breaking Changes | ||
|
|
||
| ### Bugs Fixed | ||
|
|
||
| ### Other Changes |
6 changes: 6 additions & 0 deletions
6
sdk/contentunderstanding/Azure.AI.ContentUnderstanding/Directory.Build.props
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <!-- | ||
| Add any shared properties you want for the projects under this package directory that need to be set before the auto imported Directory.Build.props | ||
| --> | ||
| <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.props))\Directory.Build.props" /> | ||
| </Project> |
260 changes: 260 additions & 0 deletions
260
sdk/contentunderstanding/Azure.AI.ContentUnderstanding/README.md
Large diffs are not rendered by default.
Oops, something went wrong.
1,276 changes: 1,276 additions & 0 deletions
1,276
...ntunderstanding/Azure.AI.ContentUnderstanding/api/Azure.AI.ContentUnderstanding.net8.0.cs
Large diffs are not rendered by default.
Oops, something went wrong.
1,275 changes: 1,275 additions & 0 deletions
1,275
...tanding/Azure.AI.ContentUnderstanding/api/Azure.AI.ContentUnderstanding.netstandard2.0.cs
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
sdk/contentunderstanding/Azure.AI.ContentUnderstanding/assets.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "AssetsRepo": "Azure/azure-sdk-assets", | ||
| "AssetsRepoPrefixPath": "net", | ||
| "TagPrefix": "net/contentunderstanding/Azure.AI.ContentUnderstanding", | ||
| "Tag": "net/contentunderstanding/Azure.AI.ContentUnderstanding_1764097269" | ||
| } | ||
|
|
313 changes: 313 additions & 0 deletions
313
sdk/contentunderstanding/Azure.AI.ContentUnderstanding/samples/README.md
Large diffs are not rendered by default.
Oops, something went wrong.
111 changes: 111 additions & 0 deletions
111
...derstanding/Azure.AI.ContentUnderstanding/samples/Sample00_ConfigureDefaults.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # Configure model deployment defaults | ||
|
|
||
| This sample demonstrates how to configure and retrieve default model deployment settings for your Microsoft Foundry resource. This is a **required one-time setup** before using prebuilt analyzers. | ||
|
|
||
| ## About Model Deployment Configuration | ||
|
|
||
| Content Understanding prebuilt analyzers require specific GPT model deployments to function: | ||
|
|
||
| - **GPT-4.1** - Used by most prebuilt analyzers (e.g., `prebuilt-invoice`, `prebuilt-receipt`, `prebuilt-idDocument`) | ||
| - **GPT-4.1-mini** - Used by RAG analyzers (e.g., `prebuilt-documentSearch`, `prebuilt-audioSearch`, `prebuilt-videoSearch`) | ||
| - **text-embedding-3-large** - Used for semantic search and embeddings | ||
|
|
||
| This configuration is **per Microsoft Foundry resource** and persists across sessions. You only need to configure it once per Microsoft Foundry resource (or when you change deployment names). | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| To get started you'll need a **Microsoft Foundry resource**. See [README][README] for prerequisites and instructions. | ||
|
|
||
| You also need to have deployed the following models in Microsoft Foundry: | ||
| - GPT-4.1 | ||
| - GPT-4.1-mini | ||
| - text-embedding-3-large | ||
|
|
||
| ## Creating a `ContentUnderstandingClient` | ||
|
|
||
| The `ContentUnderstandingClient` is the main interface for interacting with the Content Understanding service. In this sample, you'll use the client to: | ||
| - Retrieve current model deployment defaults (`GetDefaultsAsync`) | ||
| - Update model deployment mappings (`UpdateDefaultsAsync`) | ||
|
|
||
| To create a new `ContentUnderstandingClient` you need the endpoint and credentials from your Microsoft Foundry resource. You can authenticate using either `DefaultAzureCredential` (recommended) or an API key. | ||
|
|
||
| ### Using DefaultAzureCredential (Recommended) | ||
|
|
||
| ```C# Snippet:CreateContentUnderstandingClient | ||
| string endpoint = "<endpoint>"; | ||
| var credential = new DefaultAzureCredential(); | ||
| var client = new ContentUnderstandingClient(new Uri(endpoint), credential); | ||
| ``` | ||
|
|
||
| ### Using API Key | ||
|
|
||
| ```C# Snippet:CreateContentUnderstandingClientApiKey | ||
| string endpoint = "<endpoint>"; | ||
| string apiKey = "<apiKey>"; | ||
| var client = new ContentUnderstandingClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); | ||
| ``` | ||
|
|
||
| > **⚠️ Security Warning**: API key authentication is not secure and is only recommended for testing purposes with test resources. For production, use `DefaultAzureCredential` or other secure authentication methods. | ||
|
|
||
| ## Configure Model Deployments | ||
|
|
||
| Before you can use prebuilt analyzers, you need to map your deployed GPT models to the models required by the prebuilt analyzers: | ||
|
|
||
| ```C# Snippet:ContentUnderstandingUpdateDefaults | ||
| // Map your deployed models to the models required by prebuilt analyzers | ||
| var modelDeployments = new Dictionary<string, string> | ||
| { | ||
| ["gpt-4.1"] = "<your-gpt-4.1-deployment-name>", | ||
| ["gpt-4.1-mini"] = "<your-gpt-4.1-mini-deployment-name>", | ||
| ["text-embedding-3-large"] = "<your-text-embedding-3-large-deployment-name>" | ||
| }; | ||
|
|
||
| var response = await client.UpdateDefaultsAsync(modelDeployments); | ||
| ContentUnderstandingDefaults updatedDefaults = response.Value; | ||
|
|
||
| Console.WriteLine("Model deployments configured successfully!"); | ||
| foreach (var kvp in updatedDefaults.ModelDeployments) | ||
| { | ||
| Console.WriteLine($" {kvp.Key} → {kvp.Value}"); | ||
| } | ||
| ``` | ||
|
|
||
| ## Retrieve Current Defaults | ||
|
|
||
| You can retrieve the current default model deployment configuration: | ||
|
|
||
| ```C# Snippet:ContentUnderstandingGetDefaults | ||
| var getResponse = await client.GetDefaultsAsync(); | ||
| ContentUnderstandingDefaults defaults = getResponse.Value; | ||
|
|
||
| Console.WriteLine("Current model deployment mappings:"); | ||
| if (defaults.ModelDeployments != null && defaults.ModelDeployments.Count > 0) | ||
| { | ||
| foreach (var kvp in defaults.ModelDeployments) | ||
| { | ||
| Console.WriteLine($" {kvp.Key} → {kvp.Value}"); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine(" No model deployments configured yet."); | ||
| } | ||
| ``` | ||
|
|
||
| ## Next Steps | ||
|
|
||
| After configuring model deployments, you can use prebuilt analyzers. See: | ||
| - [Sample 01: Analyze a document from binary data][sample01] to analyze PDF files | ||
| - [Sample 02: Analyze a document from URL][sample02] to analyze documents from URLs | ||
|
|
||
| ## Learn More | ||
|
|
||
| - [Content Understanding Documentation][cu-docs] | ||
| - [Model Deployment Configuration][model-deployment-docs] | ||
|
|
||
| [README]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/contentunderstanding/Azure.AI.ContentUnderstanding/samples/README.md | ||
| [sample01]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/contentunderstanding/Azure.AI.ContentUnderstanding/samples/Sample01_AnalyzeBinary.md | ||
| [sample02]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/contentunderstanding/Azure.AI.ContentUnderstanding/samples/Sample02_AnalyzeUrl.md | ||
| [cu-docs]: https://learn.microsoft.com/azure/ai-services/content-understanding/ | ||
| [model-deployment-docs]: https://learn.microsoft.com/azure/ai-services/content-understanding/quickstart/use-rest-api?tabs=portal%2Cdocument | ||
|
|
145 changes: 145 additions & 0 deletions
145
...understanding/Azure.AI.ContentUnderstanding/samples/Sample00_ConfigureDefaults/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using Azure; | ||
| using Azure.AI.ContentUnderstanding; | ||
| using Azure.Core; | ||
| using Azure.Identity; | ||
| using Microsoft.Extensions.Configuration; | ||
|
|
||
| /// <summary> | ||
| /// This sample demonstrates how to configure and retrieve default model deployment settings for your Microsoft Foundry resource. | ||
| /// | ||
| /// Prerequisites: | ||
| /// - Azure subscription | ||
| /// - Microsoft Foundry resource | ||
| /// - .NET 8.0 SDK or later | ||
| /// - Deployed GPT-4.1, GPT-4.1-mini, and text-embedding-3-large models in Microsoft Foundry | ||
| /// | ||
| /// Setup: | ||
| /// Set the following environment variables or add them to appsettings.json: | ||
| /// - AZURE_CONTENT_UNDERSTANDING_ENDPOINT (required) | ||
| /// - AZURE_CONTENT_UNDERSTANDING_KEY (optional - DefaultAzureCredential will be used if not set) | ||
| /// - GPT_4_1_DEPLOYMENT (optional - required only for UpdateDefaults) | ||
| /// - GPT_4_1_MINI_DEPLOYMENT (optional - required only for UpdateDefaults) | ||
| /// - TEXT_EMBEDDING_3_LARGE_DEPLOYMENT (optional - required only for UpdateDefaults) | ||
| /// | ||
| /// To run: | ||
| /// dotnet run | ||
| /// </summary> | ||
| class Program | ||
| { | ||
| static async Task Main(string[] args) | ||
| { | ||
| // Load configuration | ||
| var configuration = new ConfigurationBuilder() | ||
| .SetBasePath(AppContext.BaseDirectory) | ||
| .AddJsonFile("appsettings.json", optional: true) | ||
| .AddEnvironmentVariables() | ||
| .Build(); | ||
|
|
||
| var endpoint = configuration["AZURE_CONTENT_UNDERSTANDING_ENDPOINT"]; | ||
| if (string.IsNullOrEmpty(endpoint)) | ||
| { | ||
| Console.Error.WriteLine("Error: AZURE_CONTENT_UNDERSTANDING_ENDPOINT is required."); | ||
| Console.Error.WriteLine("Please set it in environment variables or appsettings.json"); | ||
| Environment.Exit(1); | ||
| } | ||
|
|
||
| // Trim and validate endpoint | ||
| endpoint = endpoint.Trim(); | ||
| if (!Uri.TryCreate(endpoint, UriKind.Absolute, out var endpointUri)) | ||
| { | ||
| Console.Error.WriteLine($"Error: Invalid endpoint URL: {endpoint}"); | ||
| Console.Error.WriteLine("Endpoint must be a valid absolute URI (e.g., https://your-resource.services.ai.azure.com/)"); | ||
| Environment.Exit(1); | ||
| } | ||
|
|
||
| // Create client with appropriate authentication | ||
| var apiKey = configuration["AZURE_CONTENT_UNDERSTANDING_KEY"]; | ||
| ContentUnderstandingClient client; | ||
| if (!string.IsNullOrEmpty(apiKey)) | ||
| { | ||
| client = new ContentUnderstandingClient(endpointUri, new AzureKeyCredential(apiKey)); | ||
| } | ||
| else | ||
| { | ||
| var credential = new DefaultAzureCredential(); | ||
| client = new ContentUnderstandingClient(endpointUri, credential); | ||
| } | ||
|
|
||
| try | ||
| { | ||
| // First, update defaults if deployment names are provided | ||
| var gpt41Deployment = configuration["GPT_4_1_DEPLOYMENT"]; | ||
| var gpt41MiniDeployment = configuration["GPT_4_1_MINI_DEPLOYMENT"]; | ||
| var textEmbeddingDeployment = configuration["TEXT_EMBEDDING_3_LARGE_DEPLOYMENT"]; | ||
|
|
||
| if (!string.IsNullOrEmpty(gpt41Deployment) && !string.IsNullOrEmpty(gpt41MiniDeployment) && !string.IsNullOrEmpty(textEmbeddingDeployment)) | ||
| { | ||
| Console.WriteLine("=== Updating Defaults ==="); | ||
| // Map your deployed models to the models required by prebuilt analyzers | ||
| var modelDeployments = new Dictionary<string, string> | ||
| { | ||
| ["gpt-4.1"] = gpt41Deployment, | ||
| ["gpt-4.1-mini"] = gpt41MiniDeployment, | ||
| ["text-embedding-3-large"] = textEmbeddingDeployment | ||
| }; | ||
|
|
||
| var updateResponse = await client.UpdateDefaultsAsync(modelDeployments); | ||
| ContentUnderstandingDefaults updatedDefaults = updateResponse.Value; | ||
|
|
||
| Console.WriteLine("Model deployments configured successfully!"); | ||
| foreach (var kvp in updatedDefaults.ModelDeployments) | ||
| { | ||
| Console.WriteLine($" {kvp.Key} → {kvp.Value}"); | ||
| } | ||
|
|
||
| Console.WriteLine(); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine("=== Skipping UpdateDefaults ==="); | ||
| Console.WriteLine("To update defaults, set the following in appsettings.json or environment variables:"); | ||
| Console.WriteLine(" - GPT_4_1_DEPLOYMENT"); | ||
| Console.WriteLine(" - GPT_4_1_MINI_DEPLOYMENT"); | ||
| Console.WriteLine(" - TEXT_EMBEDDING_3_LARGE_DEPLOYMENT"); | ||
| Console.WriteLine(); | ||
| } | ||
|
|
||
| // Then, retrieve current defaults to verify | ||
| Console.WriteLine("=== Retrieving Current Defaults ==="); | ||
| var getResponse = await client.GetDefaultsAsync(); | ||
| ContentUnderstandingDefaults currentDefaults = getResponse.Value; | ||
|
|
||
| Console.WriteLine("Current model deployment mappings:"); | ||
| if (currentDefaults.ModelDeployments != null && currentDefaults.ModelDeployments.Count > 0) | ||
| { | ||
| foreach (var kvp in currentDefaults.ModelDeployments) | ||
| { | ||
| Console.WriteLine($" {kvp.Key} → {kvp.Value}"); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine(" No model deployments configured yet."); | ||
| Console.WriteLine(" Run UpdateDefaults to configure model deployments."); | ||
| } | ||
| } | ||
| catch (RequestFailedException ex) | ||
| { | ||
| Console.Error.WriteLine($"Error: {ex.Message}"); | ||
| Console.Error.WriteLine($"Status: {ex.Status}"); | ||
| Console.Error.WriteLine($"Error Code: {ex.ErrorCode}"); | ||
| Environment.Exit(1); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.Error.WriteLine($"Error: {ex.Message}"); | ||
| Environment.Exit(1); | ||
| } | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
...ding/Azure.AI.ContentUnderstanding/samples/Sample00_ConfigureDefaults/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Sample00_ConfigureDefaults | ||
|
|
||
| This sample demonstrates how to configure and retrieve default model deployment settings for your Microsoft Foundry resource. | ||
| For detailed documentation, see [Sample00_ConfigureDefaults.md](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/contentunderstanding/Azure.AI.ContentUnderstanding/samples/Sample00_ConfigureDefaults.md). | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Azure subscription | ||
| - Microsoft Foundry resource | ||
| - .NET 8.0 SDK or later | ||
|
|
||
| ## Setup | ||
|
|
||
| ### Option 1: Use appsettings.json.sample | ||
|
|
||
| 1. Copy `appsettings.json.sample` from the parent `samples` directory: | ||
| ```bash | ||
| cp ../appsettings.json.sample appsettings.json | ||
| ``` | ||
|
|
||
| 2. Edit `appsettings.json` and fill in your values: | ||
| - `AZURE_CONTENT_UNDERSTANDING_ENDPOINT` (required) - Your Microsoft Foundry resource endpoint | ||
| - `AZURE_CONTENT_UNDERSTANDING_KEY` (optional) - Your API key, or leave empty to use DefaultAzureCredential | ||
|
|
||
| ### Option 2: Use Environment Variables | ||
|
|
||
| Set the following environment variables: | ||
|
|
||
| - `AZURE_CONTENT_UNDERSTANDING_ENDPOINT` (required) | ||
| - `AZURE_CONTENT_UNDERSTANDING_KEY` (optional - DefaultAzureCredential will be used if not set) | ||
|
|
||
| ## Run | ||
|
|
||
| ```bash | ||
| dotnet run | ||
| ``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.