@layer-ai/core 0.5.1 → 0.5.3
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.
- package/dist/lib/db/postgres.d.ts.map +1 -1
- package/dist/lib/db/postgres.js +6 -3
- package/dist/routes/gates.d.ts.map +1 -1
- package/dist/routes/gates.js +21 -3
- package/dist/services/providers/mistral-adapter.d.ts +1 -0
- package/dist/services/providers/mistral-adapter.d.ts.map +1 -1
- package/dist/services/providers/mistral-adapter.js +71 -69
- package/dist/services/providers/tests/test-mistral-adapter.js +23 -22
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../../src/lib/db/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAyB,MAAM,eAAe,CAAC;AAO/E,iBAAS,OAAO,IAAI,EAAE,CAAC,IAAI,CAqB1B;AA0BD,eAAO,MAAM,EAAE;gBAEK,MAAM,WAAW,GAAG,EAAE;0BASZ,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;oBAQnC,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;sBAQ3B,MAAM,gBAAgB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;6BASrC,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;yBAQnC,MAAM,WAAW,MAAM,aAAa,MAAM,QAAQ,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;kCAQjE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;8BAO1B,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;qBAQnC,MAAM,UAAU,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;iCAS7B,MAAM,YAAY,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;4BAQpD,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;uBAQ7B,MAAM,QAAQ,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../../src/lib/db/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAyB,MAAM,eAAe,CAAC;AAO/E,iBAAS,OAAO,IAAI,EAAE,CAAC,IAAI,CAqB1B;AA0BD,eAAO,MAAM,EAAE;gBAEK,MAAM,WAAW,GAAG,EAAE;0BASZ,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;oBAQnC,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;sBAQ3B,MAAM,gBAAgB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;6BASrC,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;yBAQnC,MAAM,WAAW,MAAM,aAAa,MAAM,QAAQ,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;kCAQjE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;8BAO1B,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;qBAQnC,MAAM,UAAU,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;iCAS7B,MAAM,YAAY,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;4BAQpD,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;uBAQ7B,MAAM,QAAQ,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;oBA4BpC,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;mBAQ9B,MAAM,QAAQ,GAAG,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;mBA4CxC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;qBASvB,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;iCAgBP,MAAM,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC;6BAQhE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;qCAehB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAM9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
package/dist/lib/db/postgres.js
CHANGED
|
@@ -94,8 +94,8 @@ export const db = {
|
|
|
94
94
|
return result.rows.map(toCamelCase);
|
|
95
95
|
},
|
|
96
96
|
async createGate(userId, data) {
|
|
97
|
-
const result = await getPool().query(`INSERT INTO gates (user_id, name, description, task_type, model, system_prompt, allow_overrides, temperature, max_tokens, top_p, tags, routing_strategy, fallback_models, cost_weight, latency_weight, quality_weight, reanalysis_period)
|
|
98
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING *`, [
|
|
97
|
+
const result = await getPool().query(`INSERT INTO gates (user_id, name, description, task_type, model, system_prompt, allow_overrides, temperature, max_tokens, top_p, tags, routing_strategy, fallback_models, cost_weight, latency_weight, quality_weight, reanalysis_period, task_analysis)
|
|
98
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18) RETURNING *`, [
|
|
99
99
|
userId,
|
|
100
100
|
data.name,
|
|
101
101
|
data.description,
|
|
@@ -112,7 +112,8 @@ export const db = {
|
|
|
112
112
|
data.costWeight ?? 0.33,
|
|
113
113
|
data.latencyWeight ?? 0.33,
|
|
114
114
|
data.qualityWeight ?? 0.34,
|
|
115
|
-
data.reanalysisPeriod || 'never'
|
|
115
|
+
data.reanalysisPeriod || 'never',
|
|
116
|
+
data.taskAnalysis ? JSON.stringify(data.taskAnalysis) : null
|
|
116
117
|
]);
|
|
117
118
|
return toCamelCase(result.rows[0]);
|
|
118
119
|
},
|
|
@@ -137,6 +138,7 @@ export const db = {
|
|
|
137
138
|
latency_weight = COALESCE($14, latency_weight),
|
|
138
139
|
quality_weight = COALESCE($15, quality_weight),
|
|
139
140
|
reanalysis_period = COALESCE($16, reanalysis_period),
|
|
141
|
+
task_analysis = COALESCE($17, task_analysis),
|
|
140
142
|
updated_at = NOW()
|
|
141
143
|
WHERE id = $1 RETURNING *`, [
|
|
142
144
|
id,
|
|
@@ -155,6 +157,7 @@ export const db = {
|
|
|
155
157
|
data.latencyWeight,
|
|
156
158
|
data.qualityWeight,
|
|
157
159
|
data.reanalysisPeriod,
|
|
160
|
+
data.taskAnalysis ? JSON.stringify(data.taskAnalysis) : null,
|
|
158
161
|
]);
|
|
159
162
|
return result.rows[0] ? toCamelCase(result.rows[0]) : null;
|
|
160
163
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gates.d.ts","sourceRoot":"","sources":["../../src/routes/gates.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAOpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"gates.d.ts","sourceRoot":"","sources":["../../src/routes/gates.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAOpD,QAAA,MAAM,MAAM,EAAE,UAAqB,CAAC;AA0TpC,eAAe,MAAM,CAAC"}
|
package/dist/routes/gates.js
CHANGED
|
@@ -13,7 +13,7 @@ router.post('/', async (req, res) => {
|
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
try {
|
|
16
|
-
const { name, description, model, systemPrompt, allowOverrides, temperature, maxTokens, topP, tags, routingStrategy, fallbackModels } = req.body;
|
|
16
|
+
const { name, description, taskType, model, systemPrompt, allowOverrides, temperature, maxTokens, topP, tags, routingStrategy, fallbackModels, costWeight, latencyWeight, qualityWeight, reanalysisPeriod, taskAnalysis } = req.body;
|
|
17
17
|
if (!name || !model) {
|
|
18
18
|
res.status(400).json({ error: 'bad_request', message: 'Missing required fields: name and model' });
|
|
19
19
|
return;
|
|
@@ -30,6 +30,7 @@ router.post('/', async (req, res) => {
|
|
|
30
30
|
const gate = await db.createGate(req.userId, {
|
|
31
31
|
name,
|
|
32
32
|
description,
|
|
33
|
+
taskType,
|
|
33
34
|
model,
|
|
34
35
|
systemPrompt,
|
|
35
36
|
allowOverrides,
|
|
@@ -39,6 +40,11 @@ router.post('/', async (req, res) => {
|
|
|
39
40
|
tags,
|
|
40
41
|
routingStrategy,
|
|
41
42
|
fallbackModels,
|
|
43
|
+
costWeight,
|
|
44
|
+
latencyWeight,
|
|
45
|
+
qualityWeight,
|
|
46
|
+
reanalysisPeriod,
|
|
47
|
+
taskAnalysis,
|
|
42
48
|
});
|
|
43
49
|
res.status(201).json(gate);
|
|
44
50
|
}
|
|
@@ -111,7 +117,7 @@ router.patch('/name/:name', async (req, res) => {
|
|
|
111
117
|
return;
|
|
112
118
|
}
|
|
113
119
|
try {
|
|
114
|
-
const { description, model, systemPrompt, allowOverrides, temperature, maxTokens, topP, tags, routingStrategy, fallbackModels } = req.body;
|
|
120
|
+
const { description, taskType, model, systemPrompt, allowOverrides, temperature, maxTokens, topP, tags, routingStrategy, fallbackModels, costWeight, latencyWeight, qualityWeight, reanalysisPeriod, taskAnalysis } = req.body;
|
|
115
121
|
const existing = await db.getGateByUserAndName(req.userId, req.params.name);
|
|
116
122
|
if (!existing) {
|
|
117
123
|
res.status(404).json({ error: 'not_found', message: 'Gate not found' });
|
|
@@ -123,6 +129,7 @@ router.patch('/name/:name', async (req, res) => {
|
|
|
123
129
|
}
|
|
124
130
|
const updated = await db.updateGate(existing.id, {
|
|
125
131
|
description,
|
|
132
|
+
taskType,
|
|
126
133
|
model,
|
|
127
134
|
systemPrompt,
|
|
128
135
|
allowOverrides,
|
|
@@ -132,6 +139,11 @@ router.patch('/name/:name', async (req, res) => {
|
|
|
132
139
|
tags,
|
|
133
140
|
routingStrategy,
|
|
134
141
|
fallbackModels,
|
|
142
|
+
costWeight,
|
|
143
|
+
latencyWeight,
|
|
144
|
+
qualityWeight,
|
|
145
|
+
reanalysisPeriod,
|
|
146
|
+
taskAnalysis,
|
|
135
147
|
});
|
|
136
148
|
await cache.invalidateGate(req.userId, existing.name);
|
|
137
149
|
res.json(updated);
|
|
@@ -148,7 +160,7 @@ router.patch('/:id', async (req, res) => {
|
|
|
148
160
|
return;
|
|
149
161
|
}
|
|
150
162
|
try {
|
|
151
|
-
const { description, model, systemPrompt, allowOverrides, temperature, maxTokens, topP, tags, routingStrategy, fallbackModels } = req.body;
|
|
163
|
+
const { description, taskType, model, systemPrompt, allowOverrides, temperature, maxTokens, topP, tags, routingStrategy, fallbackModels, costWeight, latencyWeight, qualityWeight, reanalysisPeriod, taskAnalysis } = req.body;
|
|
152
164
|
const existing = await db.getGateById(req.params.id);
|
|
153
165
|
if (!existing) {
|
|
154
166
|
res.status(404).json({ error: 'not_found', message: 'Gate not found' });
|
|
@@ -164,6 +176,7 @@ router.patch('/:id', async (req, res) => {
|
|
|
164
176
|
}
|
|
165
177
|
const updated = await db.updateGate(req.params.id, {
|
|
166
178
|
description,
|
|
179
|
+
taskType,
|
|
167
180
|
model,
|
|
168
181
|
systemPrompt,
|
|
169
182
|
allowOverrides,
|
|
@@ -173,6 +186,11 @@ router.patch('/:id', async (req, res) => {
|
|
|
173
186
|
tags,
|
|
174
187
|
routingStrategy,
|
|
175
188
|
fallbackModels,
|
|
189
|
+
costWeight,
|
|
190
|
+
latencyWeight,
|
|
191
|
+
qualityWeight,
|
|
192
|
+
reanalysisPeriod,
|
|
193
|
+
taskAnalysis,
|
|
176
194
|
});
|
|
177
195
|
await cache.invalidateGate(req.userId, existing.name);
|
|
178
196
|
res.json(updated);
|
|
@@ -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();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layer-ai/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Core API routes and services for Layer AI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"nanoid": "^5.0.4",
|
|
37
37
|
"openai": "^4.24.0",
|
|
38
38
|
"pg": "^8.11.3",
|
|
39
|
-
"@layer-ai/sdk": "^0.5.
|
|
39
|
+
"@layer-ai/sdk": "^0.5.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/bcryptjs": "^2.4.6",
|