-
Notifications
You must be signed in to change notification settings - Fork 6k
Updates to show exception handling and more protocol method examples #42723
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
74bdc02
code and content updates
alexwolfmsft e0cb568
fix version
alexwolfmsft e318444
build fixes
alexwolfmsft 8d89d0f
fix build
alexwolfmsft acb39a4
fix links
alexwolfmsft b8f01c1
Apply suggestions from code review
alexwolfmsft d77fa01
Apply suggestions from code review
alexwolfmsft ba76e85
highlights
alexwolfmsft 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
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
15 changes: 15 additions & 0 deletions
15
...pets/protocol-convenience-methods/AzureCore/ExceptionHandling/AzureCoreConvenience.csproj
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,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 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,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 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
21 changes: 21 additions & 0 deletions
21
docs/azure/sdk/snippets/protocol-convenience-methods/SCM/ExceptionHandling/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,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 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 @@ | ||
<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 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
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
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.