Skip to content

Merge main into live #42774

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 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions docs/azure/includes/dotnet-all.md

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions docs/azure/includes/dotnet-new.md

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion docs/azure/sdk/protocol-convenience-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ The preceding code demonstrates the following `System.ClientModel` convenience m

The following code uses a `ChatClient` to call the `CompleteChat` protocol method:

:::code source="snippets/protocol-convenience-methods/SCM/Protocol/Program.cs" highlight="26-31":::
:::code source="snippets/protocol-convenience-methods/SCM/Protocol/Program.cs" highlight="31-34":::

The preceding code demonstrates the following `System.ClientModel` protocol method patterns:

Expand Down Expand Up @@ -129,6 +129,20 @@ PipelineResponse response = result.GetRawResponse();

---

## Handle exceptions

When a service call fails, the service client throws an exception that exposes the HTTP status code and the details of the service response, if available. A `System.ClientModel`-dependent library throws a <xref:System.ClientModel.ClientResultException>, while an `Azure.Core`-dependent library throws a <xref:Azure.RequestFailedException>.

# [System.ClientModel exceptions](#tab/system-clientmodel)

:::code source="snippets/protocol-convenience-methods/AzureCore/ExceptionHandling/Program.cs" highlight="21-24":::

# [Azure.Core exceptions](#tab/azure-core)

:::code source="snippets/protocol-convenience-methods/SCM/ExceptionHandling/Program.cs" highlight="17-20":::

---

## Protocol and convenience method usage guidance

Although the Azure SDK for .NET client libraries provide the option to use either protocol or convenience methods, prioritize using convenience methods in most scenarios. Convenience methods are designed to improve the development experience and provide flexibility for authoring requests and handling responses. However, both method types can be used in your app as needed. Consider the following criteria when deciding which type of method to use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
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>
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}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
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}");
}

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>
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
"""u8.ToArray());
using BinaryContent content = BinaryContent.Create(input);

var requestOptions = new RequestOptions();

requestOptions.AddHeader("CustomHeader", "CustomHeaderValue");
requestOptions.ErrorOptions = ClientErrorBehaviors.NoThrow;

// Call the protocol method
ClientResult result = client.CompleteChat(
content,
new RequestOptions
{
ErrorOptions = ClientErrorBehaviors.NoThrow,
});
requestOptions
);

PipelineResponse response = result.GetRawResponse();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
5 changes: 4 additions & 1 deletion docs/core/docker/build-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ If you pass a number on the command line to the app, it will only count up to th

## Publish .NET app

Before adding the .NET app to the Docker image, first it must be published. It's best to have the container run the published version of the app. To publish the app, run the following command:
In order for the app to be suitable for an image creation it has to be built. The `dotnet publish` command is most apt for this, as it builds and publishes the app. For an in-depth reference, see [dotnet build](/dotnet/core/tools/dotnet-build) and [dotnet publish](/dotnet/core/tools/dotnet-publish) commands documentation.

```dotnetcli
dotnet publish -c Release
Expand All @@ -141,6 +141,9 @@ This command compiles your app to the *publish* folder. The path to the *publish

This command compiles your app to the *publish* folder. The path to the *publish* folder from the working folder should be `.\App\bin\Release\net7.0\publish\`.

> [!NOTE]
> Application publishing is needed for image creation but this is rather orchestrated by the _Dockerfile_. See [Create the Dockerfile](#create-the-dockerfile).

:::zone-end

#### [Windows](#tab/windows)
Expand Down
6 changes: 6 additions & 0 deletions docs/core/tools/dotnet-tool-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Global tools are installed in the following directories by default when you spec

Executables are generated in these folders for each globally installed tool, although the actual tool binaries are nested deep into the sibling `.store` directory.

> [!NOTE]
> On Linux after installing a command-line tool with `dotnet tool`, the tool can be executed only from the `$HOME/.dotnet/tools` path.
> To make the tool executable from any directory, update the `PATH` environment variable.
> To make the updated `PATH` environment variable permanent in your shell, update your shell settings.
> For `Bash`, this is the `$HOME/.bashrc` file.

### `--tool-path` tools

Tools with explicit tool paths are stored wherever you specified the `--tool-path` parameter to point to. They're stored in the same way as global tools: an executable binary with the actual binaries in a sibling `.store` directory.
Expand Down
Loading