"Cohere" (Service Connection)
Connecting & Authenticating
Requests
"TestConnection" — returns Success for working connection, Failure otherwise
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 | |
| "FrequencyPenalty" | Automatic | penalize tokens based on their existing frequency in the text so far (between -2 and 2) | |
| "Model" | Automatic | name of the model to use | |
| "N" | Automatic | number of completions to return | |
| "PresencePenalty" | Automatic | penalize new tokens based on whether they appear in the text so far | |
| "StopTokens" | Automatic | strings where the API will stop generating further tokens | |
| "Stream" | False | return the result as server-sent events | |
| "Temperature" | Automatic | sampling temperature | |
| "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 |
"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 | |
| "StopTokens" | Automatic | strings where the API will stop generating further tokens | |
| "Stream" | False | return the result as server-sent events | |
| "Temperature" | Automatic | sampling temperature | |
| "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 text or a list of texts to get embeddings for | |
| "Model" | Automatic | name of the model to use |
Model Lists
"ChatModelList" — list models available for the "Chat" request
"EmbeddingModelList" — list models available for the "Embedding" request
Examples
open all close allBasic Examples (1)
cohere = ServiceConnect["Cohere"]ServiceExecute[cohere, "Completion", {"Prompt" -> "Hello there!"}]Generate a response from a chat:
ServiceExecute[cohere, "Chat", {"Messages" -> {<|"Role" -> "User", "Content" -> "Hello there!"|>}}]Compute the embedding for a sentence:
ServiceExecute[cohere, "Embedding", {"Input" -> "The quick brown fox ..."}]Scope (5)
Connection (1)
Text (4)
Completion (1)
Chat (1)
Respond to a chat containing multiple messages:
ServiceExecute["Cohere", "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:
tool = LLMTool[{"countCharacter", "count the number of characters in a string"}, "string", StringLength[#string]&]ServiceExecute["Cohere", "Chat", {"Model" -> "command-r", "Messages" -> {<|"Role" -> "User", "Content" -> "Please tell me how long this message is"|>}, "Tools" -> tool}]ChatModelList (1)
See Also
ServiceExecute ▪ ServiceConnect ▪ LLMFunction ▪ LLMSynthesize ▪ ChatEvaluate ▪ LLMConfiguration
Service Connections: AlephAlpha ▪ Anthropic ▪ DeepSeek ▪ GoogleGemini ▪ Groq ▪ MistralAI ▪ OpenAI ▪ TogetherAI
History
Introduced in 2024 (14.1)