@layer-ai/core 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mistral-adapter.d.ts","sourceRoot":"","sources":["../../../src/services/providers/mistral-adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EACL,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,YAAY,EAEb,MAAM,eAAe,CAAC;AAavB,qBAAa,cAAe,SAAQ,mBAAmB;IACrD,SAAS,CAAC,QAAQ,SAAa;IAE/B,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAQ1C;IAGF,SAAS,CAAC,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAM1D;IAEF,SAAS,CAAC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIlD;IAEI,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;YAmB3C,UAAU;YA8LV,gBAAgB;
|
|
1
|
+
{"version":3,"file":"mistral-adapter.d.ts","sourceRoot":"","sources":["../../../src/services/providers/mistral-adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EACL,YAAY,EACZ,aAAa,EACb,IAAI,EACJ,YAAY,EAEb,MAAM,eAAe,CAAC;AAavB,qBAAa,cAAe,SAAQ,mBAAmB;IACrD,SAAS,CAAC,QAAQ,SAAa;IAE/B,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAQ1C;IAGF,SAAS,CAAC,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAM1D;IAEF,SAAS,CAAC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIlD;IAEI,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;YAmB3C,UAAU;YA8LV,gBAAgB;YAuChB,SAAS;CA2ExB"}
|
|
@@ -36,73 +36,6 @@ export class MistralAdapter extends BaseProviderAdapter {
|
|
|
36
36
|
none: 'none',
|
|
37
37
|
required: 'any',
|
|
38
38
|
};
|
|
39
|
-
// private async handleOCR(
|
|
40
|
-
// request: Extract<LayerRequest, { type: 'ocr' }>
|
|
41
|
-
// ): Promise<LayerResponse> {
|
|
42
|
-
// const startTime = Date.now();
|
|
43
|
-
// const mistral = getMistralClient();
|
|
44
|
-
// const { data: ocr, model } = request;
|
|
45
|
-
// const ocrModel = model || 'mistral-ocr-latest';
|
|
46
|
-
// let document: { type: string; documentUrl?: string; imageUrl?: string };
|
|
47
|
-
// if (ocr.documentUrl) {
|
|
48
|
-
// document = {
|
|
49
|
-
// type: 'document_url',
|
|
50
|
-
// documentUrl: ocr.documentUrl,
|
|
51
|
-
// };
|
|
52
|
-
// } else if (ocr.imageUrl) {
|
|
53
|
-
// document = {
|
|
54
|
-
// type: 'image_url',
|
|
55
|
-
// imageUrl: ocr.imageUrl,
|
|
56
|
-
// };
|
|
57
|
-
// } else if (ocr.base64) {
|
|
58
|
-
// const mimeType = ocr.mimeType || 'application/pdf';
|
|
59
|
-
// const isImage = mimeType.startsWith('image/');
|
|
60
|
-
// if (isImage) {
|
|
61
|
-
// document = {
|
|
62
|
-
// type: 'image_url',
|
|
63
|
-
// imageUrl: `data:${mimeType};base64,${ocr.base64}`,
|
|
64
|
-
// };
|
|
65
|
-
// } else {
|
|
66
|
-
// document = {
|
|
67
|
-
// type: 'document_url',
|
|
68
|
-
// documentUrl: `data:${mimeType};base64,${ocr.base64}`,
|
|
69
|
-
// };
|
|
70
|
-
// }
|
|
71
|
-
// } else {
|
|
72
|
-
// throw new Error('OCR requires either documentUrl, imageUrl, or base64 input');
|
|
73
|
-
// }
|
|
74
|
-
// const response = await (mistral as any).ocr.process({
|
|
75
|
-
// model: ocrModel,
|
|
76
|
-
// document,
|
|
77
|
-
// ...(ocr.tableFormat && { tableFormat: ocr.tableFormat }),
|
|
78
|
-
// ...(ocr.includeImageBase64 !== undefined && { includeImageBase64: ocr.includeImageBase64 }),
|
|
79
|
-
// ...(ocr.extractHeader !== undefined && { extractHeader: ocr.extractHeader }),
|
|
80
|
-
// ...(ocr.extractFooter !== undefined && { extractFooter: ocr.extractFooter }),
|
|
81
|
-
// });
|
|
82
|
-
// const pages = response.pages?.map((page: any) => ({
|
|
83
|
-
// index: page.index,
|
|
84
|
-
// markdown: page.markdown,
|
|
85
|
-
// images: page.images,
|
|
86
|
-
// tables: page.tables,
|
|
87
|
-
// hyperlinks: page.hyperlinks,
|
|
88
|
-
// header: page.header,
|
|
89
|
-
// footer: page.footer,
|
|
90
|
-
// dimensions: page.dimensions,
|
|
91
|
-
// })) || [];
|
|
92
|
-
// const combinedMarkdown = pages.map((p: any) => p.markdown).join('\n\n---\n\n');
|
|
93
|
-
// return {
|
|
94
|
-
// content: combinedMarkdown,
|
|
95
|
-
// ocr: {
|
|
96
|
-
// pages,
|
|
97
|
-
// model: response.model || ocrModel,
|
|
98
|
-
// documentAnnotation: response.documentAnnotation,
|
|
99
|
-
// usageInfo: response.usageInfo,
|
|
100
|
-
// },
|
|
101
|
-
// model: response.model || ocrModel,
|
|
102
|
-
// latencyMs: Date.now() - startTime,
|
|
103
|
-
// raw: response,
|
|
104
|
-
// };
|
|
105
|
-
// }
|
|
106
39
|
}
|
|
107
40
|
async call(request) {
|
|
108
41
|
switch (request.type) {
|
|
@@ -110,8 +43,8 @@ export class MistralAdapter extends BaseProviderAdapter {
|
|
|
110
43
|
return this.handleChat(request);
|
|
111
44
|
case 'embeddings':
|
|
112
45
|
return this.handleEmbeddings(request);
|
|
113
|
-
|
|
114
|
-
|
|
46
|
+
case 'ocr':
|
|
47
|
+
return this.handleOCR(request);
|
|
115
48
|
case 'image':
|
|
116
49
|
throw new Error('Image generation not supported by Mistral');
|
|
117
50
|
case 'tts':
|
|
@@ -305,4 +238,73 @@ export class MistralAdapter extends BaseProviderAdapter {
|
|
|
305
238
|
raw: response,
|
|
306
239
|
};
|
|
307
240
|
}
|
|
241
|
+
async handleOCR(request) {
|
|
242
|
+
const startTime = Date.now();
|
|
243
|
+
const mistral = getMistralClient();
|
|
244
|
+
const { data: ocr, model } = request;
|
|
245
|
+
const ocrModel = model || 'mistral-ocr-latest';
|
|
246
|
+
let document;
|
|
247
|
+
if (ocr.documentUrl) {
|
|
248
|
+
document = {
|
|
249
|
+
type: 'document_url',
|
|
250
|
+
documentUrl: ocr.documentUrl,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
else if (ocr.imageUrl) {
|
|
254
|
+
document = {
|
|
255
|
+
type: 'image_url',
|
|
256
|
+
imageUrl: ocr.imageUrl,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
else if (ocr.base64) {
|
|
260
|
+
const mimeType = ocr.mimeType || 'application/pdf';
|
|
261
|
+
const isImage = mimeType.startsWith('image/');
|
|
262
|
+
if (isImage) {
|
|
263
|
+
document = {
|
|
264
|
+
type: 'image_url',
|
|
265
|
+
imageUrl: `data:${mimeType};base64,${ocr.base64}`,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
document = {
|
|
270
|
+
type: 'document_url',
|
|
271
|
+
documentUrl: `data:${mimeType};base64,${ocr.base64}`,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
throw new Error('OCR requires either documentUrl, imageUrl, or base64 input');
|
|
277
|
+
}
|
|
278
|
+
const response = await mistral.ocr.process({
|
|
279
|
+
model: ocrModel,
|
|
280
|
+
document,
|
|
281
|
+
...(ocr.tableFormat && { tableFormat: ocr.tableFormat }),
|
|
282
|
+
...(ocr.includeImageBase64 !== undefined && { includeImageBase64: ocr.includeImageBase64 }),
|
|
283
|
+
...(ocr.extractHeader !== undefined && { extractHeader: ocr.extractHeader }),
|
|
284
|
+
...(ocr.extractFooter !== undefined && { extractFooter: ocr.extractFooter }),
|
|
285
|
+
});
|
|
286
|
+
const pages = response.pages?.map((page) => ({
|
|
287
|
+
index: page.index,
|
|
288
|
+
markdown: page.markdown,
|
|
289
|
+
images: page.images,
|
|
290
|
+
tables: page.tables,
|
|
291
|
+
hyperlinks: page.hyperlinks,
|
|
292
|
+
header: page.header,
|
|
293
|
+
footer: page.footer,
|
|
294
|
+
dimensions: page.dimensions,
|
|
295
|
+
})) || [];
|
|
296
|
+
const combinedMarkdown = pages.map((p) => p.markdown).join('\n\n---\n\n');
|
|
297
|
+
return {
|
|
298
|
+
content: combinedMarkdown,
|
|
299
|
+
ocr: {
|
|
300
|
+
pages,
|
|
301
|
+
model: response.model || ocrModel,
|
|
302
|
+
documentAnnotation: response.documentAnnotation,
|
|
303
|
+
usageInfo: response.usageInfo,
|
|
304
|
+
},
|
|
305
|
+
model: response.model || ocrModel,
|
|
306
|
+
latencyMs: Date.now() - startTime,
|
|
307
|
+
raw: response,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
308
310
|
}
|
|
@@ -270,27 +270,28 @@ async function testMultiTurn() {
|
|
|
270
270
|
console.log('Response:', response.content);
|
|
271
271
|
console.log();
|
|
272
272
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
273
|
+
async function testOCR() {
|
|
274
|
+
console.log('--- Testing OCR Capability ---');
|
|
275
|
+
const request = {
|
|
276
|
+
gate: 'test-gate',
|
|
277
|
+
type: 'ocr',
|
|
278
|
+
model: 'mistral-ocr-latest',
|
|
279
|
+
data: {
|
|
280
|
+
documentUrl: 'https://arxiv.org/pdf/2201.04234',
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
try {
|
|
284
|
+
const response = await adapter.call(request);
|
|
285
|
+
console.log('OCR Response (first 500 chars):', response.content?.substring(0, 500));
|
|
286
|
+
console.log('Model:', response.model);
|
|
287
|
+
console.log('Pages extracted:', response.ocr?.pages?.length || 0);
|
|
288
|
+
console.log('Latency:', response.latencyMs, 'ms');
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
console.log('Test failed:', error.message);
|
|
292
|
+
}
|
|
293
|
+
console.log();
|
|
294
|
+
}
|
|
294
295
|
async function testUnsupportedModality() {
|
|
295
296
|
console.log('--- Testing Unsupported Modality (Image Generation) ---');
|
|
296
297
|
const request = {
|
|
@@ -319,7 +320,7 @@ async function runAllTests() {
|
|
|
319
320
|
await testToolResponse();
|
|
320
321
|
await testEmbeddings();
|
|
321
322
|
await testVisionCapability();
|
|
322
|
-
|
|
323
|
+
await testOCR();
|
|
323
324
|
await testResponseFormat();
|
|
324
325
|
await testMultiTurn();
|
|
325
326
|
await testUnsupportedModality();
|