feat(ocr): add a Mistral-based OCR adapter for KVM frames
This commit is contained in:
@@ -3,3 +3,4 @@ export * from './smartkvm.classes.browserkvm.js';
|
||||
export * from './smartkvm.classes.kvmterminal.js';
|
||||
export * from './smartkvm.commandwrappers.js';
|
||||
export * from './smartkvm.tools.smartagent.js';
|
||||
export * from './smartkvm.ocr.smartai.js';
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
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,
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user