Skip to main content

HuggingFaceJavaScriptEndpoint

Namespace: Wisej.AI.Endpoints

Assembly: Wisej.AI

Represents an endpoint that uses the transformers.js module in the user's browser to provide AI services to Wisej.AI components.

public class HuggingFaceJavaScriptEndpoint : SmartEndpoint

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​

HuggingFaceJavaScriptEndpoint()​

Initializes a new instance of the HuggingFaceJavaScriptEndpoint.

Properties​

Id​

String: Gets the unique identifier for the component.

Model​

String: Gets or sets the model used by the endpoint. (Default: null)

Pipeline​

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

PipelineSubtask​

String: Gets or sets the subtask for the selected pipeline. (Default: "")

This property allows further specification of the task within the chosen pipeline. index

SourceURL​

String: Gets or sets the source URL for the transformers.js library. (Default: "https://cdn.jsdelivr.net/npm/@xenova/transformers")

Methods​

AskAsync(session, messages)​

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

ParameterTypeDescription
sessionSmartSessionThe current smart session.
messagesIList<Message>A list of messages to process.

Returns: Task<Message>. A task that represents the asynchronous operation. The task result contains the response message.

Throws:

Dispose(disposing)​

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

ParameterTypeDescription
disposingBooleantrue to release both managed and unmanaged resources; false to release only unmanaged resources.

GetSimilarityAsync(query, text)​

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

ParameterTypeDescription
queryStringThe query string to compare.
textString[]An array of text strings to compare against the query.

Returns: Task<Single[]>. A task that represents the asynchronous operation. The task result contains an array of similarity scores.

ReadAssistantMessage(response, message)​

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

ParameterTypeDescription
responseResponseThe response containing the assistant message.
messageMessageThe message to update with the assistant's response.

Throws:

ReadUsage(message, reply)​

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

ParameterTypeDescription
messageMessageThe message to update with usage information.
replyObjectThe reply containing usage information.