SmartHub

Wisej.AI.SmartHub

Namespace: Wisej.AI

Assembly: Wisej.AI (3.5.0.0)

Represents a SmartHub component that provides AI capabilities to controls within a container.

public class SmartHub : SmartObject, IExtenderProvider, IToolProvider

The SmartHub class is an extender provider that allows controls to be extended with AI functionalities. It manages various services and tools to facilitate AI operations, such as embedding generation, document conversion, and similarity queries.

Constructors

SmartHub()

Initializes a new instance of the SmartHub class.

SmartHub(containerControl)

Initializes a new instance of the SmartHub class with a specified container control.

Name
Type
Description

containerControl

The container control to which the SmartHub is attached.

Throws:

SmartHub(container)

Initializes a new instance of the SmartHub class attached to an IContainer implementation.

Name
Type
Description

container

An IContainer that represents the container of the SmartHub extender.

Properties

BindingContext

BindingContext: Gets the binding context for the SmartHub.

ContainerControl

Control: Returns or sets the container Controlthat provides the BindingContext for binding to the IDataErrorInfo interface implemented by a DataSource. (Default: null)

Culture

CultureInfo: Gets or sets the culture information for the SmartHub. (Default: null)

DataSource

Object: Gets or sets a data source that can be used to resolve prompt parameters. (Default: null)

Endpoint

SmartEndpoint: Gets or sets the default endpoint. (Default: null)

IsDisposed

Boolean: Gets a value indicating whether the SmartHub is disposed.

Methods

AskAsync(question, image, systemPrompt)

Asynchronously asks a question and returns a response message.

Parameter
Type
Description

question

The question to ask.

image

An optional image to include in the question. Default is null.

systemPrompt

Option system prompt.

Returns: Task<Message>. A task representing the asynchronous operation, with a Message as the result.

Throws:

Dispose(disposing)

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

Parameter
Type
Description

disposing

true to release both managed and unmanaged resources; false to release only unmanaged resources.

EmbedAsync(text)

Asynchronously generates an embedding for a specified text.

Parameter
Type
Description

text

The text to embed.

Returns: Task<Embedding>. A task representing the asynchronous operation, with an Embedding as the result.

EmbedAsync(chunks)

Asynchronously generates an embedding for a specified array of text chunks.

Parameter
Type
Description

chunks

The text chunks to embed.

Returns: Task<Embedding>. A task representing the asynchronous operation, with an Embedding as the result.

Throws:

GetAdapter(control)

Gets the adapter associated with a specified control.

Parameter
Type
Description

control

The control for which to get the adapter.

Returns: SmartAdapter. The SmartAdapter associated with the control, or null if none exists.

Throws:

GetAdapter<T>(control)

Gets the adapter of a specified type associated with a specified control.

Parameter
Type
Description

T

The type of the adapter.

control

The control for which to get the adapter.

Returns: T. The adapter of type T associated with the control, or null if none exists.

Throws:

GetAI(control)

Gets the AI properties for a specified control.

Parameter
Type
Description

control

The control for which to get the AI properties.

Returns: Properties. The Properties associated with the control.

GetParameterValue(parameter)

Gets the value of a specified parameter.

Parameter
Type
Description

parameter

The parameter for which to get the value.

Returns: Object. The value of the parameter as a string.

Throws:

IngestDocumentAsync(filePath, documentName, collectionName, metadata, overwrite)

Asynchronously ingests a document from a specified file path.

Parameter
Type
Description

filePath

The file path of the document to ingest.

documentName

The name of the document.

collectionName

The name of the collection. Default is null.

metadata

The metadata for the document. Default is null.

overwrite

Whether to overwrite an existing document. Default is false.

Returns: Task<EmbeddedDocument>. A task representing the asynchronous operation, with an EmbeddedDocument as the result.

This method utilizes several services to perform its operations: ITextSplitterService, and IDocumentConversionService, and IEmbeddingGenerationService, and IEmbeddingStorageService.Throws:

IngestDocumentAsync(stream, documentName, collectionName, overwrite, metadata)

Asynchronously ingests a document from a specified stream.

Parameter
Type
Description

stream

The stream of the document to ingest.

documentName

The name of the document.

collectionName

The name of the collection. Default is null.

overwrite

Whether to overwrite an existing document. Default is false.

metadata

The metadata for the document. Default is null.

Returns: Task<EmbeddedDocument>. A task representing the asynchronous operation, with an EmbeddedDocument as the result.

This method utilizes several services to perform its operations: ITextSplitterService, and IDocumentConversionService, and IEmbeddingGenerationService, and IEmbeddingStorageService.Throws:

RemoveAdapter(adapter)

Removes a specified adapter from the SmartHub.

Parameter
Type
Description

adapter

The adapter to remove.

Throws:

RemoveTool(tool)

Removes a tool from the SmartHub.

Parameter
Type
Description

tool

The tool to remove.

Returns: SmartHub. The current SmartHub instance.

Throws:

SimilarityQueryAsync(query, chunks, topN, minSimilarity, computeSimilarity)

Asynchronously performs a similarity query on a specified query and text chunks.

Parameter
Type
Description

query

The query text.

chunks

The text chunks to compare against.

topN

The number of top results to return.

minSimilarity

The minimum similarity threshold.

computeSimilarity

The function to compute similarity. Default is null.

Returns: Task<String[]>. A task representing the asynchronous operation, with an array of strings as the result.

Throws:

SimilarityQueryAsync(query, chunks, vectors, topN, minSimilarity, computeSimilarity)

Asynchronously performs a similarity query on a specified query, text chunks, and vectors.

Parameter
Type
Description

query

The query text.

chunks

The text chunks to compare against.

vectors

The vectors to compare against.

topN

The number of top results to return.

minSimilarity

The minimum similarity threshold.

computeSimilarity

The function to compute similarity. Default is null.

Returns: Task<String[]>. A task representing the asynchronous operation, with an array of strings as the result.

Throws:

SimilarityScoreAsync(query, chunks, computeSimilarity)

Asynchronously calculates similarity scores for a specified query and text chunks.

Parameter
Type
Description

query

The query text.

chunks

The text chunks to compare against.

computeSimilarity

The function to compute similarity. Default is null.

Returns: Task<Single[]>. A task representing the asynchronous operation, with an array of floats as the result.

Throws:

SimilarityScoreAsync(query, chunks, embeddings, computeSimilarity)

Asynchronously calculates similarity scores for a specified query, text chunks, and embeddings.

Parameter
Type
Description

query

The query text.

chunks

The text chunks to compare against.

embeddings

The embeddings to compare against.

computeSimilarity

The function to compute similarity. Default is null.

Returns: Task<Single[]>. A task representing the asynchronous operation, with an array of floats as the result.

Throws:

UseTool(tool)

Adds a tool to the SmartHub.

Parameter
Type
Description

tool

The tool to add.

Returns: SmartHub. The current SmartHub instance.

Throws:

UseTools(target)

Uses tools from a specified target.

Parameter
Type
Description

target

The target from which to use tools.

Returns: SmartHub. The current SmartHub instance.

Implements

Name
Description

Represents a provider that supplies tools.

Last updated