# SmartEndpoint

Namespace: **Wisej.AI**

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

Represents an abstract base class for a smart endpoint component that interacts with AI models.

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

```csharp
public class SmartEndpoint : Component
```

{% endtab %}

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

```visual-basic
Public Class SmartEndpoint
    Inherits Component
```

{% endtab %}
{% endtabs %}

This class provides properties and methods to configure and interact with AI models, including handling messages, building payloads, and managing tool invocations.

```csharp

// Example usage:
SmartEndpoint endpoint = new CustomSmartEndpoint();
var response = await endpoint.AskAsync(session, messages);

```

## Constructors

### ![](/files/ptrKjmmRoQB76pvrIqh0) SmartEndpoint()

Initializes a new instance of the [SmartEndpoint](/ai/components/api/smartendpoint.md) class.

## Properties

### ![](/files/ptrKjmmRoQB76pvrIqh0) ContextWindow

[Int32](https://docs.microsoft.com/dotnet/api/system.int32): Gets or sets the size of the context window in tokens. (Default: `32000`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) EmbeddingModel

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the embedding model used by the endpoint. (Default: `null`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) MaxOutputTokens

[Int32](https://docs.microsoft.com/dotnet/api/system.int32): Gets or sets the maximum number of output tokens. (Default: `4096`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) Model

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the model used by the endpoint. (Default: `null`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) ModelOptions

[Object](https://docs.microsoft.com/dotnet/api/system.object): Gets the model options for the endpoint.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Name

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the name of the endpoint.

### ![](/files/ptrKjmmRoQB76pvrIqh0) SystemPrompt

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the system prompt for the endpoint.

Warning, setting this property entirely overrides the internal system prompt.

### ![](/files/KL0Ik37djZRr8a07Wopd) ToolsPrompt

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the tools prompt for the endpoint.

Warning, setting this property entirely overrides the internal tools prompt.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Usage

[Metrics](/ai/components/api/smartendpoint/wisej.ai.smartendpoint.metrics.md): Gets the usage metrics for the endpoint.

### ![](/files/ptrKjmmRoQB76pvrIqh0) UseNativeTools

[Boolean](https://docs.microsoft.com/dotnet/api/system.boolean): Gets or sets a value indicating that the endpoint should use the native tools payload when adding tools to the request. (Default: `False`)

## Methods

### ![](/files/KL0Ik37djZRr8a07Wopd) AddMessages(payload, session, messages)

Adds messages to the payload object.

| Parameter    | Type                                                                                        | Description                   |
| ------------ | ------------------------------------------------------------------------------------------- | ----------------------------- |
| **payload**  | [Object](https://docs.microsoft.com/dotnet/api/system.object)                               | The payload object to update. |
| **session**  | [SmartSession](/ai/components/api/smartsession.md)                                          | The session context.          |
| **messages** | [IList\<Message>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ilist-1) | The list of messages to add.  |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the session, payload, or messages are null.

### ![](/files/KL0Ik37djZRr8a07Wopd) AddOptions(message, session)

Adds model options to the message object.

| Parameter   | Type                                                          | Description                   |
| ----------- | ------------------------------------------------------------- | ----------------------------- |
| **message** | [Object](https://docs.microsoft.com/dotnet/api/system.object) | The message object to update. |
| **session** | [SmartSession](/ai/components/api/smartsession.md)            | The session context.          |

**Throws:**

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

### ![](/files/ptrKjmmRoQB76pvrIqh0) AskAsync(session, messages)

Asynchronously sends a message to the AI model and returns the response.

| Parameter    | Type                                                                                        | Description                   |
| ------------ | ------------------------------------------------------------------------------------------- | ----------------------------- |
| **session**  | [SmartSession](/ai/components/api/smartsession.md)                                          | The session context.          |
| **messages** | [IList\<Message>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ilist-1) | The list of messages to send. |

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

This method must be implemented by derived classes to handle the specific logic for sending messages to the AI model.

```csharp

// Example usage:
var response = await endpoint.AskAsync(session, messages);

```

{% hint style="info" %}
The implementation of this method should call `session.Usage.Add(assistantMessage.Usage)` to keep track if the input and output tokens utilized at the session level.
{% endhint %}

### ![](/files/ptrKjmmRoQB76pvrIqh0) AskEmbeddingsAsync(inputs)

Asynchronously requests embeddings for the given inputs.

| Parameter  | Type                                                              | Description                 |
| ---------- | ----------------------------------------------------------------- | --------------------------- |
| **inputs** | [String\[\]](https://docs.microsoft.com/dotnet/api/system.string) | The array of input strings. |

**Returns:** [Task\<Embedding>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation, with an [Embedding](/ai/components/api/embeddings/wisej.ai.embeddings.embedding.md) as the result.

**Throws:**

* [NotImplementedException](https://docs.microsoft.com/dotnet/api/system.notimplementedexception)\
  Thrown when the method is not implemented.

### ![](/files/KL0Ik37djZRr8a07Wopd) BuildAssistantMessage(response)

Builds an assistant [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) from the given response.

| Parameter    | Type                                                                            | Description                 |
| ------------ | ------------------------------------------------------------------------------- | --------------------------- |
| **response** | [Response](/ai/components/api/smartendpoint/wisej.ai.smartendpoint.response.md) | The response to build from. |

**Returns:** [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md). A [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) representing the assistant's response.

**Throws:**

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

### ![](/files/KL0Ik37djZRr8a07Wopd) BuildEmbeddingsPayload(inputs)

Builds a payload for requesting embeddings.

| Parameter  | Type                                                              | Description                 |
| ---------- | ----------------------------------------------------------------- | --------------------------- |
| **inputs** | [String\[\]](https://docs.microsoft.com/dotnet/api/system.string) | The array of input strings. |

**Returns:** [Object](https://docs.microsoft.com/dotnet/api/system.object). An object representing the embeddings payload.

**Throws:**

* [NotImplementedException](https://docs.microsoft.com/dotnet/api/system.notimplementedexception)\
  Thrown when the method is not implemented.

### ![](/files/KL0Ik37djZRr8a07Wopd) BuildMessage(message)

Builds a message object from the given [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md).

| Parameter   | Type                                                                        | Description                |
| ----------- | --------------------------------------------------------------------------- | -------------------------- |
| **message** | [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) | The message to build from. |

**Returns:** [Object](https://docs.microsoft.com/dotnet/api/system.object). An object representing the built message.

**Throws:**

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

### ![](/files/KL0Ik37djZRr8a07Wopd) BuildNativeToolsPrompt(session)

Builds the tools namespace prompt based on the session context.

| Parameter   | Type                                               | Description          |
| ----------- | -------------------------------------------------- | -------------------- |
| **session** | [SmartSession](/ai/components/api/smartsession.md) | The session context. |

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). A string representing the tools prompt.

**Throws:**

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

### ![](/files/KL0Ik37djZRr8a07Wopd) BuildParameters(parameters)

Builds a string representation of tool parameters.

| Parameter      | Type                                                                          | Description                            |
| -------------- | ----------------------------------------------------------------------------- | -------------------------------------- |
| **parameters** | [Parameter\[\]](https://docs.wisej.com/api?q=wisej.ai.smarttool+parameter\[]) | The array of parameters to build from. |

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). A string representing the tool parameters.

### ![](/files/KL0Ik37djZRr8a07Wopd) BuildPayload(session, messages)

Builds a payload object for the given [Session](https://docs.wisej.com/api?q=wisej.core.session) and [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md).

| Parameter    | Type                                                                                        | Description                                     |
| ------------ | ------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| **session**  | [SmartSession](/ai/components/api/smartsession.md)                                          | The session context.                            |
| **messages** | [IList\<Message>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ilist-1) | The list of messages to include in the payload. |

**Returns:** [Object](https://docs.microsoft.com/dotnet/api/system.object). An object representing the built payload.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the session or messages are null.

### ![](/files/ptrKjmmRoQB76pvrIqh0) BuildToolResults(toolResults)

Builds the messages containing tool results.

| Parameter       | Type                                                                              | Description |
| --------------- | --------------------------------------------------------------------------------- | ----------- |
| **toolResults** | [ToolContext\[\]](/ai/components/api/smarttool/wisej.ai.smarttool.toolcontext.md) |             |

**Returns:** [Message\[\]](/ai/components/api/smartsession/wisej.ai.smartsession.message.md). An array of [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) representing the tool results.

### ![](/files/ptrKjmmRoQB76pvrIqh0) BuildToolResultsMessage(toolResults)

Builds a message containing tool results.

| Parameter       | Type                                                                              | Description                      |
| --------------- | --------------------------------------------------------------------------------- | -------------------------------- |
| **toolResults** | [ToolContext\[\]](/ai/components/api/smarttool/wisej.ai.smarttool.toolcontext.md) | The array of tools with results. |

**Returns:** [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md). A [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) representing the tool results.

### ![](/files/KL0Ik37djZRr8a07Wopd) BuildToolsPayload(session)

Builds the tools payload based on the session context.

| Parameter   | Type                                               | Description          |
| ----------- | -------------------------------------------------- | -------------------- |
| **session** | [SmartSession](/ai/components/api/smartsession.md) | The session context. |

**Returns:** [Object\[\]](https://docs.microsoft.com/dotnet/api/system.object). A JSON object representing the tools payload.

**Throws:**

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

### ![](/files/KL0Ik37djZRr8a07Wopd) BuildToolsPrompt(session)

Builds the tools prompt based on the session context.

| Parameter   | Type                                               | Description          |
| ----------- | -------------------------------------------------- | -------------------- |
| **session** | [SmartSession](/ai/components/api/smartsession.md) | The session context. |

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). A string representing the tools prompt.

**Throws:**

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

### ![](/files/KL0Ik37djZRr8a07Wopd) GetCurrentLanguage(session)

Gets the current language based on the session context.

| Parameter   | Type                                               | Description          |
| ----------- | -------------------------------------------------- | -------------------- |
| **session** | [SmartSession](/ai/components/api/smartsession.md) | The session context. |

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). A string representing the current language.

### ![](/files/KL0Ik37djZRr8a07Wopd) GetTodayDescription()

Gets a description of the current date.

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). A string representing the current date.

### ![](/files/ptrKjmmRoQB76pvrIqh0) GetToolsToInvoke(session, message)

Gets the tools to invoke based on the session and message context.

| Parameter   | Type                                                                        | Description          |
| ----------- | --------------------------------------------------------------------------- | -------------------- |
| **session** | [SmartSession](/ai/components/api/smartsession.md)                          | The session context. |
| **message** | [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) | The message context. |

**Returns:** [ToolContext\[\]](/ai/components/api/smarttool/wisej.ai.smarttool.toolcontext.md). An array of [ToolContext](/ai/components/api/smarttool/wisej.ai.smarttool.toolcontext.md) representing the tools to invoke.

**Throws:**

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

### ![](/files/KL0Ik37djZRr8a07Wopd) ReadAssistantMessage(response, message)

Reads the assistant message from the response and updates the message object.

| Parameter    | Type                                                                            | Description                                    |
| ------------ | ------------------------------------------------------------------------------- | ---------------------------------------------- |
| **response** | [Response](/ai/components/api/smartendpoint/wisej.ai.smartendpoint.response.md) | The response containing the assistant message. |
| **message**  | [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md)     | The message object to update.                  |

{% hint style="info" %}
The implementation of this method should call [ReadUsage](#readusage) to keep track if the input and output tokens utilized.
{% endhint %}

### ![](/files/KL0Ik37djZRr8a07Wopd) ReadEmbeddingsResponse(response)

Reads the embeddings response and returns the embeddings data.

| Parameter    | Type                                                                            | Description                              |
| ------------ | ------------------------------------------------------------------------------- | ---------------------------------------- |
| **response** | [Response](/ai/components/api/smartendpoint/wisej.ai.smartendpoint.response.md) | The response containing embeddings data. |

**Returns:** [Single\[\]\[\]](https://docs.microsoft.com/dotnet/api/system.single). A jagged array of floats representing the embeddings.

**Throws:**

* [NotImplementedException](https://docs.microsoft.com/dotnet/api/system.notimplementedexception)\
  Thrown when the method is not implemented.

### ![](/files/KL0Ik37djZRr8a07Wopd) ReadUsage(message, reply)

Reads the usage information from reply.

| Parameter   | Type                                                                        | Description                                        |
| ----------- | --------------------------------------------------------------------------- | -------------------------------------------------- |
| **message** | [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) | The message containing usage information.          |
| **reply**   | [Object](https://docs.microsoft.com/dotnet/api/system.object)               | The reply object to update with usage information. |

## Inherited By

| Name                                                                                                                  | Description                                                                                                                      |
| --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| [AmazonBedrockEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.amazonbedrockendpoint.md)                 | Represents an endpoint for connecting to Amazon Bedrock services.                                                                |
| [AnthropicEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.anthropicendpoint.md)                         | Represents an endpoint for connecting to Anthropic services.                                                                     |
| [AzureAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.azureaiendpoint.md)                             | Represents an endpoint for connecting to Azure AI services, specifically designed to interact with OpenAI models.                |
| [CerebrasEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.cerebrasendpoint.md)                           | Represents a connection to Cerebras endpoints, inheriting from OpenAIEndpoint.                                                   |
| [DeepSeekEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.deepseekendpoint.md)                           | Represents a connection to DeepSeek endpoints, inheriting from OpenAIEndpoint.                                                   |
| [GoogleAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.googleaiendpoint.md)                           | Represents a connection to Google AI endpoints for generating content and embeddings.                                            |
| [GroqCloudEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.groqcloudendpoint.md)                         | <https://console.groq.com/docs/openai>                                                                                           |
| [GroqCloudEndpointWhisper](/ai/components/api/smartendpoint/wisej.ai.endpoints.groqcloudendpointwhisper.md)           | Represents a connection to GroqCloud speech endpoints for audio transcription.                                                   |
| [HuggingFaceEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.huggingfaceendpoint.md)                     | Represents a connection to HuggingFace serverless endpoints for model inference and embeddings.                                  |
| [HuggingFaceJavaScriptEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.huggingfacejavascriptendpoint.md) | Represents an endpoint that uses the transformers.js module in the user's browser to provide AI services to Wisej.AI components. |
| [LocalAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.localaiendpoint.md)                             | Represents a connection to LocalAI endpoints, providing access to various AI models and services.                                |
| [LocalAIEndpointImageGen](/ai/components/api/smartendpoint/wisej.ai.endpoints.localaiendpointimagegen.md)             | Represents an endpoint for connecting to LocalAI Image Generation services.                                                      |
| [LocalAIEndpointTTS](/ai/components/api/smartendpoint/wisej.ai.endpoints.localaiendpointtts.md)                       | Represents an endpoint for connecting to LocalAI's speech services.                                                              |
| [LocalAIEndpointWhisper](/ai/components/api/smartendpoint/wisej.ai.endpoints.localaiendpointwhisper.md)               | Represents an endpoint for connecting to LocalAI's Whisper model for speech-to-text transcriptions.                              |
| [NvidiaAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.nvidiaaiendpoint.md)                           | Represents a connection to NVIDIA AI endpoints, providing access to various AI models and services.                              |
| [OllamaEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.ollamaendpoint.md)                               | Represents an endpoint that connects to Ollama services, providing functionalities for chat and embeddings.                      |
| [OpenAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpoint.md)                               | Represents an endpoint for connecting to OpenAI services.                                                                        |
| [OpenAIEndpointDallE](/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpointdalle.md)                     | Represents an endpoint for connecting to OpenAI DallE services.                                                                  |
| [OpenAIEndpointRealtime](/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpointrealtime.md)               | Represents a component that manages communication with OpenAI's real-time API endpoints.                                         |
| [OpenAIEndpointTTS](/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpointtts.md)                         | Represents an endpoint for connecting to OpenAI's speech services.                                                               |
| [OpenAIEndpointWhisper](/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpointwhisper.md)                 | Represents an endpoint for connecting to OpenAI's Whisper model for speech-to-text transcriptions.                               |
| [SambaNovaEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.sambanovaendpoint.md)                         | Represents a connection to SambaNova endpoints, inheriting from OpenAIEndpoint.                                                  |
| [SmartHttpEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.smarthttpendpoint.md)                         | Represents an abstract base class for a smart HTTP endpoint, providing common functionality for HTTP-based communication.        |
| [TogetherAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.togetheraiendpoint.md)                       | Represents a connection to TogetherAI endpoints, providing access to various AI models and services.                             |
| [XAIEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.xaiendpoint.md)                                     | Represents a connection to X.AI endpoints, extending the functionality of OpenAIEndpoint.                                        |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/ai/components/api/smartendpoint.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
