LogoLogo
HomeNewsSupportVideos
  • Welcome
  • Wisej.NET
  • Concepts
    • Getting Started
    • General Concepts
    • Architecture
    • Extensibility
    • AI Providers
    • Vector Databases
    • Usage Metrics
    • Logging & Error Handling
  • Markup
  • Components
    • API
      • SmartAdapter
        • SmartAudioTTSAdapter
        • SmartAudioWhisperAdapter
        • SmartCalendarAdapter
        • SmartChartAdapter
        • SmartChartJS3Adapter
        • SmartChatBoxAdapter
        • SmartComboBoxAdapter
        • SmartCopilotAdapter
        • SmartDataEntryAdapter
        • SmartDocumentAdapter
        • SmartFullCalendarAdapter
        • SmartObjectAdapter
        • SmartPictureBoxAdapter
        • SmartQueryAdapter
        • SmartRealtimeAdapter
        • SmartReportAdapter
        • SmartTextBoxAdapter
        • SmartAdapter.ExtendsAttribute
        • SmartAdapter.FieldNameAttribute
        • SmartAdapter.FieldPromptAttribute
        • SmartAdapter.FieldRectangleAttribute
        • SmartAdapter.WorksWithAttribute
      • SmartEndpoint
        • AmazonBedrockEndpoint
        • AnthropicEndpoint
        • AzureAIEndpoint
        • CerebrasEndpoint
        • DeepSeekEndpoint
        • GoogleAIEndpoint
        • GroqCloudEndpoint
        • GroqCloudEndpointWhisper
        • HuggingFaceEndpoint
        • HuggingFaceJavaScriptEndpoint
        • LocalAIEndpoint
        • LocalAIEndpointImageGen
        • LocalAIEndpointTTS
        • LocalAIEndpointWhisper
        • NvidiaAIEndpoint
        • OllamaEndpoint
        • OpenAIEndpoint
        • OpenAIEndpointDallE
        • OpenAIEndpointRealtime
        • OpenAIEndpointTTS
        • OpenAIEndpointWhisper
        • SambaNovaEndpoint
        • SmartHttpEndpoint
        • TogetherAIEndpoint
        • XAIEndpoint
        • SmartEndpoint.Metrics
        • SmartEndpoint.Response
      • SmartExtensions
      • SmartHub
        • SmartSession.ConvertParameterEventArgs
        • SmartSession.ConvertParameterEventHandler
        • SmartSession.ErrorEventArgs
        • SmartSession.ErrorEventHandler
        • SmartSession.InvokeToolEventArgs
        • SmartSession.InvokeToolEventHandler
        • SmartSession.MessagesEventArgs
        • SmartSession.MessagesEventHandler
      • SmartObject
      • SmartPrompt
        • SmartAgentPrompt
        • SmartParallelPrompt
        • SmartPrompt.Parameter
        • SmartSession.ConvertParameterEventArgs
        • SmartSession.ConvertParameterEventHandler
        • SmartSession.ErrorEventArgs
        • SmartSession.ErrorEventHandler
        • SmartSession.InvokeToolEventArgs
        • SmartSession.InvokeToolEventHandler
        • SmartSession.MessagesEventArgs
        • SmartSession.MessagesEventHandler
      • SmartRealtimeSession
      • SmartSession
        • SmartSession.ConvertParameterEventArgs
        • SmartSession.ConvertParameterEventHandler
        • SmartSession.ErrorEventArgs
        • SmartSession.ErrorEventHandler
        • SmartSession.InvokeToolEventArgs
        • SmartSession.InvokeToolEventHandler
        • SmartSession.Message
        • SmartSession.MessageCollection
        • SmartSession.MessageRole
        • SmartSession.MessagesEventArgs
        • SmartSession.MessagesEventHandler
        • SmartSession.TrimmingStrategy
      • SmartTool
        • SmartTool.IToolProvider
        • SmartTool.ToolAttribute
        • SmartTool.ToolContext
      • Markup
        • MarkupExtensions
      • Controls
        • UVLightOverlay
      • Embeddings
        • EmbeddedDocument
        • Embedding
        • Matches
        • Metadata
      • Helpers
        • ApiKeys
        • Markdown
        • TextTokenizer
      • Services
        • DefaultSessionTrimmingService
        • IDocumentConversionService
          • DefaultDocumentConversionService
        • IEmbeddingGenerationService
          • DefaultEmbeddingGenerationService
          • HuggingFaceEmbeddingGenerationService
        • IEmbeddingStorageService
          • AzureAISearchEmbeddingStorageService
          • ChromaEmbeddingStorageService
          • FileSystemEmbeddingStorageService
          • MemoryEmbeddingStorageService
          • PineconeEmbeddingStorageService
          • QdrantEmbeddingStorageService
        • IHttpClientService
          • DefaultHttpClientService
        • ILoggerService
          • DefaultLoggerService
        • IOCRService
          • DefaultOCRService
        • IRerankingService
          • DefaultRerankingService
          • LocalAIRerankingService
          • PineconeRerankingService
        • ISessionTrimmingService
          • DefaultSessionTrimmingService
        • ITextSplitterService
          • RecursiveCharacterTextSplitterService
          • TextSplitterServiceBase
        • ITokenizerService
          • DefaultTokenizerService
        • IWebSearchService
          • BingWebSearchService
          • BraveWebSearchService
          • GoogleWebSearchService
      • Tools
        • ArxivTools
        • ChartJS3Tools
        • DatabaseTools
        • DataTableFilterTools
        • DocumentSearchTools
        • DocumentTools
        • FullCalendarTools
        • IToolsContainer
        • MathTools
        • ToolsContainer
        • UtilityTools
        • WebSearchTools
    • Built-in Services
      • IOCRService
      • ILoggerService
      • ITextSplitterService
      • ITokenizerService
      • IHttpClientService
      • IWebSearchService
      • IRerankingService
      • ISessionTrimmingService
      • IDocumentConversionService
      • IEmbeddingStorageService
      • IEmbeddingGenerationService
    • Built-in SmartTools
      • ToolsContainer
      • MathTools
      • UtilityTools
      • DatabaseTools
      • DocumentTools
      • DocumentSearchTools
      • WebSearchTools
      • ChartJS3Tools
      • FullCalendarTools
    • Built-in SmartAdapters
      • SmartAdapter
      • SmartAudioTTSAdapter
      • SmartAudioWhisperAdapter
      • SmartCalendarAdapter
      • SmartChartAdapter
      • SmartChartJS3Adapter
      • SmartChatBoxAdapter
      • SmartComboBoxAdapter
      • SmartCopilotAdapter
      • SmartDataEntryAdapter
      • SmartDocumentAdapter
      • SmartFullCalendarAdapter
      • SmartObjectAdapter
      • SmartPictureBoxAdapter
      • SmartQueryAdapter
      • SmartRealtimeAdapter
      • SmartReportAdapter
      • SmartTextBoxAdapter
    • Configure Services
    • Using SmartHub
    • Using SmartTools
    • Using SmartPrompt
    • Using SmartSession
    • Using SmartRealTimeAdapter
    • UVLightOverlay Control
