# SmartPrompt

Namespace: **Wisej.AI**

Assembly: **Wisej.AI** (3.5.0.0)

* [SmartObject](https://docs.wisej.com/ai/components/api/wisej.ai.smartobject)
  * [SmartPrompt](https://docs.wisej.com/ai/components/api/smartprompt)

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

{% tabs %}
{% tab title="C#" %}

```csharp
public class SmartPrompt : SmartObject, IToolProvider, ICloneable
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class SmartPrompt
    Inherits SmartObject
    Implements IToolProvider, ICloneable
```

{% endtab %}
{% endtabs %}

The [SmartPrompt](https://docs.wisej.com/ai/components/api/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.

```csharp

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

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) SmartPrompt(text)

Initializes a new instance of the [SmartPrompt](https://docs.wisej.com/ai/components/api/smartprompt) class with the specified text.

| Name     | Type                                                          | Description                                         |
| -------- | ------------------------------------------------------------- | --------------------------------------------------- |
| **text** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The initial text for the prompt. Default is `null`. |

## Properties

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FEPpV9g2fTvKYNWpTJsLx%2Fstatic.png?alt=media\&token=d34d45e6-160f-4123-8358-42f2e0a757db) PromptDictionaries

[IList\<IDictionary\<String, String>>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ilist-1): Gets the collection of prompt dictionaries.

The prompt dictionaries are loaded from the AI directory and embedded resources.

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) Text

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the text of the smart prompt. (Default: `null`)

The text is resolved using the [ResolvePrompt](#resolveprompt-key) method.

## Methods

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) AskAsync(hub, question, image)

Asynchronously asks a question using the specified smart hub.

| Parameter                                                                                                                                                                                                                              | Type                                                                | Description                                                      |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | ---------------------------------------------------------------- |
| **hub**                                                                                                                                                                                                                                | [SmartHub](https://docs.wisej.com/ai/components/api/smarthub)       | The smart hub to use.                                            |
| **question**                                                                                                                                                                                                                           | [String](https://docs.microsoft.com/dotnet/api/system.string)       | The question to ask.                                             |
| **image** ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FBPFc5AMUqwkzAJdlTYv8%2Fbadge-optional.svg?alt=media\&token=38bdb20d-14b6-4aba-816f-833f010523df) | [Image](https://docs.microsoft.com/dotnet/api/system.drawing.image) | An optional image to include in the question. Default is `null`. |

**Returns:** [Task\<Message>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with a [Message](https://docs.wisej.com/ai/components/api/smartsession/wisej.ai.smartsession.message) result.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the hub or question is null.

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) AskAsync(endpoint, question, image)

Asynchronously asks a question using the specified smart endpoint.

| Parameter                                                                                                                                                                                                                              | Type                                                                    | Description                                      |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------ |
| **endpoint**                                                                                                                                                                                                                           | [SmartEndpoint](https://docs.wisej.com/ai/components/api/smartendpoint) | The smart endpoint to use.                       |
| **question**                                                                                                                                                                                                                           | [String](https://docs.microsoft.com/dotnet/api/system.string)           | The question to ask.                             |
| **image** ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FBPFc5AMUqwkzAJdlTYv8%2Fbadge-optional.svg?alt=media\&token=38bdb20d-14b6-4aba-816f-833f010523df) | [Image](https://docs.microsoft.com/dotnet/api/system.drawing.image)     | An optional image to include. Default is `null`. |

**Returns:** [Task\<Message>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with a [Message](https://docs.wisej.com/ai/components/api/smartsession/wisej.ai.smartsession.message) result.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the endpoint or question is null.

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) Clone()

Creates a new instance of the [SmartPrompt](https://docs.wisej.com/ai/components/api/smartprompt) class that is a copy of the current instance.

**Returns:** [SmartPrompt](https://docs.wisej.com/ai/components/api/smartprompt). A new [SmartPrompt](https://docs.wisej.com/ai/components/api/smartprompt) object that is a copy of this instance.

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) RemoveTool(tool)

Removes a tool from the smart prompt.

| Parameter | Type                                                              | Description         |
| --------- | ----------------------------------------------------------------- | ------------------- |
| **tool**  | [Delegate](https://docs.microsoft.com/dotnet/api/system.delegate) | The tool to remove. |

**Returns:** [SmartPrompt](https://docs.wisej.com/ai/components/api/smartprompt). The current [SmartPrompt](https://docs.wisej.com/ai/components/api/smartprompt) instance.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the tool is null.

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) RemoveTools(target)

Removes the tools from the specified object.

| Parameter  | Type                                                          | Description                         |
| ---------- | ------------------------------------------------------------- | ----------------------------------- |
| **target** | [Object](https://docs.microsoft.com/dotnet/api/system.object) | The target object containing tools. |

**Returns:** [SmartPrompt](https://docs.wisej.com/ai/components/api/smartprompt). The current [SmartPrompt](https://docs.wisej.com/ai/components/api/smartprompt) instance.

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FEPpV9g2fTvKYNWpTJsLx%2Fstatic.png?alt=media\&token=d34d45e6-160f-4123-8358-42f2e0a757db) ResolvePrompt(key)

Resolves the prompt text for the specified key.

| Parameter | Type                                                          | Description         |
| --------- | ------------------------------------------------------------- | ------------------- |
| **key**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key to resolve. |

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). The resolved prompt text, or the key if not found.

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FEPpV9g2fTvKYNWpTJsLx%2Fstatic.png?alt=media\&token=d34d45e6-160f-4123-8358-42f2e0a757db) SavePrompts(filePath)

Saves the prompts to the specified file path.

| Parameter    | Type                                                          | Description                           |
| ------------ | ------------------------------------------------------------- | ------------------------------------- |
| **filePath** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The file path to save the prompts to. |

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) UseTool(tool)

Adds a tool to the smart prompt.

| Parameter | Type                                                              | Description      |
| --------- | ----------------------------------------------------------------- | ---------------- |
| **tool**  | [Delegate](https://docs.microsoft.com/dotnet/api/system.delegate) | The tool to add. |

**Returns:** [SmartPrompt](https://docs.wisej.com/ai/components/api/smartprompt). The current [SmartPrompt](https://docs.wisej.com/ai/components/api/smartprompt) instance.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the tool is null.

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FdLVsGEp1mKmjdHvG0Itk%2Finstance.png?alt=media\&token=0061ee96-c913-420d-aa2f-daf782ca6a1d) UseTools(target)

Uses the tools from the specified target object.

| Parameter  | Type                                                          | Description                         |
| ---------- | ------------------------------------------------------------- | ----------------------------------- |
| **target** | [Object](https://docs.microsoft.com/dotnet/api/system.object) | The target object containing tools. |

**Returns:** [SmartPrompt](https://docs.wisej.com/ai/components/api/smartprompt). The current [SmartPrompt](https://docs.wisej.com/ai/components/api/smartprompt) instance.

## Inherited By

| Name                                                                                                     | Description                                                                      |
| -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| [SmartAgentPrompt](https://docs.wisej.com/ai/components/api/smartprompt/wisej.ai.smartagentprompt)       | TODO:                                                                            |
| [SmartParallelPrompt](https://docs.wisej.com/ai/components/api/smartprompt/wisej.ai.smartparallelprompt) | Represents a smart parallel prompt that can execute multiple tasks concurrently. |

## Implements

| Name                                                                                                 | Description                                |
| ---------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| [IToolProvider](https://docs.wisej.com/ai/components/api/smarttool/wisej.ai.smarttool.itoolprovider) | Represents a provider that supplies tools. |
