Dialog - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

NaturalLanguage

  

Dialog

  

complete a sequence of messages sent to a large language model

 

Calling Sequence

Parameters

Description

Examples

References

Compatibility

Calling Sequence

Dialog(sp, opts)

Dialog(sys, prompt, opts)

Dialog(h, prompt, opts)

Parameters

sp

-

list of [string, string] pairs, where the first string in each pair is one of "system", "user", or "assistant"

sys

-

system message (string)

prompt

-

user prompt (string)

opts

-

(optional) equation(s) of the form model=m or output=o, where m is a name and o is history, string, or stringpairs.

Description

• 

The Dialog command sends the sequence of messages specified in its arguments to a large language model (LLM). The command returns the message from the LLM, optionally together with the dialog history.

• 

Each message has an associated source: it can be "system", "user", or "assistant". A system message sets up the dialog; it typically gives general guidelines for the LLM on how to respond. A user message typically comes from an end user of the system. An assistant message is a message sent by the LLM. Please see OpenAI's documentation for more information on this.

• 

There are three different calling sequences.

– 

For the most general calling sequence, you submit a list of pairs source1,message1,source2,message2, which represents the dialog so far; the LLM will generate an assistant message that it judges a reasonable continuation of the dialog.

– 

Alternatively, you can use just two strings. These are interpreted as a system message and a user prompt: passing strings sys and prompt is equivalent to passing system,sys,user,prompt.

– 

Finally, you can ask Maple to return an object representing the conversation so far as a history object, explained in more detail below. You can then pass this history object back to Dialog to continue the conversation. For this calling sequence, you can also pass zero or more strings that will be considered user messages to be appended to the history so far before it is passed to the LLM.

• 

You can request three types of output:

– 

With the output=string option, Maple returns just the (string) return value from the LLM. This is the default output.

– 

With the option output=stringpairs, Maple returns the list of pairs of strings that represents the full conversation including the newly returned value from the LLM.

– 

With the option output=history, Maple returns an object that represents the history so far, including the newly returned value from the LLM. You can interrogate this object, or pass it back into the Dialog command to continue the conversation. Ways you can interrogate the object (let's call it h) are:

• 

AddMessageh,s,msg appends a message to the history, where h is the history object; s is the source for the message - "system", "user", or "assistant"; and msg is the message to add to the end of the history.

• 

Messagesh returns a list of pairs of strings like you can pass into Dialog.

• 

Maple can interface with OpenAI's GPT-4o, o1-mini, and o3-mini models. You can select these by using the options model=GPT4o; model=O1Mini; and model=O3Mini, respectively. By default, or when explicitly selected with the model=default option, a Maplesoft server chooses an appropriate model. (At the time of release of Maple 2025, this was the o3-mini model.) Note that OpenAI may deprecate and disable models, so the set of models supported may change in the future.

  

Note: Large language models often generate inaccurate statements. Please keep this in mind: this is not technology for building a bridge with.

Examples

withNaturalLanguage:

In this example, we instruct the large language model to act as a college instructor. We can see how we can construct a dialog between the model and the user.

sysmsgYou are a helpful and knowledgeable instructor for Calculus I at a community college.

sysmsgYou are a helpful and knowledgeable instructor for Calculus I at a community college.

(1)

userpromptHow do I compute the derivative of sin(2*x)?

userpromptHow do I compute the derivative of sin(2*x)?

(2)

r1Dialogsysmsg,userprompt,output=stringpairs

r1system,You are a helpful and knowledgeable instructor for Calculus I at a community college.,user,How do I compute the derivative of sin(2*x)?,assistant,To differentiate sin(2x), you'll want to use the chain rule. The chain rule states that if you have a composite function f(g(x)), the derivative is f '(g(x)) · g '(x). Here, think of sin(2x) as being composed of:  • An outer function f(u) = sin(u), where u = 2x.  • An inner function g(x) = 2x. Step 1: Differentiate the outer function.  The derivative of f(u) = sin(u) with respect to u is f '(u) = cos(u). Step 2: Differentiate the inner function.  The derivative of g(x) = 2x with respect to x is g '(x) = 2. Step 3: Apply the chain rule.  The derivative of sin(2x) is then:   d/dx [sin(2x)] = cos(2x) · 2 Thus, the final answer is:  2cos(2x). This is your derivative of sin(2x).

(3)

dialogopr1,user,How about sin(x^2)?

dialogsystem,You are a helpful and knowledgeable instructor for Calculus I at a community college.,user,How do I compute the derivative of sin(2*x)?,assistant,To differentiate sin(2x), you'll want to use the chain rule. The chain rule states that if you have a composite function f(g(x)), the derivative is f '(g(x)) · g '(x). Here, think of sin(2x) as being composed of:  • An outer function f(u) = sin(u), where u = 2x.  • An inner function g(x) = 2x. Step 1: Differentiate the outer function.  The derivative of f(u) = sin(u) with respect to u is f '(u) = cos(u). Step 2: Differentiate the inner function.  The derivative of g(x) = 2x with respect to x is g '(x) = 2. Step 3: Apply the chain rule.  The derivative of sin(2x) is then:   d/dx [sin(2x)] = cos(2x) · 2 Thus, the final answer is:  2cos(2x). This is your derivative of sin(2x).,user,How about sin(x^2)?

(4)

r2Dialogdialog

r2To differentiate sin(x²), you'll again use the chain rule. The chain rule is applicable when you have a composite function f(g(x)), and it tells you:  d/dx [f(g(x))] = f '(g(x)) · g '(x). For sin(x²): 1. Identify the inner function: u = x². 2. Identify the outer function: f(u) = sin(u). Step 1: Differentiate the outer function with respect to u.  Since f(u) = sin(u), the derivative is f '(u) = cos(u). Step 2: Differentiate the inner function with respect to x.  Since u = x², the derivative is d/dx (x²) = 2x. Step 3: Apply the chain rule.  d/dx [sin(x²)] = cos(u) · 2x.  Now substitute back u = x²:  d/dx [sin(x²)] = 2x · cos(x²). Therefore, the derivative of sin(x²) is 2x cos(x²).

(5)

When an LLM does not give the exact type of answers you're looking for, it can help to frame the input as a conversation where you include one or a few earlier answers of the form that you need. For example, if you want the LLM to include steps in a computation, it can be hard to describe exactly the level of detail you are looking for. An example, or a few examples, might work better.

dialogsystem,You solve math problems.,user,What is 3*(2+5)?,assistant,3*(2+5) = 3*7 = 21.,user,What is 15/(2+3)?

dialogsystem,You solve math problems.,user,What is 3*(2+5)?,assistant,3*(2+5) = 3*7 = 21.,user,What is 15/(2+3)?

(6)

response,hDialogdialog,output=string,history,model=GPT4o:

response

15/(2+3) = 15/5 = 3.

(7)

AddMessageh,user,What is 2*3+4?

6

(8)

Dialogh,model=GPT4o

2*3+4 = 6+4 = 10.

(9)

References

  

The OpenAI website.

Compatibility

• 

The NaturalLanguage:-Dialog command was introduced in Maple 2025.

• 

For more information on Maple 2025 changes, see Updates in Maple 2025.


Download Help Document