PromptManager class
A filesystem based prompt manager.
Remarks
The default prompt manager uses the file system to define prompts that are compatible with Microsoft's Semantic Kernel SDK (see: https://github.com/microsoft/semantic-kernel)
Each prompt is a separate folder under a root prompts folder. The folder should contain the following files:
- "config.json": Required. Contains the prompts configuration and is a serialized instance of
PromptTemplateConfig
. - "skprompt.txt": Required. Contains the text of the prompt and supports Semantic Kernels prompt template syntax.
- "actions.json": Optional. Contains a list of actions that can be called by the prompt.
Prompts can be loaded and used by name and new dynamically defined prompt templates can be registered with the prompt manager.
Constructors
Prompt |
Creates a new 'PromptManager' instance. |
Properties
options | Gets the configured prompt manager options. |
Methods
add |
Registers a new data source with the prompt manager. |
add |
Registers a new prompt template function with the prompt manager. |
add |
Registers a new prompt template with the prompt manager. |
get |
Looks up a data source by name. |
get |
Looks up a prompt template function by name. |
get |
Loads a named prompt template from the filesystem. |
has |
Checks for the existence of a named data source. |
has |
Checks for the existence of a named prompt template function. |
has |
Checks for the existence of a named prompt. |
invoke |
Invokes a prompt template function by name. |
Constructor Details
PromptManager(PromptManagerOptions)
Creates a new 'PromptManager' instance.
new PromptManager(options: PromptManagerOptions)
Parameters
- options
- PromptManagerOptions
Options used to configure the prompt manager.
Property Details
options
Gets the configured prompt manager options.
ConfiguredPromptManagerOptions options
Property Value
The configured prompt manager options.
Method Details
addDataSource(DataSource)
Registers a new data source with the prompt manager.
function addDataSource(dataSource: DataSource): PromptManager
Parameters
- dataSource
- DataSource
Data source to add.
Returns
The prompt manager for chaining.
addFunction(string, PromptFunction)
Registers a new prompt template function with the prompt manager.
function addFunction(name: string, fn: PromptFunction): PromptManager
Parameters
- name
-
string
Name of the function to add.
Function to add.
Returns
- The prompt manager for chaining.
addPrompt(PromptTemplate)
Registers a new prompt template with the prompt manager.
function addPrompt(prompt: PromptTemplate): PromptManager
Parameters
- prompt
- PromptTemplate
Prompt template to add.
Returns
The prompt manager for chaining.
getDataSource(string)
Looks up a data source by name.
function getDataSource(name: string): DataSource
Parameters
- name
-
string
Name of the data source to lookup.
Returns
The data source.
getFunction(string)
Looks up a prompt template function by name.
function getFunction(name: string): PromptFunction
Parameters
- name
-
string
Name of the function to lookup.
Returns
The function.
getPrompt(string)
Loads a named prompt template from the filesystem.
function getPrompt(name: string): Promise<PromptTemplate>
Parameters
- name
-
string
Name of the prompt to load.
Returns
Promise<PromptTemplate>
The loaded and parsed prompt template.
Remarks
The template will be pre-parsed and cached for use when the template is rendered by name.
Any augmentations will also be added to the template.
hasDataSource(string)
Checks for the existence of a named data source.
function hasDataSource(name: string): boolean
Parameters
- name
-
string
Name of the data source to lookup.
Returns
boolean
True if the data source exists.
hasFunction(string)
Checks for the existence of a named prompt template function.
function hasFunction(name: string): boolean
Parameters
- name
-
string
Name of the function to lookup.
Returns
boolean
True if the function exists.
hasPrompt(string)
Checks for the existence of a named prompt.
function hasPrompt(name: string): Promise<boolean>
Parameters
- name
-
string
Name of the prompt to load.
Returns
Promise<boolean>
True if the prompt exists.
invokeFunction(string, TurnContext, Memory, Tokenizer, string[])
Invokes a prompt template function by name.
function invokeFunction(name: string, context: TurnContext, memory: Memory, tokenizer: Tokenizer, args: string[]): Promise<any>
Parameters
- name
-
string
Name of the function to invoke.
- context
-
TurnContext
Turn context for the current turn of conversation with the user.
- memory
- Memory
An interface for accessing state values.
- tokenizer
- Tokenizer
Tokenizer to use when rendering the prompt.
- args
-
string[]
Arguments to pass to the function.
Returns
Promise<any>
Value returned by the function.