Note: Use the Meai alias because the Together SDK has its own generated IChatClient interface.
Chat Client Five Random Words Streaming
1 2 3 4 5 6 7 8 91011121314151617181920
usingvarclient=newTogetherClient(apiKey);Meai.IChatClientchatClient=client;varupdates=chatClient.GetStreamingResponseAsync([ new Meai.ChatMessage(Meai.ChatRole.User, "Generate 5 random words.") ],newMeai.ChatOptions{ModelId="meta-llama/Llama-3-8b-chat-hf",});vardeltas=newList<string>();awaitforeach(varupdateinupdates){if(!string.IsNullOrWhiteSpace(update.Text)){deltas.Add(update.Text);}}
Chat Client Five Random Words
1 2 3 4 5 6 7 8 91011
usingvarclient=newTogetherClient(apiKey);Meai.IChatClientchatClient=client;varresponse=awaitchatClient.GetResponseAsync([ new Meai.ChatMessage(Meai.ChatRole.User, "Generate 5 random words.") ],newMeai.ChatOptions{ModelId="meta-llama/Llama-3-8b-chat-hf",});
Chat Client Get Service Returns Chat Client Metadata
usingvarclient=newTogetherClient(apiKey);Meai.IChatClientchatClient=client;varresponse=awaitchatClient.GetResponseAsync([new Meai.ChatMessage(Meai.ChatRole.User, "What is 25 * 37? Think step by step.")],newMeai.ChatOptions{ModelId="deepseek-ai/DeepSeek-R1",});varreasoning=response.Messages.SelectMany(m=>m.Contents).OfType<Meai.TextReasoningContent>().ToList();vartext=response.Messages.SelectMany(m=>m.Contents).OfType<Meai.TextContent>().ToList();// DeepSeek-R1 should produce reasoning content
usingvarclient=newTogetherClient(apiKey);Meai.IChatClientchatClient=client;vargetWeatherTool=AIFunctionFactory.Create((stringlocation)=>$"The weather in {location} is sunny, 72°F","GetWeather","Gets the current weather for a location");varmessages=newList<Meai.ChatMessage>{new(Meai.ChatRole.User,"What's the weather in Seattle?"),};varoptions=newMeai.ChatOptions{ModelId="meta-llama/Llama-3.3-70B-Instruct-Turbo",Tools=[getWeatherTool],};// First turn: model should call the toolvarresponse=awaitchatClient.GetResponseAsync(messages,options);varfunctionCall=response.Messages.SelectMany(m=>m.Contents).OfType<FunctionCallContent>().FirstOrDefault();// Add assistant response with tool call and tool resultmessages.AddRange(response.Messages);vartoolResult=awaitgetWeatherTool.InvokeAsync(functionCall!.Argumentsis{}args?newAIFunctionArguments(args):null);messages.Add(newMeai.ChatMessage(Meai.ChatRole.Tool,[ new FunctionResultContent(functionCall.CallId, toolResult),]));// Second turn: model should respond with the weather infovarfinalResponse=awaitchatClient.GetResponseAsync(messages,options);
Chat Client Tool Calling Single Turn
1 2 3 4 5 6 7 8 91011121314151617181920
usingvarclient=newTogetherClient(apiKey);Meai.IChatClientchatClient=client;vargetWeatherTool=AIFunctionFactory.Create((stringlocation)=>$"The weather in {location} is sunny, 72°F","GetWeather","Gets the current weather for a location");varresponse=awaitchatClient.GetResponseAsync([new Meai.ChatMessage(Meai.ChatRole.User, "What's the weather in Seattle?")],newMeai.ChatOptions{ModelId="meta-llama/Llama-3.3-70B-Instruct-Turbo",Tools=[getWeatherTool],});varfunctionCall=response.Messages.SelectMany(m=>m.Contents).OfType<FunctionCallContent>().FirstOrDefault();
Chat Client Tool Calling Streaming
1 2 3 4 5 6 7 8 9101112131415161718192021
usingvarclient=newTogetherClient(apiKey);Meai.IChatClientchatClient=client;vargetWeatherTool=AIFunctionFactory.Create((stringlocation)=>$"The weather in {location} is sunny, 72°F","GetWeather","Gets the current weather for a location");varupdates=chatClient.GetStreamingResponseAsync([new Meai.ChatMessage(Meai.ChatRole.User, "What's the weather in Seattle?")],newMeai.ChatOptions{ModelId="meta-llama/Llama-3.3-70B-Instruct-Turbo",Tools=[getWeatherTool],});varfunctionCalls=newList<FunctionCallContent>();awaitforeach(varupdateinupdates){functionCalls.AddRange(update.Contents.OfType<FunctionCallContent>());}