Powered by GitBook
On this page
  • Overview
  • Existing Services
  • Replacing Services
  • Services Lifetime
Export as PDF
  1. Components

Built-in Services

Overridable built-in services

Overview

To provide greater flexibility and avoid the over-engineering often associated with framework libraries, along with the confusing and conflicting typical WithThis(), AddThat() chaining methods, Wisej.AI employs overridable services for higher-level functionalities. This design allows developers to easily customize these functionalities to suit their specific needs.

Existing Services

Here are the services utilized by various Wisej.AI components, along with their default implementations:

Service
Implementations
Used by

DefaultOCRService

SmartObjectAdapter

SmartDataEntryAdapter

DefaultLoggerService

Everywhere

RecursiveCharacterTextSplitterService

SmartHub

DefaultTokenizerService

DatabaseTools

WebSearchTools

DocumentSearchTools

DefaultHttpClientService

SmartHttpEndpoint

PineconeEmbeddingStorageService

AzureAISearchEmbeddingStorageService

ChromaEmbeddingStorageService

HuggingFaceEmbeddingGenerationService

WebSearchTools

BingWebSearchService

GoogleWebSearchService

BraveWebSearchService

WebSearchTools

DefaultSessionTrimmingService

SmartSession

DefaultRerankingService

DocumentTools DocumentSearchTools

DefaultDocumentConversionService

SmartHub

SmartReportAdapter

WebSearchTools

MemoryEmbeddingStorageService

FileSystemEmbeddingStorageService

ChromaEmbeddingStorageService

PineconeEmbeddingStorageService

AzureAISearchEmbeddingStorageService

SmartHub

SmartDocumentAdapter DocumentTools

DocumentSearchTools

DefaultEmbeddingGenerationService

SmartHub DocumentTools

DocumentSearchTools

Please note that the IWebSearchService does not have any default implementation pre-registered by Wisej.AI. If you use the WebSearchTools without registering a web search service, it will not return any results.

Replacing Services

