Together.AI 1.3.1

dotnet add package Together.AI --version 1.3.1
NuGet\Install-Package Together.AI -Version 1.3.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Together.AI" Version="1.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Together.AI --version 1.3.1
#r "nuget: Together.AI, 1.3.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Together.AI as a Cake Addin
#addin nuget:?package=Together.AI&version=1.3.1

// Install Together.AI as a Cake Tool
#tool nuget:?package=Together.AI&version=1.3.1

Together Homepage

Together Homepage Nuget Nuget GitHub License

A unofficial .NET client for Together's API platform.

Getting started:

Prerequisites

If you'd like to use the Together.AI .NET client library you'll need an API key from a developer account at Together's API.

Install the package

Install the client library for .NET with NuGet:

dotnet add package Together.AI

Authenticate the client

In order to interact with Together's API, you'll need to create an instance of the IHttpClient class that points to Together's api endpoint URI using a valid Authorization API key.

The easiest way to do this is by using the SetupClient extension method.

using Together.AI;

var client = new HttpClient();
client.SetupClient(apiKey: "your-api-key-from-together");

Then creates a instance of TogetherAIClient using the configured HttpClient.

var togetherAI = new TogetherAIClient(client);

Start Querying

Getting completion results

To simply get text completion results, you can use the GetCompletionsAsync method.

using Together.AI;

// ...

// Setup Request Arguments
var togetherAIArgs = new TogetherAIRequestArgs()
{
    Model = "togethercomputer/RedPajama-INCITE-7B-Instruct",
    MaxTokens = 128,
    Prompt = "Alan Turing was "
};

var result = await togetherAI.GetCompletionsAsync(togetherAIArgs);

// Print generated text
Console.WriteLine(result?.Choices?.First().Text);

Streaming tokens

To get tokens as the model generates, you can use the GetCompletionsStreamAsync method.

using Together.AI;

// ...

var togetherAIArgs = new TogetherAIRequestArgs()
{
    Model = MODEL_ID,
    MaxTokens = 128,
    Prompt = "Alan Turing was "
};

await foreach (var streamResult in togetherAI.GetCompletionsStreamAsync(togetherAIArgs))
{
    var token = streamResult.Choices.First().Text;

    // Print generated token
    Console.Write(token);
}

Getting embeddings

To simply get text embedding results, you can use the GetEmbeddingsAsync method.

using Together.AI;

// ...

// Setup Request Arguments
var togetherAIArgs = new TogetherAIEmbeddingsRequestArgs()
{
    Model = MODEL_ID,
    Input = "Our solar system orbits the Milky Way galaxy at about 515,000 mph"
};

// Getting result
var result = await togetherAI.GetEmbeddingsAsync(togetherAIArgs);

// Print generated embeddings
foreach (var token in result?.Data?.First()?.Values ?? [])
{
    Console.Write(token);
}

Getting chat completions

To simply get chat completion results, you can use the GetChatCompletionsAsync method.

using Together.AI;

// ...

// Creating a message history
var messages = new List<TogetherAIChatMessage>() {
    new TogetherAIChatSystemMessage("You are a helpful travel agent."),
    new TogetherAIChatUserMessage("Tell me about San Francisco.")
};

// Setup Request Arguments
var togetherAIArgs = new TogetherAIChatCompletionArgs
{
    Model = "mistralai/Mixtral-8x7B-Instruct-v0.1",
    Messages = messages,
    MaxTokens = 512,
    Stop = new string[]{
        "</s>",
        "[/INST]"
    },
};

var result = await togetherAI.GetChatCompletionsAsync(chatArgs);

if (result?.Choices?.FirstOrDefault()?.Message?.Content is string content)
{
    messages.Add(new TogetherAIChatAssistantMessage(content));
}

// Printing out the chat results
messages.ForEach(Console.WriteLine);

Function calling

The GetChatCompletionsAsync method, can also be used to function calling. Like the following Example

Examples

Looking for Grammar errors

using Together.AI;

const string API_KEY = "your-api-key-from-together";
const string MODEL_ID = "Open-Orca/Mistral-7B-OpenOrca";
const string PROMPT_TEMPLATE =
    "<|im_start|> system\nDoes the text contain grammar errors? Answer with (Y/N)\n\n'{{$input}}'\n<|im_end|>\n<|im_start|> assistant\n";

var client = new HttpClient();
client.SetupClient(apiKey: API_KEY);

var togetherAI = new TogetherAIClient(client);

var promptInput = PROMPT_TEMPLATE.Replace(
    oldValue: "{{$input}}",
    newValue: "I mised the training session this morning"
);

var togetherAIArgs = new TogetherAIRequestArgs()
{
    Model = MODEL_ID,
    MaxTokens = 8,
    Prompt = promptInput
};

var result = await togetherAI.GetCompletionsAsync(togetherAIArgs);

Console.WriteLine(result?.Choices?.First().Text);

// Result: 'Y'

More examples can be found in the Examples folder

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Together.AI:

Package Downloads
Together.AI.SemanticKernel

A unofficial .NET Semantic Kernel integration for Together's API platform, providing a convenient way for interacting with the Together APIs and enables easy integration of the inference API with your applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.1 103 4/1/2024
1.3.0 179 3/27/2024
1.2.0 89 3/24/2024
1.1.3 75 3/20/2024
1.1.2 87 3/20/2024
1.1.1 66 3/20/2024
1.1.0 129 2/17/2024
1.0.2 128 11/24/2023
1.0.1 119 11/23/2023
1.0.0.1 99 11/22/2023