WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

ChatSubmit [chat,prompt]

submits prompt to be appended with its follow-ups to the ChatObject chat asynchronously.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Options  
Authentication  
HandlerFunctions  
HandlerFunctionsKeys  
LLMEvaluator  
Applications  
Tool Calling  
See Also
Related Guides
History
Cite this Page

ChatSubmit [chat,prompt]

submits prompt to be appended with its follow-ups to the ChatObject chat asynchronously.

Details and Options

  • ChatSubmit is used to continue the conversation in a ChatObject asynchronously.
  • ChatSubmit requires external service authentication, billing and internet connectivity.
  • Possible values for prompt include:
  • "text" static text
    LLMPrompt ["name"] a repository prompt
    StringTemplate [] templated text
    TemplateObject [] template for creating a prompt
    Image [] an image
    {prompt1,} a list of prompts
  • Prompt created with TemplateObject can contain text and images. Not every LLM supports image input.
  • ChatSubmit returns a TaskObject [].
  • The following options can be specified:
  • Authentication Inherited authentication scheme
    HandlerFunctions how to handle generated events
    HandlerFunctionsKeys Automatic parameters to supply to handler functions
    LLMEvaluator Inherited LLM configuration to use
  • During the asynchronous execution of ChatSubmit , various events can be generated.
  • Events triggered by the LLM:
  • "ContentChunkReceived" incremental message content received
    "StoppingReasonReceived" stopping reason for the generation received
    "MetadataReceived" other metadata received
    "ToolRequestReceived" LLMToolRequest [] received
    "UsageInformationReceived" incremental usage information received
  • Events triggered by local processing:
  • "ChatObjectGenerated" the final ChatObject [] generated
    "ToolResponseGenerated" an LLMToolResponse [] generated
  • Events triggered by the task framework:
  • "FailureOccurred" failure generated during the computation
    "TaskFinished" task completely finished
    "TaskRemoved" task being removed
    "TaskStarted" task started
    "TaskStatusChanged" task status changed
  • HandlerFunctions f uses f for all the events.
  • With the specification HandlerFunctions -><|,"eventi"->fi,|>, fi[assoc] is evaluated whenever eventi is generated. The elements of assoc have keys specified by the setting for HandlerFunctionsKeys .
  • Possible keys specified by HandlerFunctionsKeys include:
  • "ChatObject" modified ChatObject []
    "ContentChunk" a message part
    "EventName" the name of the event being handled
    "Failure" failure object generated if task failed
    "Model" model used to generate the message
    "Role" role of the message author
    "StoppingReason" why the generation has stopped
    "Task" the task object generated by ChatSubmit
    "TaskStatus" the status of the task
    "TaskUUID" unique task identifier
    "Timestamp" timestamp of the message
    "ToolRequest" received LLMToolRequest []
    "ToolResponse" last generated LLMToolResponse []
    "UsageIncrement" token usage update
    {key1,} a list of keys
    All all the keys
    Automatic keys lexically present in HandlerFunctions
  • Values that have not yet been received are given as Missing ["NotAvailable"].
  • If LLMEvaluator is set to Inherited , the LLM configuration specified in chat is used.
  • LLMEvaluator can be set to an LLMConfiguration object or an association with any of the following keys:
  • "MaxTokens" maximum amount of tokens to generate
    "Model" base model
    "PromptDelimiter" string to insert between prompts
    "Prompts" initial prompts or LLMPromptGenerator objects
    "StopTokens" tokens on which to stop generation
    "Temperature" sampling temperature
    "ToolMethod" method to use for tool calling
    "Tools" list of LLMTool objects to make available
    "TopProbabilities" sampling classes cutoff
    "TotalProbabilityCutoff" sampling probability cutoff (nucleus sampling)
  • Valid forms of "Model" include:
  • name named model
    {service,name} named model from service
    <|"Service"service,"Name"name|> fully specified model
  • Prompts specified in "Prompts" are prepended to the messages in chat with role set as "System".
  • Multiple prompts are separated by the "PromptDelimiter" property.
  • The generated text is sampled from a distribution. Details of the sampling can be specified using the following properties of the LLMEvaluator :
  • "Temperature"t Automatic sample using a positive temperature t
    "TopProbabilities"k Automatic sample only among the k highest-probability classes
    "TotalProbabilityCutoff"p Automatic sample among the most probable choices with an accumulated probability of at least p (nucleus sampling)
  • The Automatic value of these parameters uses the default for the specified "Model".
  • Possible values for "ToolMethod" include:
  • "Service" rely on the tool mechanism of service
    "Textual" use prompt-based tool calling
  • Possible values for Authentication are:
  • Automatic choose the authentication scheme automatically
    Inherited inherit settings from chat
    Environment check for a key in the environment variables
    SystemCredential check for a key in the system keychain
    ServiceObject [] inherit the authentication from a service object
    "string" provide explicit API key
  • With Authentication Automatic , the function checks the variable ToUpperCase [service]<>"_API_KEY" in Environment and SystemCredential ; otherwise, it uses ServiceConnect [service].
  • ChatSubmit uses machine learning. Its methods, training sets and biases included therein may change and yield varied results in different versions of the Wolfram Language.

