Skip to content

Commit 569329c

Browse files
committed
tests
1 parent 67d0535 commit 569329c

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

Together.SemanticKernel/Extensions/KernelBuilderExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ public static IKernelBuilder AddTogetherChatCompletion(
1717
this IKernelBuilder builder,
1818
string model,
1919
string apiKey,
20-
string endpoint,
20+
string? endpoint = null,
2121
HttpClient? httpClient = null,
2222
string? serviceId = null)
2323
{
2424
ArgumentException.ThrowIfNullOrWhiteSpace(model);
2525

2626
builder.Services.AddKeyedSingleton<IChatCompletionService>(serviceId, (serviceProvider, _) =>
2727
new TogetherChatCompletionService(
28-
new TogetherClient(GetHttpClient(httpClient, serviceProvider), apiKey, endpoint),
28+
new TogetherClient(apiKey, GetHttpClient(httpClient, serviceProvider), endpoint),
2929
model));
3030

3131
builder.Services.AddKeyedSingleton<ITextGenerationService>(serviceId, (serviceProvider, _) =>
3232
new TogetherChatCompletionService(
33-
new TogetherClient(GetHttpClient(httpClient, serviceProvider), apiKey, endpoint),
33+
new TogetherClient(apiKey, GetHttpClient(httpClient, serviceProvider), endpoint),
3434
model));
3535

3636
return builder;
@@ -49,7 +49,7 @@ public static IKernelBuilder AddTogetherTextEmbeddingGeneration(
4949

5050
builder.Services.AddKeyedSingleton<ITextEmbeddingGenerationService>(serviceId, (serviceProvider, _) =>
5151
new TogetherTextEmbeddingGenerationService(
52-
new TogetherClient(GetHttpClient(httpClient, serviceProvider), apiKey, endpoint),
52+
new TogetherClient(apiKey, GetHttpClient(httpClient, serviceProvider), endpoint),
5353
model));
5454

5555
return builder;
@@ -68,14 +68,14 @@ public static IKernelBuilder AddTogetherTextToImage(
6868

6969
builder.Services.AddKeyedSingleton<ITextToImageService>(serviceId, (serviceProvider, _) =>
7070
new TogetherTextToImageService(
71-
new TogetherClient(GetHttpClient(httpClient, serviceProvider), apiKey, endpoint),
71+
new TogetherClient(apiKey, GetHttpClient(httpClient, serviceProvider), endpoint),
7272
model));
7373

7474
return builder;
7575
}
7676

7777
private static HttpClient GetHttpClient(HttpClient? httpClient, IServiceProvider serviceProvider)
7878
{
79-
return httpClient ?? serviceProvider.GetRequiredService<HttpClient>();
79+
return httpClient ?? serviceProvider.GetService<HttpClient>() ?? new HttpClient();
8080
}
8181
}

Together.Tests/Together.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<PrivateAssets>all</PrivateAssets>
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1919
</PackageReference>
20+
<PackageReference Include="FluentAssertions" Version="7.0.0" />
2021
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
2122
<PackageReference Include="System.Linq.Async" Version="6.0.1"/>
2223
<PackageReference Include="xunit" Version="2.9.3"/>

Together.Tests/TogetherClientIntegraionTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public class TogetherClientIntegraionTests
1414

1515
private TogetherClient CreateTogetherClient()
1616
{
17-
var httpClient = new HttpClient();
18-
httpClient.Timeout = TimeSpan.FromSeconds(TogetherConstants.TIMEOUT_SECS);
19-
return new TogetherClient(httpClient, API_KEY);
17+
return new TogetherClient(API_KEY);
2018
}
2119

2220
[Fact

Together/TogetherClient.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ public class TogetherClient
77
private readonly HttpClient _httpClient;
88
private const string BaseUrl = "https://api.together.xyz/";
99

10-
public TogetherClient(HttpClient httpClient, string apiKey, string baseUrl = null)
10+
public TogetherClient(string apiKey) : this(apiKey, new HttpClient()
1111
{
12-
_httpClient = new HttpClient
13-
{
14-
BaseAddress = new Uri(baseUrl ?? BaseUrl)
15-
};
12+
Timeout = TimeSpan.FromSeconds(TogetherConstants.TIMEOUT_SECS)
13+
})
14+
{
15+
}
16+
17+
public TogetherClient(string apiKey, HttpClient httpClient, string baseUrl = BaseUrl)
18+
{
19+
_httpClient = httpClient;
20+
_httpClient.BaseAddress = new Uri(baseUrl);
1621
_httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
1722

1823
Completions = new CompletionClient(_httpClient);

0 commit comments

Comments
 (0)