SmartHub
Namespace: Wisej.AI
Assembly: Wisej.AI
Represents a SmartHub component that provides AI capabilities to controls within a container.
- C#
- VB.NET
public class SmartHub : SmartObject, IExtenderProvider, IToolProvider
Public Class SmartHub
Inherits SmartObject
Implements 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 | ContainerControl | The container control to which the SmartHub is attached. |
Throws:
- ArgumentNullException Thrown when the containerControl is null.
SmartHub(container)
Initializes a new instance of the SmartHub class attached to an IContainer implementation.
| Name | Type | Description |
|---|---|---|
| container | IContainer | 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 | String | The question to ask. |
| image | Image | An optional image to include in the question. Default is null. |
| systemPrompt | String | Option system prompt. |
Returns: Task<Message>. A task representing the asynchronous operation, with a Message as the result.
Throws:
- ArgumentNullException Thrown when the question is null.
Dispose(disposing)
Releases the unmanaged resources used by the SmartHub 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. |
EmbedAsync(text)
Asynchronously generates an embedding for a specified text.
| Parameter | Type | Description |
|---|---|---|
| text | String | 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 | String[] | The text chunks to embed. |
Returns: Task<Embedding>. A task representing the asynchronous operation, with an Embedding as the result.
Throws:
- ArgumentNullException Thrown when the chunks array is null.
GetAdapter(control)
Gets the adapter associated with a specified control.
| Parameter | Type | Description |
|---|---|---|
| control | Control | The control for which to get the adapter. |
Returns: SmartAdapter. The SmartAdapter associated with the control, or null if none exists.
Throws:
- ArgumentNullException Thrown when the control is null.
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 | 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:
- ArgumentNullException Thrown when the control is null.
GetAI(control)
Gets the AI properties for a specified control.
| Parameter | Type | Description |
|---|---|---|
| control | 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 | Parameter | The parameter for which to get the value. |
Returns: Object. The value of the parameter as a string.
Throws:
- ArgumentNullException Thrown when the parameter is null.
IngestDocumentAsync(filePath, documentName, collectionName, metadata, overwrite)
Asynchronously ingests a document from a specified file path.
| Parameter | Type | Description |
|---|---|---|
| filePath | String | The file path of the document to ingest. |
| documentName | String | The name of the document. |
| collectionName | String | The name of the collection. Default is null. |
| metadata | Metadata | The metadata for the document. Default is null. |
| overwrite | Boolean | 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:
- ArgumentNullException Thrown when the filePath or documentName is null.
IngestDocumentAsync(stream, documentName, collectionName, overwrite, metadata)
Asynchronously ingests a document from a specified stream.
| Parameter | Type | Description |
|---|---|---|
| stream | Stream | The stream of the document to ingest. |
| documentName | String | The name of the document. |
| collectionName | String | The name of the collection. Default is null. |
| overwrite | Boolean | Whether to overwrite an existing document. Default is false. |
| metadata | 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:
- ArgumentNullException Thrown when the stream or documentName is null.
RemoveAdapter(adapter)
Removes a specified adapter from the SmartHub.
| Parameter | Type | Description |
|---|---|---|
| adapter | SmartAdapter | The adapter to remove. |
Throws:
- ArgumentNullException Thrown when the adapter is null.
RemoveTool(tool)
Removes a tool from the SmartHub.
| Parameter | Type | Description |
|---|---|---|
| tool | Delegate | The tool to remove. |
Returns: SmartHub. The current SmartHub instance.
Throws:
- ArgumentNullException Thrown when the tool is null.
SimilarityQueryAsync(query, chunks, topN, minSimilarity, computeSimilarity)
Asynchronously performs a similarity query on a specified query and text chunks.
| Parameter | Type | Description |
|---|---|---|
| query | String | The query text. |
| chunks | String[] | The text chunks to compare against. |
| topN | Int32 | The number of top results to return. |
| minSimilarity | Single | The 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:
- ArgumentNullException Thrown when the query or chunks are null.
SimilarityQueryAsync(query, chunks, vectors, topN, minSimilarity, computeSimilarity)
Asynchronously performs a similarity query on a specified query, text chunks, and vectors.
| Parameter | Type | Description |
|---|---|---|
| query | String | The query text. |
| chunks | String[] | The text chunks to compare against. |
| vectors | Single[][] | The vectors to compare against. |
| topN | Int32 | The number of top results to return. |
| minSimilarity | Single | The 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:
- ArgumentNullException Thrown when the query, chunks, or vectors are null.
SimilarityScoreAsync(query, chunks, computeSimilarity)
Asynchronously calculates similarity scores for a specified query and text chunks.
| Parameter | Type | Description |
|---|---|---|
| query | String | The query text. |
| chunks | String[] | 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:
- ArgumentNullException Thrown when the query or chunks are null.
SimilarityScoreAsync(query, chunks, embeddings, computeSimilarity)
Asynchronously calculates similarity scores for a specified query, text chunks, and embeddings.
| Parameter | Type | Description |
|---|---|---|
| query | String | The query text. |
| chunks | String[] | The text chunks to compare against. |
| embeddings | Single[][] | 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:
- ArgumentNullException Thrown when the query, chunks, or embeddings are null.
UseTool(tool)
Adds a tool to the SmartHub.
| Parameter | Type | Description |
|---|---|---|
| tool | Delegate | The tool to add. |
Returns: SmartHub. The current SmartHub instance.
Throws:
- ArgumentNullException Thrown when the tool is null.
UseTools(target)
Uses tools from a specified target.
| Parameter | Type | Description |
|---|---|---|
| target | Object | The target from which to use tools. |
Returns: SmartHub. The current SmartHub instance.
Implements
| Name | Description |
|---|---|
| IToolProvider | Represents a provider that supplies tools. |