1- import { Mistral } from ' @mistralai/mistralai' ;
2- import fs from 'fs' ;
3- import path from ' path' ;
1+ import { Mistral } from " @mistralai/mistralai" ;
2+ import fs from "fs" ;
3+ import path from " path" ;
44import { fileURLToPath } from "url" ;
55
66const apiKey = process . env . MISTRAL_API_KEY ;
77
88const client = new Mistral ( { apiKey : apiKey } ) ;
99
10-
1110// Get the absolute directory path
1211const __filename = fileURLToPath ( import . meta. url ) ;
1312const __dirname = path . dirname ( __filename ) ;
14- const filePath = path . join ( __dirname , "ocr.pdf" )
13+ const filePath = path . join ( __dirname , "ocr.pdf" ) ;
1514
1615// Upload the file and run ocr
1716const uploaded_file = fs . readFileSync ( filePath ) ;
1817const uploaded_pdf = await client . files . upload ( {
19- file : {
20- fileName : "uploaded_file.pdf" ,
21- content : uploaded_file ,
22- } ,
23- purpose : "ocr"
18+ file : {
19+ fileName : "uploaded_file.pdf" ,
20+ content : uploaded_file ,
21+ } ,
22+ purpose : "ocr" ,
2423} ) ;
2524
2625const ocrResponse = await client . ocr . process ( {
27- model : "mistral-ocr-latest" ,
28- document : {
29- type : "file" ,
30- fileId : uploaded_pdf . id
31- } ,
32- includeImageBase64 : true
26+ model : "mistral-ocr-latest" ,
27+ document : {
28+ type : "file" ,
29+ fileId : uploaded_pdf . id ,
30+ } ,
31+ includeImageBase64 : true ,
3332} ) ;
34- console . log ( "OCR " , ocrResponse ) ;
33+ console . log ( "OCR " , ocrResponse ) ;
0 commit comments