Microsoft.Extensions.AI Integration
The tryAGI.Together SDK implements both IChatClient and IEmbeddingGenerator interfaces from Microsoft.Extensions.AI, enabling you to use Together AI models through standardized .NET AI abstractions.
Namespace Conflict
This SDK has a generated IChatClient interface that conflicts with Microsoft.Extensions.AI.IChatClient. Use the Meai alias pattern shown below.
Supported Interfaces
| Interface |
Support Level |
IChatClient |
Full (text, streaming, tool calling, reasoning) |
IEmbeddingGenerator<string, Embedding<float>> |
Full |
IChatClient
Installation
| dotnet add package tryAGI.Together
|
Basic Usage
Because the SDK generates its own IChatClient interface, you must use a namespace alias:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 | using Together;
using Meai = Microsoft.Extensions.AI;
using var client = new TogetherClient(apiKey);
Meai.IChatClient chatClient = client;
var response = await chatClient.GetResponseAsync(
"What is the capital of France?",
new Meai.ChatOptions
{
ModelId = "meta-llama/Llama-3.3-70B-Instruct-Turbo",
});
Console.WriteLine(response.Text);
|
Streaming
1
2
3
4
5
6
7
8
9
10
11
12
13 | using Meai = Microsoft.Extensions.AI;
Meai.IChatClient chatClient = client;
await foreach (var update in chatClient.GetStreamingResponseAsync(
"Write a short poem about coding.",
new Meai.ChatOptions
{
ModelId = "meta-llama/Llama-3.3-70B-Instruct-Turbo",
}))
{
Console.Write(update.Text);
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 | using CSharpToJsonSchema;
using Meai = Microsoft.Extensions.AI;
[GenerateJsonSchema]
public interface IWeatherTools
{
[Description("Gets the current weather for a location.")]
string GetWeather(
[Description("The city name")] string city);
}
Meai.IChatClient chatClient = client;
var service = new WeatherToolsService();
var response = await chatClient.GetResponseAsync(
"What's the weather in Paris?",
new Meai.ChatOptions
{
ModelId = "meta-llama/Llama-3.3-70B-Instruct-Turbo",
Tools = service.AsTools().AsAITools(),
});
|
When using the Meai alias, call extension methods explicitly:
| var metadata = Meai.ChatClientExtensions.GetService<Meai.ChatClientMetadata>(chatClient);
var self = Meai.ChatClientExtensions.GetService<TogetherClient>(chatClient);
|
IEmbeddingGenerator
Basic Usage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 | using Together;
using Meai = Microsoft.Extensions.AI;
using var client = new TogetherClient(apiKey);
Meai.IEmbeddingGenerator<string, Meai.Embedding<float>> generator = client;
var embeddings = await generator.GenerateAsync(
["Hello, world!", "How are you?"],
new Meai.EmbeddingGenerationOptions
{
ModelId = "BAAI/bge-large-en-v1.5",
});
foreach (var embedding in embeddings)
{
Console.WriteLine($"Dimensions: {embedding.Vector.Length}");
}
|