AsposeAI class

The AsposeAI class provides the bridge between LLM models and the OCR engine.

🛠 Constructors

public AsposeAI();
public AsposeAI(ILogger logger);

You can also pass optional logging and customization callbacks.

Configuration

⚙️ AsposeAIModelConfig

Property Type Description
AllowAutoDownload string If true, the model will be automatically downloaded if not available locally.
DirectoryModelPath string Optional path where downloaded or processed models will be cached. If not set, a default system location will be used.
FileModelPath string Local path to the folder containing the model files. If specified, this will be used instead of downloading. Default empty.
HuggingFaceQuantization string Optional quantization type to use when downloading from HuggingFace. Examples: “int8”, “fp16”, “none”. Default q4_k_m.
HuggingFaceRepoId string ID of the model on HuggingFace (e.g., “openai/gpt2”). If specified, the model will be downloaded from HuggingFace. Default bartowski/Qwen2.5-3B-Instruct-GGUF.
ContextSize int Defines the maximum number of tokens the LLM can use as context during inference. If null, the default context size defined by the model will be used. Larger values allow the model to consider more text but may require more memory.
GpuLayers int Number of GPU layers to use for the model. If not specified, the default value (40) will be used. Set to 0 to run entirely on the CPU.

🧠 AsposeAI Class – Core Methods

Method Description
SetPostProcessor(IOcrAIPostProcessor processor, AsposeAIModelConfig config) Adds a custom AI postprocessor to enhance OCR results.
RunPostprocessor(List<string> texts) Enhances plain recognized text strings using registered AI modules.
RunPostprocessor(OcrOutput output) Enhances structured OCR output using registered AI modules.
Dispose() Cleans up and releases resources used by the AI component.
FreeResources() Explicitly unloads AI models and clears memory.
ListLocal() Lists all local AI models available in the configured folder.
GetLocalPath() Returns the directory path of the current model location.
IsInitialized() Checks if the AI engine and model are ready to use.