forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to show exception handling and more protocol method examples (d…
…otnet#42723) Adding new exception handling documentation --------- Co-authored-by: Scott Addie <[email protected]>
- Loading branch information
1 parent
824bde0
commit 0f2ea15
Showing
9 changed files
with
99 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
15 changes: 15 additions & 0 deletions
15
...pets/protocol-convenience-methods/AzureCore/ExceptionHandling/AzureCoreConvenience.csproj
This file contains 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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Azure.AI.ContentSafety" /> | ||
<PackageReference Include="Azure.Identity" /> | ||
</ItemGroup> | ||
|
||
</Project> |
24 changes: 24 additions & 0 deletions
24
docs/azure/sdk/snippets/protocol-convenience-methods/AzureCore/ExceptionHandling/Program.cs
This file contains 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,24 @@ | ||
using Azure.AI.ContentSafety; | ||
using Azure.Identity; | ||
using Azure; | ||
|
||
// Create the client | ||
ContentSafetyClient client = new( | ||
new Uri("https://contentsafetyai.cognitiveservices.azure.com/"), | ||
new DefaultAzureCredential()); | ||
|
||
try | ||
{ | ||
// Call the convenience method | ||
AnalyzeTextResult result = client.AnalyzeText("What is Microsoft Azure?"); | ||
|
||
// Display the results | ||
foreach (TextCategoriesAnalysis item in result.CategoriesAnalysis) | ||
{ | ||
Console.WriteLine($"{item.Category}: {item.Severity}"); | ||
} | ||
} | ||
catch (RequestFailedException ex) | ||
{ | ||
Console.WriteLine($"Error: {ex.Message}"); | ||
} |
This file contains 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
21 changes: 21 additions & 0 deletions
21
docs/azure/sdk/snippets/protocol-convenience-methods/SCM/ExceptionHandling/Program.cs
This file contains 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,21 @@ | ||
using OpenAI.Chat; | ||
using System.ClientModel; | ||
|
||
// Create the client | ||
ChatClient client = new( | ||
model: "gpt-4o-mini", | ||
credential: Environment.GetEnvironmentVariable("OPENAI_API_KEY")!); | ||
|
||
try | ||
{ | ||
// Call the convenience method | ||
ChatCompletion completion = client.CompleteChat("What is Microsoft Azure?"); | ||
|
||
// Display the results | ||
Console.WriteLine($"[{completion.Role}]: {completion}"); | ||
} | ||
catch (ClientResultException ex) | ||
{ | ||
Console.WriteLine($"Error: {ex.Message}"); | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
...ure/sdk/snippets/protocol-convenience-methods/SCM/ExceptionHandling/SCMConvenience.csproj
This file contains 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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="OpenAI" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains 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
This file contains 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