SmartPrompt
Namespace: Wisej.AI
Assembly: Wisej.AI
Represents a smart prompt component that can process and manage prompts with tools and parameters.
- C#
- VB.NET
public class SmartPrompt : SmartObject, IToolProvider, ICloneable
Public Class SmartPrompt
Inherits SmartObject
Implements IToolProvider, ICloneable
The SmartPrompt class provides functionality to manage prompts, tools, and parameters. It supports cloning and asynchronous operations to ask questions using a smart hub or endpoint.
SmartPrompt prompt = new SmartPrompt("You are a weather expert");
prompt.Start += (s, e) => Console.WriteLine("Processing started.");
prompt.Done += (s, e) => Console.WriteLine("Processing done.");
await prompt.AskAsync(new OpenAIEndpoint(), "What is the weather today?");
Constructors
SmartPrompt(text)
Initializes a new instance of the SmartPrompt class with the specified text.
| Name | Type | Description |
|---|---|---|
| text | String | The initial text for the prompt. Default is null. |
Properties
PromptDictionaries
IList<IDictionary<String, String>>: Gets the collection of prompt dictionaries.
The prompt dictionaries are loaded from the AI directory and embedded resources.
Text
String: Gets or sets the text of the smart prompt. (Default: null)
The text is resolved using the ResolvePrompt method.
Methods
AskAsync(hub, question, image)
Asynchronously asks a question using the specified smart hub.
| Parameter | Type | Description |
|---|---|---|
| hub | SmartHub | The smart hub to use. |
| question | String | The question to ask. |
| image | Image | An optional image to include in the question. Default is null. |
Returns: Task<Message>. A task representing the asynchronous operation, with a Message result.
Throws:
- ArgumentNullException Thrown when the hub or question is null.
AskAsync(endpoint, question, image)
Asynchronously asks a question using the specified smart endpoint.
| Parameter | Type | Description |
|---|---|---|
| endpoint | SmartEndpoint | The smart endpoint to use. |
| question | String | The question to ask. |
| image | Image | An optional image to include. Default is null. |
Returns: Task<Message>. A task representing the asynchronous operation, with a Message result.
Throws:
- ArgumentNullException Thrown when the endpoint or question is null.
Clone()
Creates a new instance of the SmartPrompt class that is a copy of the current instance.
Returns: SmartPrompt. A new SmartPrompt object that is a copy of this instance.
RemoveTool(tool)
Removes a tool from the smart prompt.
| Parameter | Type | Description |
|---|---|---|
| tool | Delegate | The tool to remove. |
Returns: SmartPrompt. The current SmartPrompt instance.
Throws:
- ArgumentNullException Thrown when the tool is null.
RemoveTools(target)
Removes the tools from the specified object.
| Parameter | Type | Description |
|---|---|---|
| target | Object | The target object containing tools. |
Returns: SmartPrompt. The current SmartPrompt instance.
ResolvePrompt(key)
Resolves the prompt text for the specified key.
| Parameter | Type | Description |
|---|---|---|
| key | String | The key to resolve. |
Returns: String. The resolved prompt text, or the key if not found.
SavePrompts(filePath)
Saves the prompts to the specified file path.
| Parameter | Type | Description |
|---|---|---|
| filePath | String | The file path to save the prompts to. |
UseTool(tool)
Adds a tool to the smart prompt.
| Parameter | Type | Description |
|---|---|---|
| tool | Delegate | The tool to add. |
Returns: SmartPrompt. The current SmartPrompt instance.
Throws:
- ArgumentNullException Thrown when the tool is null.
UseTools(target)
Uses the tools from the specified target object.
| Parameter | Type | Description |
|---|---|---|
| target | Object | The target object containing tools. |
Returns: SmartPrompt. The current SmartPrompt instance.
Inherited By
| Name | Description |
|---|---|
| SmartAgentPrompt | TODO: |
| SmartParallelPrompt | Represents a smart parallel prompt that can execute multiple tasks concurrently. |
Implements
| Name | Description |
|---|---|
| IToolProvider | Represents a provider that supplies tools. |