To replace any of the built-in services, simply implement the corresponding interface and register your service. The optimal place to perform this registration is in the static constructor of the Program class or module in VB.NET.

Alternatively, you can extend any of the built-in service implementations by overriding the virtual properties and methods. In this case, you still need to create your own service class, but instead of implementing the interface from scratch, you extend the existing service implementation and override only the parts you wish to modify.

For instance, if you want to use Aspose PDF for converting PDF documents to text while retaining the default IDocumentConversionService, you can follow this approach:

public class AsposeDocumentConversionService 
	: DefaultDocumentConversionService
{
  static AsposeDocumentConversionService()
  {
    new Aspose.Pdf.License()
      .SetLicense(
        File.OpenRead(Application.MapPath("Aspose.Pdf.lic")));
  }
  
  public string[] Convert(
          Stream stream, 
          string fileType, Metadata metadata = null)
  {
    if (fileType == "pdf")
      return ConvertPdfToText(stream, metadata);

    return base.Convert(stream, fileType);
  }
}
Public Class AsposeDocumentConversionService
  Inherits DefaultDocumentConversionService

  Shared Sub New()
    Dim license As New Aspose.Pdf.License()
      license.SetLicense(File.OpenRead(Application.MapPath("Aspose.Pdf.lic")))
  End Sub

  Public Overloads Function Convert( _
                    stream As Stream, _
                    fileType As String, _
                    Optional metadata As Metadata = Nothing) As String()

    If fileType = "pdf" Then
      Return ConvertPdfToText(stream, metadata)
    End If
        
    Return MyBase.Convert(stream, fileType)
  End Function

End Class

When the default implementation doesn't offer virtual methods, you can still leverage it by maintaining an instance of the default implementation within your service implementation. Here's how you can do it:

public class AsposeDocumentConversionService 
	: IDocumentConversionService
{
  private IDocumentConversionService _baseService;
  
  static AsposeDocumentConversionService()
  {
    new Aspose.Pdf.License()
      .SetLicense(
        File.OpenRead(Application.MapPath("Aspose.Pdf.lic")));
  }
  
  public AsposeDocumentConversionService()
  {
    _baseService = new DefaultDocumentConversionService();
  }
  
  public string[] Convert(
          Stream stream, 
          string fileType, Metadata metadata = null)
  {
    if (fileType == "pdf")
      return ConvertPdfToText(stream, metadata);

    return _baseService.Convert(stream, fileType);
  }
}
Public Class AsposeDocumentConversionService
  Inherits DefaultDocumentConversionService

  Private _baseService As IDocumentConversionService

  Shared Sub New()
    Dim license As New Aspose.Pdf.License()
      license.SetLicense(File.OpenRead(Application.MapPath("Aspose.Pdf.lic")))
  End Sub

  Public Sub New()
    _baseService = New DefaultDocumentConversionService()
  End Sub
  
  Public Overloads Function Convert( _
                    stream As Stream, _
                    fileType As String, _
                    Optional metadata As Metadata = Nothing) As String()

    If fileType = "pdf" Then
      Return ConvertPdfToText(stream, metadata)
    End If
        
    Return _baseService.Convert(stream, fileType)
  End Function

End Class

In place of invoking the base or MyBase methods, utilize the _baseService instance.

Services Lifetime

You are not required to consistently use the same service once you decide to register your own replacements. Wisej.AI registers the following services with a Transient lifetime:

IOCRService, IHttpClientService, ITextSplitterService, IDocumentConversionService

This means that each time a service is requested, the consumer receives a new instance of the implementation. This approach allows for flexibility and adaptability, enabling you to customize and replace services as needed without being tied to a single instance.

For example, the SmartHub component requests all the services it utilizes at the time of its creation, as do all the adapters. If you wish to use different services for each instance, ensure that you register the new services before the SmartHub or the adapters are instantiated. This allows you to customize the behavior of each component by providing them with the specific services they require, ensuring that they operate with the desired functionality.

The following services are registered with a Shared lifetime, meaning that only a single instance of each service is created and shared across the entire application:

ILoggerService, ITokenizerService, IEmbeddingStorageService, IEmbeddingGenerationService, ISessionTrimmingService.

When registering your own services, you have the flexibility to change the lifetime of any service.

PreviousWebSearchToolsNextIOCRService

Last updated 9 days ago

IOCRService
ILoggerService
ITextSplitterService
ITokenizerService
IHttpClientService
IWebSearchService
ISessionTrimmingService
IRerankingService
IDocumentConversionService
IEmbeddingStorageService
IEmbeddingGenerationService