"TogetherAI" (服务连接)
连接该服务需要访问 LLM »
连接与认证
ServiceConnect["TogetherAI"] 创建与 Together AI API 的连接. 如果可以找到之前保存的连接,则将使用该连接;否则,将发起新的身份认证请求.
请求
文本
| "Prompt" | (必需) | 为其生成补全的提示 | |
| "MaxTokens" | Automatic | 最多生成多少个词元 | |
| "Model" | Automatic | 使用的模型的名称 | |
| "N" | Automatic | 返回多少个补全 | |
| "SafetyModel" | Automatic | 使用的审核模型;可能的值包括 "Meta-Llama/Llama-Guard-7b" | |
| "StopTokens" | Automatic | 用来指示 API 停止生成更多词元的字符串 | |
| "Temperature" | Automatic | 采样温度 | |
| "TotalProbabilityCutoff" | Automatic | 温度采样的替代方法,称为核心采样,模型只考虑具有所要求的概率质量的词元 |
| "Messages" | (必需) | 对话中的消息列表,用 "Role" 和 "Content" 为键的关联给出每条消息 | |
| "MaxTokens" | Automatic | 最多生成多少个词元 | |
| "Model" | Automatic | 使用的模型的名称 | |
| "N" | Automatic | 返回多少个聊天补全 | |
| "SafetyModel" | Automatic | 使用的审核模型;可能的值包括 "Meta-Llama/Llama-Guard-7b" | |
| "StopTokens" | Automatic | 用来指示 API 停止生成更多词元的字符串 | |
| "Stream" | False | 将结果作为服务器发送的事件返回 | |
| "Temperature" | Automatic | 采样温度 | |
| "ToolChoice" | Automatic | 模型调用哪个工具(如果有) | |
| "Tools" | Automatic | 模型可用的一个或多个 LLMTool 对象 | |
| "TopProbabilities" | Automatic | 只在 k 个概率最高的类别中采样 | |
| "TotalProbabilityCutoff" | Automatic | 温度采样的替代方法,称为核心采样,模型只考虑具有所要求的概率质量的词元 |
| "Input" | (必需) | 要为其创建嵌入向量的一个或一组文本 | |
| "Model" | Automatic | 使用的模型的名称 |
图像
"ImageCreate" — 给定提示,创建一个正方形的图片
| "Prompt" | (必需) | 所需图像的文字描述 | |
| "Model" | Automatic | 使用的模型的名称 | |
| "N" | Automatic | 生成多少幅图像 | |
| "Seed" | Automatic | 用于生成图像的种子 | |
| "Size" | Automatic | 生成图像的大小 | |
| "Steps" | Automatic | 迭代的次数 |
模型列表
"ChatModelList" — 列出 "Chat" 请求可用的模型
"CompletionModelList" — 列出 "Completion" 请求可用的模型
范例
打开所有单元 关闭所有单元基本范例 (1)
togetherAI = ServiceConnect["TogetherAI"]ServiceExecute[togetherAI, "Completion", {"Prompt" -> "What is the capital of France?"}]ServiceExecute[togetherAI, "Chat", {"Messages" -> {<|"Role" -> "User", "Content" -> "Hello there!"|>}}]ServiceExecute[togetherAI, "Embedding", {"Input" -> "The quick brown fox ..."}]根据提示生成 Image:
ServiceExecute[togetherAI, "ImageCreate", {"Prompt" -> "A cat in a hat"}]范围 (7)
文本 (5)
补全 (1)
聊天 (1)
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?"|>
}}]允许模型使用 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]}}]CompletionModelList (1)
参见
ServiceExecute ▪ ServiceConnect ▪ LLMFunction ▪ LLMSynthesize ▪ ChatEvaluate ▪ ChatObject ▪ LLMConfiguration ▪ ImageSynthesize
服务连接: AlephAlpha ▪ Anthropic ▪ Cohere ▪ DeepSeek ▪ GoogleGemini ▪ Groq ▪ MistralAI ▪ OpenAI