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.
- C#
- VB.NET
public class HuggingFaceJavaScriptEndpoint : SmartEndpoint
Public Class HuggingFaceJavaScriptEndpoint
Inherits 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.
| Parameter | Type | Description |
|---|---|---|
| session | SmartSession | The current smart session. |
| messages | IList<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:
- ArgumentNullException Thrown when session or messages is null.
- NotSupportedException Thrown when the pipeline is not supported.
Dispose(disposing)
Releases the unmanaged resources used by the component and optionally releases the managed resources.
| Parameter | Type | Description |
|---|---|---|
| disposing | Boolean | true 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.
| Parameter | Type | Description |
|---|---|---|
| query | String | The query string to compare. |
| text | String[] | 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.
| Parameter | Type | Description |
|---|---|---|
| response | Response | The response containing the assistant message. |
| message | Message | The message to update with the assistant's response. |
Throws:
- ArgumentNullException Thrown when response or message is null.
ReadUsage(message, reply)
Reads the usage information from the reply and updates the message.
| Parameter | Type | Description |
|---|---|---|
| message | Message | The message to update with usage information. |
| reply | Object | The reply containing usage information. |