Skip to main content

SmartPrompt

Namespace: Wisej.AI

Assembly: Wisej.AI

Represents a smart prompt component that can process and manage prompts with tools and parameters.

public class SmartPrompt : SmartObject, 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.

NameTypeDescription
textStringThe 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.

ParameterTypeDescription
hubSmartHubThe smart hub to use.
questionStringThe question to ask.
image ImageAn optional image to include in the question. Default is null.

Returns: Task<Message>. A task representing the asynchronous operation, with a Message result.

Throws:

AskAsync(endpoint, question, image)

Asynchronously asks a question using the specified smart endpoint.

ParameterTypeDescription
endpointSmartEndpointThe smart endpoint to use.
questionStringThe question to ask.
image ImageAn optional image to include. Default is null.

Returns: Task<Message>. A task representing the asynchronous operation, with a Message result.

Throws:

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.

ParameterTypeDescription
toolDelegateThe tool to remove.

Returns: SmartPrompt. The current SmartPrompt instance.

Throws:

RemoveTools(target)

Removes the tools from the specified object.

ParameterTypeDescription
targetObjectThe target object containing tools.

Returns: SmartPrompt. The current SmartPrompt instance.

ResolvePrompt(key)

Resolves the prompt text for the specified key.

ParameterTypeDescription
keyStringThe 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.

ParameterTypeDescription
filePathStringThe file path to save the prompts to.

UseTool(tool)

Adds a tool to the smart prompt.

ParameterTypeDescription
toolDelegateThe tool to add.

Returns: SmartPrompt. The current SmartPrompt instance.

Throws:

UseTools(target)

Uses the tools from the specified target object.

ParameterTypeDescription
targetObjectThe target object containing tools.

Returns: SmartPrompt. The current SmartPrompt instance.

Inherited By

NameDescription
SmartAgentPromptTODO:
SmartParallelPromptRepresents a smart parallel prompt that can execute multiple tasks concurrently.

Implements

NameDescription
IToolProviderRepresents a provider that supplies tools.