Skip to content

Commit e1654f2

Browse files
committed
Format.
1 parent cd2e4de commit e1654f2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

site/content/blog/2025-01-07-SemanticKernel-Azure-Open-AI.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tags: [ ".NET", "AI", "Semantic Kernel" ]
1111

1212
In real-world systems, it's crucial to handle HTTP errors effectively, especially when interacting with Large Language Models (LLMs) like Azure OpenAI. Rate limit exceeded errors (tokens per minute or requests per minute) always happen at some point, resulting in 429 errors. This blog post explores different approaches to HTTP error handling with semantic kernel and Azure OpenAI.
1313

14-
** Default
14+
## Default
1515
```csharp
1616
var builder = Kernel.CreateBuilder();
1717
builder.AddAzureOpenAIChatCompletion(
@@ -21,7 +21,7 @@ builder.AddAzureOpenAIChatCompletion(
2121
```
2222
The default setup for [Semantic Kernel](https://github.com/microsoft/semantic-kernel) with Azure OpenAI by AddAzureOpenAIChatCompletion. This approach offers a built-in retry policy that automatically retries requests up to three times with exponential backoff. Additionally, it can detect specific HTTP headers like 'retry-after' to implement more tailored retries.
2323

24-
** HttpClient
24+
## HttpClient
2525
```csharp
2626
var factory = provider.GetRequiredService<IHttpClientFactory>();
2727
var httpClient = factory.CreateClient("auzre:gpt-4o");
@@ -45,7 +45,7 @@ services.AddHttpClient("auzre:gpt-4o")
4545
```
4646
An important benefit of using HttpClient is that it's not limited to Azure OpenAI. This approach works with other AI connectors like OpenAI as well.
4747

48-
** AzureOpenAIClient
48+
## AzureOpenAIClient
4949
```csharp
5050
var azureOpenAIClient = new AzureOpenAIClient(
5151
endpoint: new Uri("https://resource-name.openai.azure.com"),
@@ -68,7 +68,7 @@ var clientOptions = new AzureOpenAIClientOptions
6868
This configuration enables you to combine HTTP retry policies from HttpClient with custom pipeline policy-based retries from the Azure OpenAI SDK.
6969

7070

71-
** Recommendations
71+
## Recommendations
7272
The default setup might not be suitable for scenarios where you frequently encounter token limit issues.
7373
Using HttpClient provides more control and flexibility, making it a favorable option for broader compatibility beyond Azure OpenAI.
7474
If you already have AzureOpenAIClient registered and require maximum control, this approach allows you to leverage both HTTP client policies and Azure OpenAI pipeline policy-based retries.

0 commit comments

Comments
 (0)