> For the complete documentation index, see [llms.txt](https://docs.wisej.com/ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wisej.com/ai/components/api/smartendpoint/wisej.ai.endpoints.huggingfacejavascriptendpoint.md).

# HuggingFaceJavaScriptEndpoint

Namespace: **Wisej.AI.Endpoints**

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

* [SmartEndpoint](/ai/components/api/smartendpoint.md)
  * [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.

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

```csharp
public class HuggingFaceJavaScriptEndpoint : SmartEndpoint
```

{% endtab %}

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

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

{% endtab %}
{% endtabs %}

This class is part of the SmartEndpoint category and is designed to interact with the Hugging Face transformers.js library. It provides various AI services such as text generation, translation, and more, by utilizing different pipelines.

## Constructors

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

Initializes a new instance of the [HuggingFaceJavaScriptEndpoint](/ai/components/api/smartendpoint/wisej.ai.endpoints.huggingfacejavascriptendpoint.md).

## Properties

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

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets the unique identifier for the component.

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

[TransformersPipeline](https://docs.wisej.com/api?q=wisej.ai.endpoints.huggingfacejavascriptendpoint+transformerspipeline): Gets or sets the pipeline used by the endpoint. (Default: `None`)

The pipeline determines the type of AI service provided, such as translation or text generation. [index](https://huggingface.co/docs/transformers.js/en/index)

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

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the subtask for the selected pipeline. (Default: `""`)

This property allows further specification of the task within the chosen pipeline. [index](https://huggingface.co/docs/transformers.js/en/index)

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

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the source URL for the transformers.js library. (Default: `"https://cdn.jsdelivr.net/npm/@xenova/transformers"`)

## Methods

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

Asynchronously processes a list of messages and returns a response message.

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

**Returns:** [Task\<Message>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task that represents the asynchronous operation. The task result contains the response message.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  Thrown when session or messages is null.
* [NotSupportedException](https://docs.microsoft.com/dotnet/api/system.notsupportedexception)\
  Thrown when the pipeline is not supported.

### ![](/files/KL0Ik37djZRr8a07Wopd) Dispose(disposing)

Releases the unmanaged resources used by the component and optionally releases the managed resources.

| Parameter     | Type                                                            | Description                                                                                      |
| ------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| **disposing** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | true to release both managed and unmanaged resources; false to release only unmanaged resources. |

### ![](/files/ptrKjmmRoQB76pvrIqh0) GetSimilarityAsync(query, text)

Asynchronously calculates the similarity between a query and an array of text.

| Parameter | Type                                                              | Description                                            |
| --------- | ----------------------------------------------------------------- | ------------------------------------------------------ |
| **query** | [String](https://docs.microsoft.com/dotnet/api/system.string)     | The query string to compare.                           |
| **text**  | [String\[\]](https://docs.microsoft.com/dotnet/api/system.string) | An array of text strings to compare against the query. |

**Returns:** [Task\<Single\[\]>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task that represents the asynchronous operation. The task result contains an array of similarity scores.

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

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

| 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 to update with the assistant's response. |

**Throws:**

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

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

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

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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/wisej.ai.endpoints.huggingfacejavascriptendpoint.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.
