"TogetherAI" (Service Connection)
Connecting & Authenticating
Requests
Text
"Completion" — create text completion for a given prompt
| "Prompt" | (required) | the prompt for which to generate completions | |
| "MaxTokens" | Automatic | maximum number of tokens to generate | |
| "Model" | Automatic | name of the model to use | |
| "N" | Automatic | number of completions to return | |
| "SafetyModel" | Automatic | moderation model to use; possible values include "Meta-Llama/Llama-Guard-7b" | |
| "StopTokens" | Automatic | strings where the API will stop generating further tokens | |
| "Temperature" | Automatic | sampling temperature | |
| "TotalProbabilityCutoff" | Automatic | an alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with the requested probability mass |
"Chat" — create a response for the given chat conversation
| "Messages" | (required) | a list of messages in the conversation, each given as an association with "Role" and "Content" keys | |
| "MaxTokens" | Automatic | maximum number of tokens to generate | |
| "Model" | Automatic | name of the model to use | |
| "N" | Automatic | number of completions to return | |
| "SafetyModel" | Automatic | moderation model to use; possible values include "Meta-Llama/Llama-Guard-7b" | |
| "StopTokens" | Automatic | strings where the API will stop generating further tokens | |
| "Stream" | False | return the result as server-sent events | |
| "Temperature" | Automatic | sampling temperature | |
| "ToolChoice" | Automatic | which (if any) tool is called by the model | |
| "Tools" | Automatic | one or more LLMTool objects available to the model | |
| "TopProbabilities" | Automatic | sample only among the k highest-probability classes | |
| "TotalProbabilityCutoff" | Automatic | an alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with the requested probability mass |
"Embedding" — create an embedding vector representing the input text
| "Input" | (required) | one or a list of texts to get embeddings for | |
| "Model" | Automatic | name of the model to use |
Image
"ImageCreate" — create a square image given a prompt
| "Prompt" | (required) | text description of the desired image | |
| "Model" | Automatic | name of the model to use | |
| "N" | Automatic | number of images to generate | |
| "Seed" | Automatic | seed for the image generation | |
| "Size" | Automatic | size of the generated image | |
| "Steps" | Automatic | number of iterations |
Model Lists
"ChatModelList" — list models available for the "Chat" request
"CompletionModelList" — list models available for the "Completion" request
"EmbeddingModelList" — list models available for the "Embedding" request
"ImageModelList" — list models available for the "ImageCreate" request
Examples
open all close allBasic Examples (1)
togetherAI = ServiceConnect["TogetherAI"]ServiceExecute[togetherAI, "Completion", {"Prompt" -> "What is the capital of France?"}]Generate a response from a chat:
ServiceExecute[togetherAI, "Chat", {"Messages" -> {<|"Role" -> "User", "Content" -> "Hello there!"|>}}]Compute the embedding for a sentence:
ServiceExecute[togetherAI, "Embedding", {"Input" -> "The quick brown fox ..."}]Generate an Image from a prompt:
ServiceExecute[togetherAI, "ImageCreate", {"Prompt" -> "A cat in a hat"}]Scope (7)
Text (5)
Completion (1)
Change the sampling temperature:
ServiceExecute["TogetherAI", "Completion", {"Prompt" -> "Three colors are: ", "Temperature" -> 1, "MaxTokens" -> 20}]Increase the number of characters returned:
ServiceExecute["TogetherAI", "Completion", {"Prompt" -> "Three colors are: ", "Temperature" -> 1, "MaxTokens" -> 60}]Chat (1)
Respond to a chat containing multiple messages:
ServiceExecute["TogetherAI", "Chat", {"Messages" -> {
<|"Role" -> "User", "Content" -> "What's the tallest mountain?"|>,
<|"Role" -> "Assistant", "Content" -> "The highest mountain in the world is Mount Everest."|>,
<|"Role" -> "User", "Content" -> "How tall is it?"|>
}}]Allow the model to use an LLMTool:
ServiceExecute["TogetherAI", "Chat", {"Model" -> "mistralai/Mixtral-8x7B-Instruct-v0.1", "Messages" -> {<|"Role" -> "User", "Content" -> "Tell me what today's date is and then tell me how long this message is."|>}, "Tools" -> {LLMTool["countcharacter", "string", StringLength[#string]&], LLMTool[{"getDate", "Get the current date"}, {}, DateString]}}]ChatModelList (1)
CompletionModelList (1)
See Also
ServiceExecute ▪ ServiceConnect ▪ LLMFunction ▪ LLMSynthesize ▪ ChatEvaluate ▪ ChatObject ▪ LLMConfiguration ▪ ImageSynthesize
Service Connections: AlephAlpha ▪ Anthropic ▪ Cohere ▪ DeepSeek ▪ GoogleGemini ▪ Groq ▪ MistralAI ▪ OpenAI
History
Introduced in 2024 (14.1)