47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { createMistralOcrEngine } from '@push.rocks/smartai/ocr';
|
|
import type {
|
|
ISmartAiMistralOcrTransport,
|
|
TSmartAiMistralOcrConfidenceScoresGranularity,
|
|
TSmartAiMistralOcrTableFormat,
|
|
} from '@push.rocks/smartai/ocr';
|
|
import type { IOcrEngine, IOcrResult } from './smartkvm.interfaces.js';
|
|
|
|
export interface ISmartKvmMistralOcrEngineOptions {
|
|
apiKey?: string;
|
|
model?: string;
|
|
endpointUrl?: string;
|
|
transport?: ISmartAiMistralOcrTransport;
|
|
includeImageBase64?: boolean;
|
|
tableFormat?: TSmartAiMistralOcrTableFormat;
|
|
extractHeader?: boolean;
|
|
extractFooter?: boolean;
|
|
confidenceScoresGranularity?: TSmartAiMistralOcrConfidenceScoresGranularity;
|
|
}
|
|
|
|
export const createMistralKvmOcrEngine = (
|
|
options: ISmartKvmMistralOcrEngineOptions = {}
|
|
): IOcrEngine => {
|
|
const smartAiOcrEngine = createMistralOcrEngine({
|
|
...options,
|
|
confidenceScoresGranularity: options.confidenceScoresGranularity ?? 'page',
|
|
});
|
|
|
|
return {
|
|
recognize: async (frame, recognizeOptions = {}): Promise<IOcrResult> => {
|
|
if (recognizeOptions.crop) {
|
|
throw new Error('Mistral KVM OCR does not support crop options yet.');
|
|
}
|
|
|
|
const result = await smartAiOcrEngine.recognizeImage({
|
|
dataBase64: frame.dataBase64,
|
|
mimeType: frame.mimeType,
|
|
});
|
|
|
|
return {
|
|
text: result.text,
|
|
confidence: result.confidence,
|
|
};
|
|
},
|
|
};
|
|
};
|