-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Connectors_CustomHttpClient.cs
39 lines (34 loc) · 1.35 KB
/
Connectors_CustomHttpClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.SemanticKernel;
namespace ChatCompletion;
// These examples show how to use a custom HttpClient with SK connectors.
public class Connectors_CustomHttpClient(ITestOutputHelper output) : BaseTest(output)
{
/// <summary>
/// Demonstrates the usage of the default HttpClient provided by the SK SDK.
/// </summary>
[Fact]
public void UseDefaultHttpClient()
{
var kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: TestConfiguration.OpenAI.ChatModelId,
apiKey: TestConfiguration.OpenAI.ApiKey) // If you need to use the default HttpClient from the SK SDK, simply omit the argument for the httpMessageInvoker parameter.
.Build();
}
/// <summary>
/// Demonstrates the usage of a custom HttpClient.
/// </summary>
[Fact]
public void UseCustomHttpClient()
{
using var httpClient = new HttpClient();
// If you need to use a custom HttpClient, simply pass it as an argument for the httpClient parameter.
var kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: TestConfiguration.OpenAI.ModelId,
apiKey: TestConfiguration.OpenAI.ApiKey,
httpClient: httpClient)
.Build();
}
}