# OllamaEndpoint

Namespace: **Wisej.AI.Endpoints**

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

* [SmartEndpoint](https://docs.wisej.com/ai/components/api/smartendpoint)
  * [SmartHttpEndpoint](https://docs.wisej.com/ai/components/api/smartendpoint/wisej.ai.endpoints.smarthttpendpoint)
    * [OllamaEndpoint](https://docs.wisej.com/ai/components/api/smartendpoint/wisej.ai.endpoints.ollamaendpoint)

Represents an endpoint that connects to Ollama services, providing functionalities for chat and embeddings.

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

```csharp
public class OllamaEndpoint : SmartHttpEndpoint
```

{% endtab %}

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

```visual-basic
Public Class OllamaEndpoint
    Inherits SmartHttpEndpoint
```

{% endtab %}
{% endtabs %}

This class extends the [SmartHttpEndpoint](https://docs.wisej.com/ai/components/api/smartendpoint/wisej.ai.endpoints.smarthttpendpoint) to interact with Ollama endpoints. It provides methods to construct API URLs, add options to messages, and handle responses.

## 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) OllamaEndpoint()

Initializes a new instance of the [OllamaEndpoint](https://docs.wisej.com/ai/components/api/smartendpoint/wisej.ai.endpoints.ollamaendpoint) class with default settings.

## Properties

### ![](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) EmbeddingModel

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

### ![](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) MaxContextTokens

[Int32](https://docs.microsoft.com/dotnet/api/system.int32): Gets or sets the maximum number of tokens the context window for the specified [Model](https://docs.wisej.com/ai/components/api/smartendpoint/..#model) can hold. (Default: `8192`)

## Methods

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FyTuex2up0Yt5uTtilrkf%2Fprotected.png?alt=media\&token=29b66121-3685-445d-a230-f105b94abee0) AddOptions(message, session)

Adds options to the message for the current session.

| Parameter   | Type                                                                  | Description                                            |
| ----------- | --------------------------------------------------------------------- | ------------------------------------------------------ |
| **message** | [Object](https://docs.microsoft.com/dotnet/api/system.object)         | The dynamic message object to which options are added. |
| **session** | [SmartSession](https://docs.wisej.com/ai/components/api/smartsession) | The current session containing model options.          |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when the message 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) AskEmbeddingsAsync(inputs)

Asynchronously requests embeddings for the specified inputs.

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

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

**Throws:**

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

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FyTuex2up0Yt5uTtilrkf%2Fprotected.png?alt=media\&token=29b66121-3685-445d-a230-f105b94abee0) BuildEmbeddingsPayload(inputs)

Builds the payload for the embeddings request.

| Parameter  | Type                                                              | Description                                               |
| ---------- | ----------------------------------------------------------------- | --------------------------------------------------------- |
| **inputs** | [String\[\]](https://docs.microsoft.com/dotnet/api/system.string) | An array of input strings for which the payload is built. |

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

**Throws:**

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

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FyTuex2up0Yt5uTtilrkf%2Fprotected.png?alt=media\&token=29b66121-3685-445d-a230-f105b94abee0) GetApiURL()

Constructs the API URL for chat interactions.

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

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FyTuex2up0Yt5uTtilrkf%2Fprotected.png?alt=media\&token=29b66121-3685-445d-a230-f105b94abee0) GetEmbeddingsURL()

Constructs the API URL for embeddings interactions.

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

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FyTuex2up0Yt5uTtilrkf%2Fprotected.png?alt=media\&token=29b66121-3685-445d-a230-f105b94abee0) ReadAssistantMessage(response, message)

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

| Parameter    | Type                                                                                               | Description                                                     |
| ------------ | -------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| **response** | [Response](https://docs.wisej.com/ai/components/api/smartendpoint/wisej.ai.smartendpoint.response) | The response received from the API.                             |
| **message**  | [Message](https://docs.wisej.com/ai/components/api/smartsession/wisej.ai.smartsession.message)     | The message object to be updated with the assistant's response. |

**Throws:**

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

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FyTuex2up0Yt5uTtilrkf%2Fprotected.png?alt=media\&token=29b66121-3685-445d-a230-f105b94abee0) ReadEmbeddingsResponse(response)

Reads the embeddings response and extracts the embeddings data.

| Parameter    | Type                                                                                               | Description                         |
| ------------ | -------------------------------------------------------------------------------------------------- | ----------------------------------- |
| **response** | [Response](https://docs.wisej.com/ai/components/api/smartendpoint/wisej.ai.smartendpoint.response) | The response received from the API. |

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

**Throws:**

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

### ![](https://1941161015-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFjp24h5m0lgli5swqzhO%2Fuploads%2FyTuex2up0Yt5uTtilrkf%2Fprotected.png?alt=media\&token=29b66121-3685-445d-a230-f105b94abee0) ReadUsage(message, reply)

Reads the usage statistics from the reply and updates the message usage.

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