Examples

open all close all

Basic Examples  (2)

Create a new chat:

Wolfram Language code: chat = ChatObject[]

Add a message to the conversation and submit it for a response, assigning the result to res:

Wolfram Language code: ChatSubmit[chat, "What's the tallest mountain?", HandlerFunctions -> <|"TaskFinished" -> Function[res = #ChatObject]|> ]

Inspect the generated conversation:

Wolfram Language code: res

Retrieve the generated response chunks from a multimodal model as they are received:

Wolfram Language code: chunks = {}; ChatSubmit[ChatObject[], {"what is this picture?", Entity["TaxonomicSpecies", "FelisCatus::ddvt3"][EntityProperty["TaxonomicSpecies", "Image"]]}, HandlerFunctions -> <|"ContentChunkReceived" -> Function[AppendTo[chunks, #ContentChunk]]|> ]

Show all the generation steps:

Wolfram Language code: chunks

Scope  (2)

Start a new conversation asynchronously:

Wolfram Language code: task = ChatSubmit[ChatObject[], "Tell me a joke", HandlerFunctions -> <|"TaskFinished" -> Function[res = #ChatObject]|>]

Inspect the task current status:

Wolfram Language code: task["TaskStatus"]

Inspect the generated conversation:

Wolfram Language code: res

Continue an existing conversation asynchronously:

Wolfram Language code: ChatSubmit[ChatObject[Association["LLMEvaluator" -> LLMConfiguration[ Association["Model" -> Association["Service" -> "OpenAI", "Name" -> Automatic, "Alias" -> "Wolfram LLM Service"], "MaxTokens" -> Automatic, "Temperature" -> Automatic, "To ... ]}, FaceForm[RGBColor[0.5372549019607843, 0.5372549019607843, 0.5372549019607843, 1.]]]}, ImageSize -> {{27., 27.}, {27., 27.}}, PlotRange -> {{-0.5, 26.5}, {-0.5, 26.5}}, AspectRatio -> Automatic], "LLMPacletVersion" -> "1.6.3"]], "And what about doctors?", HandlerFunctions -> <|"TaskFinished" -> Function[res = #ChatObject]|>]

Inspect the generated conversation:

Wolfram Language code: res

Options  (14)

Authentication  (4)

Provide an authentication key for the API:

Wolfram Language code: ChatSubmit[ChatObject[], "which element has atomic number 2?", Authentication -> <|"APIKey" -> "1234abcd"|>]

Look for the key in the system keychain:

Wolfram Language code: ChatSubmit[ChatObject[], "which element has atomic number 2?", Authentication -> SystemCredential]

Specify the name of the key:

Wolfram Language code: ChatSubmit[ChatObject[], "which element has atomic number 2?", Authentication -> {SystemCredential, SystemCredentialKey -> "OPENAI_API_KEY"}]

Look for the key in the system environment:

Wolfram Language code: ChatSubmit[ChatObject[], "which element has atomic number 2?", Authentication -> Environment]

Authenticate via a service object:

Wolfram Language code: so = ServiceConnect["OpenAI"]
Wolfram Language code: ChatSubmit[ChatObject[], "which element has atomic number 2?", Authentication -> so]

HandlerFunctions  (2)

Print all generated event names in the messages window:

Wolfram Language code: ChatSubmit[ ChatObject[], "the first 20 digits of Pi", HandlerFunctions -> Print, HandlerFunctionsKeys -> {"EventName"} ]

Capture the service-generated failure for an non-existing model:

Wolfram Language code: ChatSubmit[ ChatObject[LLMEvaluator -> <|"Model" -> <|"Service" -> "OpenAI", "Name" -> "WrongName"|>|>], "the first 20 digits of Pi", HandlerFunctions -> <|"FailureOccurred" -> Function@MessageDialog[#Failure]|> ]

HandlerFunctionsKeys  (3)

List explicitly the handler function keys to be passed to the handler functions:

Wolfram Language code: ChatSubmit[ ChatObject[], "the first 20 digits of Pi", HandlerFunctions -> <|"MetadataReceived" -> MessageDialog|>, HandlerFunctionsKeys -> {"Role", "Model", "Timestamp"} ]

Set HandlerFunctionsKeys values to be inferred lexically from the slots present in the handler functions (default):

Wolfram Language code: ChatSubmit[ ChatObject[], "the first 20 digits of Pi", HandlerFunctions -> <|"MetadataReceived" -> Function[MessageDialog[{#Role, #Model, #Timestamp}]]|>, HandlerFunctionsKeys -> Automatic ]

Include all available handler function keys in the handler function argument:

Wolfram Language code: ChatSubmit[ ChatObject[], "the first 20 digits of Pi", HandlerFunctions -> <|"MetadataReceived" -> MessageDialog|>, HandlerFunctionsKeys -> All ]

LLMEvaluator  (5)

Specify the service used to generate the answer:

Wolfram Language code: ChatSubmit[ChatObject[], "the first 20 digits of Pi", LLMEvaluator -> <|"Model" -> <|"Service" -> "Anthropic"|>|>]

Specify both the service and the model:

Wolfram Language code: ChatSubmit[ChatObject[], "the first 20 digits of Pi", LLMEvaluator -> <|"Model" -> <|"Service" -> "MistralAI", "Name" -> "mistral-medium"|>|>]

By default, the text generation continues until a termination token is generated:

Wolfram Language code: ChatSubmit[ChatObject[], "the first 20 digits of Pi", HandlerFunctions -> <|"StoppingReasonReceived" -> Function@MessageDialog[#StoppingReason]|>]

Limit the amount of generated samples (tokens):

Wolfram Language code: ChatSubmit[ChatObject[], "the first 20 digits of Pi", LLMEvaluator -> <|"MaxTokens" -> 3|>, HandlerFunctions -> <|"StoppingReasonReceived" -> Function@MessageDialog[#StoppingReason]|>]

Specify that the sampling should be performed at zero temperature:

Wolfram Language code: ChatSubmit[ChatObject[], "Tell me three colors", LLMEvaluator -> <|"Temperature" -> 0|>, HandlerFunctions -> <|"TaskFinished" -> Function[res1 = #ChatObject]|>]

Specify a high temperature to get more variation in the generation:

Wolfram Language code: ChatSubmit[ChatObject[], "Tell me three colors", LLMEvaluator -> <|"Temperature" -> 2|>, HandlerFunctions -> <|"TaskFinished" -> Function[res2 = #ChatObject]|>]

Compare results:

Wolfram Language code: res1 res2

Specify the maximum cumulative probability before cutting off the distribution:

Wolfram Language code: ChatSubmit[ChatObject[], "What's the plural of mouse?", LLMEvaluator -> <|"TotalProbabilityCutoff" -> .5|>]

Specify a prompt to be automatically added to the conversation:

Wolfram Language code: ChatSubmit[ChatObject[], "What's the plural of mouse?", LLMEvaluator -> <|"Prompts" -> LLMPrompt["ELI5"]|>]

Applications  (1)

Tool Calling  (1)

Define a tool that can be called by the LLM:

Wolfram Language code: altimeter = LLMTool[{"altimeter", "gives the altitude at a location"}, {"where" -> "Location"}, GeoElevationData[#where]&]

Instantiate a chat object with the tool:

Wolfram Language code: chat = ChatObject[LLMEvaluator -> <|"Tools" -> altimeter, "ToolMethod" -> "Service"|>]

Ask a question that can get a precise answer using the tool:

Wolfram Language code: ChatSubmit[chat, "what's the altitude of mount Kilimanjaro?", HandlerFunctions -> <|"TaskFinished" -> Function[res = #ChatObject]|>]

Inspect the generated conversation:

Wolfram Language code: res
Wolfram Research (2025), ChatSubmit, Wolfram Language function, https://reference.wolfram.com/language/ref/ChatSubmit.html.

Text

Wolfram Research (2025), ChatSubmit, Wolfram Language function, https://reference.wolfram.com/language/ref/ChatSubmit.html.

CMS

Wolfram Language. 2025. "ChatSubmit." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ChatSubmit.html.

APA

Wolfram Language. (2025). ChatSubmit. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ChatSubmit.html

BibTeX

@misc{reference.wolfram_2026_chatsubmit, author="Wolfram Research", title="{ChatSubmit}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/ChatSubmit.html}", note=[Accessed: 15-August-2026]}

BibLaTeX

@online{reference.wolfram_2026_chatsubmit, organization={Wolfram Research}, title={ChatSubmit}, year={2025}, url={https://reference.wolfram.com/language/ref/ChatSubmit.html}, note=[Accessed: 15-August-2026]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /