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

Online Help

NaturalLanguage

  

GenerateDocument

  

generate a document using a large language model [Technology Preview]

 

Calling Sequence

Parameters

Description

Examples

References

Compatibility

Calling Sequence

GenerateDocument(prompt)

h := GenerateDocument(prompt, opts)

h := GenerateDocument(prompt, history = h, opts)

GenerateDocument[interactive]()

Parameters

prompt

-

string, (optional) query to send to a large language model.

h

-

object, (optional) history object resulting from an earlier call to GenerateDocument

opts

-

(optional) one or more options of the form role=r, paragraphs=p, output=o, or model=m.

Description

• 

The GenerateDocument command is a technology preview that generates a document using a large language model (LLM).

• 

The first call to GenerateDocument must have a prompt argument: a string describing what you want the document to be about. By default, this opens a new document and returns an object representing the interactions with the LLM. This 'history object' is a special form of the object returned by NaturalLanguage:-Dialog.

  

In later calls, you can include the argument history=h, where h is such an object, to continue this conversation with the large language model. In such a case you do not need to include a prompt, though you can if you want to include instructions to refine what the document should be about. Alternatively, if you do not include the history option, you start a new dialog with the large language model.

• 

To fine tune how the actual document is created, you can use the output=o option. The result depends on the value of o:

• 

output=history

  

This just returns the history object.

• 

output=display

• 

output=insert

• 

output=xml

  

With these options, Maple will call Worksheet:-FromMarkdown with the same output=o option, passing it the returned string from the large language model. The documentation of that command explains these options. In short, with output=display, a new document is created; with output=insert, the content is inserted into the current document; and with output=xml, the content is returned in an XML representation. Any return values from Worksheet:-FromMarkdown are ignored (GenerateDocument will return NULL), except with output=xml.

• 

output=

  

You can also pass in a list as the value of the output option, if each entry of the list is one of the names above. In this case, Maple will perform the actions for the corresponding entries in sequence. The corresponding results, if any, are returned as an expression sequence.

  

The default value of the output option is output=history,display; that is, the history object is returned and the resulting document is opened as a new document.

• 

You can modify the document generated by using the role and paragraphs options. By using the role=r option, where r is a string or symbol, you change the tone and focus of the document by instructing the large language model to play the role of an r. By default, r is "scientist", but for example teacher or engineer can also be useful roles.

• 

The large language model is by default instructed to write five paragraphs of content. You can modify this by using the paragraphs=p option, where p is a positive integer. This changes the instruction to writing p paragraphs, where p is replaced by the value of the option. Note that setting p higher is more likely to lead to time out errors, as the large language model is given only limited time to generate its response.

• 

The final calling sequence, GenerateDocumentinteractive, displays an interactive application that allows you to interact with the facilities provided by the GenerateWorksheet command. It is described on its own help page.

• 

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:

hGenerateDocumentfractals

hGenerateDocumenthistory=h,role=teacher,output=history,insert

hGenerateDocumentinclude an explanation of Koch's snowflake curve,history=h,output=history,insert

GenerateDocumentThat's pretty good - could you include more formulas though?,history=h,output=display

References

  

The OpenAI website.

Compatibility

• 

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

• 

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

See Also

NaturalLanguage:-GenerateDocument/interactive

 


Download Help Document