LLMPromptGenerator

LLMPromptGenerator[f]

represents a prompt generator that uses the function f.

LLMPromptGenerator[f,inputspec]

provides the specified inputspec to f.

Details

  • LLMPromptGenerator is used to add message-dependent context to an LLM prompt.
  • Possible values for inputspec are:
  • "Input"the last user input (default)
    "Messages"the list of messages
    "LLMEvaluator"the current LLMConfiguration[]
    "ChatObject"the whole conversation as ChatObject[]
    {spec1,}an association of inputs
  • The result of f has to be textual prompt. Possible values include:
  • "string"static text
    LLMPrompt["name"]a repository prompt
    StringTemplate[]templated text
    TemplateObject[]template for creating a text
    SemanticSearchIndex[]a semantic search index
    {prompt1,}a list of prompts
  • If the result of f is not a string or a list of strings, it will be converted using TextString.

Examples

open allclose all

Basic Examples  (1)

Define a prompt generator that always prepends the current evaluation date and time:

Test the generator:

Use the generator in an interaction with an LLM:

Scope  (5)

Function  (3)

Use a simple prompt:

Use a function to define the tone of the answer at evaluation time based on the input:

Try with a cowboy role:

Define a generator on a SemanticSearchIndex:

Use it to add content semantically relevant to the query:

Compare with the uninformed LLM answer:

Input Specifications  (2)

Define a generator that echoes the calling function input (default argument):

Give a custom input specification:

Possible Issues  (1)

A list of prompts does not evaluate when applied to the input:

Wrap the list using TemplateObject or Function:

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

Text

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

CMS

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

APA

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

BibTeX

@misc{reference.wolfram_2024_llmpromptgenerator, author="Wolfram Research", title="{LLMPromptGenerator}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/LLMPromptGenerator.html}", note=[Accessed: 30-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_llmpromptgenerator, organization={Wolfram Research}, title={LLMPromptGenerator}, year={2024}, url={https://reference.wolfram.com/language/ref/LLMPromptGenerator.html}, note=[Accessed: 30-December-2024 ]}