Using SmartHub
Last updated
Last updated
The primary function of the SmartHub is to connect multiple SmartAdapters and offer a centralized location for managing the events from these associated adapters. It provides intuitive design-time UI editors that enable developers to easily select and incorporate endpoints and adapters into the container currently being designed.
Furthermore, a SmartHub automatically scans its container for methods that are marked with the [SmartTool.Tool]
attribute. These methods are seamlessly integrated as tools into the SmartAdapters associated with the SmartHub. The tools that are imported from the container operate within the context of the container itself. Consequently, there is no need to invoke the UseTools or UseTool methods in this scenario.
To utilize a SmartHub instance, you have two options: you can either drag and drop it from the toolbox onto a design surface (refer to the page for more details) or you can instantiate the component programmatically. When creating the SmartHub instance through code, you have the option to specify a container for the component, although this is not mandatory. This flexibility allows developers to integrate the SmartHub instance into their applications in a manner that best fits their workflow and project structure.
Using a SmartHub is required only when using one of the adapters. Otherwise, you can access all Wisej.AI features without setting up a SmartHub. It is entirely possible to instantiate and utilize any the SmartPrompt or SmartSession classes independently of a SmartHub.
However, if your project requires centralized management of certain events, monitoring the utilization of AI providers from a unified location, or the automatic importation of tools defined in a container, the SmartHub class becomes particularly useful.
In addition to offering a centralized hub for multiple adapters, the SmartHub class provides advanced functionality designed to streamline the processes of document ingestion and embedding. This includes the capability to perform similarity queries and calculate similarity scores between vectors with ease.
The following code snippet illustrates the simplest method to convert, vectorize, and store a document into a vector database. This streamlined process is achieved with just a single line of code, powered by the Wisej.AI services.
This line of code involves several services that work together in a sequence to convert and store a PDF document as a an . First, the IDocumentConversionService
is used to convert the PDF document into a text format, allowing for easier manipulation and processing of its contents. Next, the ITextSplitterService
takes over to divide the converted text into overlapping chunks. These chunks assist in maximizing context and relevance when the text is later analyzed or queried. Following this, the IEmbeddingGenerationService
processes these text chunks, transforming them into vectors via embedding, which is a numerical representation that captures the semantic meaning of the text. Finally, the IEmbeddingStorageService
saves these generated vectors, accompanying text chunks, and associated metadata into a vector database. This storage format facilitates efficient retrieval and utilization of the document's content in future operations.
Once documents are ingested, they become accessible to all components of Wisej.AI through the DocumentSearchTools
object. This integration ensures that any part of the Wisej.AI framework that requires access to the processed documents can retrieve and utilize them as needed.
ContainerControl
Control associated with the SmartHub. Can be a Page, a Form or any ContainerControl in Wisej.NET.
Culture
Overrides the default language of the application. If you want your AI to speak a particular language without changing the application's culture, use this property.
DataSource
Optional data source object that can be used to resolve parameters in prompts. Parametere are delimited by {{}}. I.e. {{UserName}}
Endpoint
Endpoint used by the adapters associated to the SmartHub.
Below are some examples demonstrating some of the functionalities offered by the SmartHub component:
Simple Logging Example: This example illustrates a straightforward approach, which involves logging all usage reported by the AI provider.
Advanced Tool Processing Example: This example is more complex, enabling the SmartHub to either pre-process or post-process tool invocations.
Quick Similarity Score: Calculates similarity between a query and an an array of text strings using smartHub’s async embedding-based similarity function.
When generating embeddings with the default IEmbeddingGenerationService
, ensure the correct ApiKey
is available to the service’s endpoint—either set as an environment variable or specified in the file.