1
This commit is contained in:
+11
-18
@@ -1306,28 +1306,19 @@
|
||||
|
||||
async function mistralOCR(dataUrl) {
|
||||
try {
|
||||
const res = await fetch('https://api.mistral.ai/v1/chat/completions', {
|
||||
const res = await fetch('https://api.mistral.ai/v1/ocr', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${MISTRAL_API_KEY}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: 'pixtral-12b-2409',
|
||||
messages: [{
|
||||
role: 'user',
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'Extract all text from this image and format it as Markdown. If there are tables, represent them using Markdown table syntax. Do not include any commentary or introductions, just the document content.'
|
||||
},
|
||||
{
|
||||
type: 'image_url',
|
||||
image_url: dataUrl // dataUrl ya incluye 'data:image/jpeg;base64,...'
|
||||
}
|
||||
]
|
||||
}],
|
||||
max_tokens: 2000
|
||||
model: 'mistral-ocr-latest',
|
||||
document: {
|
||||
type: 'image_url',
|
||||
image_url: dataUrl // dataUrl ya incluye 'data:image/jpeg;base64,...'
|
||||
},
|
||||
include_image_base64: false
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1342,9 +1333,11 @@
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
if (!data.choices || !data.choices[0]) throw new Error("Respuesta de API vacía");
|
||||
const pages = data.pages || [];
|
||||
const markdown = pages.map(page => page.markdown || '').filter(Boolean).join('\n\n');
|
||||
if (!markdown && !data.markdown) throw new Error("Respuesta de API vacía");
|
||||
|
||||
return data.choices[0].message.content;
|
||||
return markdown || data.markdown;
|
||||
} catch (error) {
|
||||
console.error("Mistral API Error:", error);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user