Skip to main content

SmartHub

Namespace: Wisej.AI

Assembly: Wisej.AI

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.

NameTypeDescription
containerControlContainerControlThe container control to which the SmartHub is attached.

Throws:

SmartHub(container)

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

NameTypeDescription
containerIContainerAn 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.

ParameterTypeDescription
questionStringThe question to ask.
image ImageAn optional image to include in the question. Default is null.
systemPrompt StringOption 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.

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

EmbedAsync(text)

Asynchronously generates an embedding for a specified text.

ParameterTypeDescription
textStringThe 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.

ParameterTypeDescription
chunksString[]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.

ParameterTypeDescription
controlControlThe 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.

ParameterTypeDescription
TThe type of the adapter.
controlControlThe 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.

ParameterTypeDescription
controlControlThe 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.

ParameterTypeDescription
parameterParameterThe 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.

ParameterTypeDescription
filePathStringThe file path of the document to ingest.
documentNameStringThe name of the document.
collectionName StringThe name of the collection. Default is null.
metadata MetadataThe metadata for the document. Default is null.
overwrite BooleanWhether 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.

ParameterTypeDescription
streamStreamThe stream of the document to ingest.
documentNameStringThe name of the document.
collectionName StringThe name of the collection. Default is null.
overwrite BooleanWhether to overwrite an existing document. Default is false.
metadata MetadataThe 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.

ParameterTypeDescription
adapterSmartAdapterThe adapter to remove.

Throws:

RemoveTool(tool)

Removes a tool from the SmartHub.

ParameterTypeDescription
toolDelegateThe 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.

ParameterTypeDescription
queryStringThe query text.
chunksString[]The text chunks to compare against.
topNInt32The number of top results to return.
minSimilaritySingleThe minimum similarity threshold.
computeSimilarity Func<Single[], Single[][], Single[]>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.

ParameterTypeDescription
queryStringThe query text.
chunksString[]The text chunks to compare against.
vectorsSingle[][]The vectors to compare against.
topNInt32The number of top results to return.
minSimilaritySingleThe minimum similarity threshold.
computeSimilarity Func<Single[], Single[][], Single[]>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.

ParameterTypeDescription
queryStringThe query text.
chunksString[]The text chunks to compare against.
computeSimilarity Func<Single[], Single[][], Single[]>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.

ParameterTypeDescription
queryStringThe query text.
chunksString[]The text chunks to compare against.
embeddingsSingle[][]The embeddings to compare against.
computeSimilarity Func<Single[], Single[][], Single[]>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.

ParameterTypeDescription
toolDelegateThe tool to add.

Returns: SmartHub. The current SmartHub instance.

Throws:

UseTools(target)

Uses tools from a specified target.

ParameterTypeDescription
targetObjectThe target from which to use tools.

Returns: SmartHub. The current SmartHub instance.

Implements

NameDescription
IToolProviderRepresents a provider that supplies tools.