"Anthropic" (Service Connection)

Use the Anthropic API with the Wolfram Language.

Connecting & Authenticating

ServiceConnect["Anthropic"] creates a connection to the Anthropic API. If a previously saved connection can be found, it will be used; otherwise, a new authentication request will be launched.
Use of this connection requires internet access and an Anthropic account.

Requests

ServiceExecute["Anthropic","request",params] sends a request to the OpenAI API using parameters params. The following gives possible requests.
Request:

"Completion" create text completion for a given prompt

Required parameters:
  • "Prompt"the prompt for which to generate completions
  • Optional parameters:
  • "MaxTokens"Automaticmaximum number of tokens to generate
    "Metadata"Automaticmetadata about the request
    "Model"Automaticname of the model to use
    "StopTokens"Noneup to four strings where the API will stop generating further tokens
    "Stream"Falsereturn the result as server-sent events
    "Temperature"Automaticsampling temperature (between 0 and 1)
    "TopProbabilities"Automaticsample only among the k highest-probability classes
    "TotalProbabilityCutoff"Nonesample among the most probable classes with an accumulated probability of at least p (nucleus sampling)
  • Request:

    "Chat" create a response for the given chat conversation

    Required parameters:
  • "Messages"a list of messages in the conversation
  • Optional parameters:
  • "MaxTokens"Automaticmaximum number of tokens to generate
    "Metadata"Automaticmetadata about the request
    "Model"Automaticname of the model to use
    "StopTokens"Noneup to four strings where the API will stop generating further tokens
    "Stream"Falsereturn the result as server-sent events
    "Temperature"Automaticsampling temperature (between 0 and 1)
    "TopProbabilities"Automaticsample only among the k highest-probability classes
    "TotalProbabilityCutoff"Nonesample among the most probable classes with an accumulated probability of at least p (nucleus sampling)
  • Examples

    open allclose all

    Basic Examples  (2)

    Create a new connection:

    Complete a piece of text:

    Generate a response from a chat:

    Scope  (2)

    Completion  (1)

    Change the sampling temperature:

    Increase the number of characters returned:

    Chat  (1)

    Respond to a chat containing multiple messages:

    Change the sampling temperature:

    Increase the number of characters returned:

    Return multiple completions: