@doclo/providers-llm 0.1.8 → 0.1.9
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/index.d.ts +46 -3
- package/dist/index.js +33 -18
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -134,6 +134,27 @@ interface LLMDerivedOptions {
|
|
|
134
134
|
maxChunkSize?: number;
|
|
135
135
|
/** Language hints for the document */
|
|
136
136
|
languageHints?: string[];
|
|
137
|
+
/**
|
|
138
|
+
* Normalize date fields to ISO 8601 format (YYYY-MM-DD)
|
|
139
|
+
* When enabled, date fields in the extraction output will be formatted consistently.
|
|
140
|
+
* Native support: Extend.ai (extend:type: "date")
|
|
141
|
+
* LLM support: Via prompting
|
|
142
|
+
*/
|
|
143
|
+
dateNormalization?: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Normalize currency fields to { amount: number, currency: string } objects
|
|
146
|
+
* When enabled, monetary values are extracted as structured objects with ISO 4217 currency codes.
|
|
147
|
+
* Native support: Extend.ai (extend:type: "currency")
|
|
148
|
+
* LLM support: Via prompting
|
|
149
|
+
*/
|
|
150
|
+
currencyNormalization?: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Detect and extract signature fields from documents
|
|
153
|
+
* When enabled, signature presence is detected and locations are reported.
|
|
154
|
+
* Native support: Extend.ai (extend:type: "signature"), Reducto
|
|
155
|
+
* LLM support: Via prompting (less reliable)
|
|
156
|
+
*/
|
|
157
|
+
signatureDetection?: boolean;
|
|
137
158
|
}
|
|
138
159
|
/**
|
|
139
160
|
* Extracted metadata from LLM response (populated when derived options are enabled)
|
|
@@ -160,6 +181,25 @@ interface LLMExtractedMetadata {
|
|
|
160
181
|
text: string;
|
|
161
182
|
pages: number[];
|
|
162
183
|
}>;
|
|
184
|
+
/** Detected signatures with location and confidence */
|
|
185
|
+
signatures?: Array<{
|
|
186
|
+
field: string;
|
|
187
|
+
detected: boolean;
|
|
188
|
+
bbox?: [number, number, number, number];
|
|
189
|
+
page?: number;
|
|
190
|
+
confidence?: number;
|
|
191
|
+
}>;
|
|
192
|
+
/** Normalized currency values (original → normalized mapping) */
|
|
193
|
+
normalizedCurrencies?: Record<string, {
|
|
194
|
+
original: string;
|
|
195
|
+
amount: number;
|
|
196
|
+
currency: string;
|
|
197
|
+
}>;
|
|
198
|
+
/** Normalized date values (original → normalized mapping) */
|
|
199
|
+
normalizedDates?: Record<string, {
|
|
200
|
+
original: string;
|
|
201
|
+
normalized: string;
|
|
202
|
+
}>;
|
|
163
203
|
}
|
|
164
204
|
/** Provider interface */
|
|
165
205
|
interface LLMProvider {
|
|
@@ -457,7 +497,8 @@ declare class OpenAIProvider implements LLMProvider {
|
|
|
457
497
|
private limits;
|
|
458
498
|
constructor(config: ProviderConfig);
|
|
459
499
|
completeJson<T>(params: {
|
|
460
|
-
input
|
|
500
|
+
input?: MultimodalInput;
|
|
501
|
+
prompt?: MultimodalInput | string;
|
|
461
502
|
schema?: UnifiedSchema<T>;
|
|
462
503
|
mode?: JsonMode;
|
|
463
504
|
max_tokens?: number;
|
|
@@ -482,7 +523,8 @@ declare class AnthropicProvider implements LLMProvider {
|
|
|
482
523
|
private limits;
|
|
483
524
|
constructor(config: ProviderConfig);
|
|
484
525
|
completeJson<T>(params: {
|
|
485
|
-
input
|
|
526
|
+
input?: MultimodalInput;
|
|
527
|
+
prompt?: MultimodalInput | string;
|
|
486
528
|
schema?: UnifiedSchema<T>;
|
|
487
529
|
mode?: JsonMode;
|
|
488
530
|
max_tokens?: number;
|
|
@@ -550,7 +592,8 @@ declare class XAIProvider implements LLMProvider {
|
|
|
550
592
|
private limits;
|
|
551
593
|
constructor(config: ProviderConfig);
|
|
552
594
|
completeJson<T>(params: {
|
|
553
|
-
input
|
|
595
|
+
input?: MultimodalInput;
|
|
596
|
+
prompt?: MultimodalInput | string;
|
|
554
597
|
schema?: UnifiedSchema<T>;
|
|
555
598
|
mode?: JsonMode;
|
|
556
599
|
max_tokens?: number;
|
package/dist/index.js
CHANGED
|
@@ -343,25 +343,30 @@ var OpenAIProvider = class {
|
|
|
343
343
|
}
|
|
344
344
|
async completeJson(params) {
|
|
345
345
|
const startTime = Date.now();
|
|
346
|
+
const rawInput = params.input ?? params.prompt;
|
|
347
|
+
if (!rawInput) {
|
|
348
|
+
throw new Error("Either input or prompt must be provided");
|
|
349
|
+
}
|
|
350
|
+
const normalizedInput = typeof rawInput === "string" ? { text: rawInput } : rawInput;
|
|
346
351
|
const mode = params.mode || (params.schema ? "strict" : "relaxed");
|
|
347
352
|
if (mode === "strict" && !params.schema) {
|
|
348
353
|
throw new Error('schema is required when mode is "strict"');
|
|
349
354
|
}
|
|
350
355
|
const extractMetadata = shouldExtractMetadata(params.derivedOptions);
|
|
351
356
|
const shouldEmbedSchema = params.embedSchemaInPrompt !== false && params.schema;
|
|
352
|
-
let enhancedInput =
|
|
357
|
+
let enhancedInput = normalizedInput;
|
|
353
358
|
if (shouldEmbedSchema) {
|
|
354
359
|
const jsonSchema = this.translator.convertZodIfNeeded(params.schema);
|
|
355
360
|
const enhancedText = params.derivedOptions ? combineSchemaUserAndDerivedPrompts(
|
|
356
361
|
jsonSchema,
|
|
357
|
-
|
|
362
|
+
normalizedInput.text || "",
|
|
358
363
|
params.derivedOptions
|
|
359
364
|
) : combineSchemaAndUserPrompt(
|
|
360
365
|
jsonSchema,
|
|
361
|
-
|
|
366
|
+
normalizedInput.text || ""
|
|
362
367
|
);
|
|
363
368
|
enhancedInput = {
|
|
364
|
-
...
|
|
369
|
+
...normalizedInput,
|
|
365
370
|
text: enhancedText
|
|
366
371
|
};
|
|
367
372
|
} else if (params.derivedOptions) {
|
|
@@ -369,8 +374,8 @@ var OpenAIProvider = class {
|
|
|
369
374
|
const derivedPrompt = buildLLMDerivedFeaturesPrompt2(params.derivedOptions);
|
|
370
375
|
if (derivedPrompt) {
|
|
371
376
|
enhancedInput = {
|
|
372
|
-
...
|
|
373
|
-
text: (
|
|
377
|
+
...normalizedInput,
|
|
378
|
+
text: (normalizedInput.text || "") + "\n\n" + derivedPrompt
|
|
374
379
|
};
|
|
375
380
|
}
|
|
376
381
|
}
|
|
@@ -596,25 +601,30 @@ var AnthropicProvider = class {
|
|
|
596
601
|
}
|
|
597
602
|
async completeJson(params) {
|
|
598
603
|
const startTime = Date.now();
|
|
604
|
+
const rawInput = params.input ?? params.prompt;
|
|
605
|
+
if (!rawInput) {
|
|
606
|
+
throw new Error("Either input or prompt must be provided");
|
|
607
|
+
}
|
|
608
|
+
const normalizedInput = typeof rawInput === "string" ? { text: rawInput } : rawInput;
|
|
599
609
|
const mode = params.mode || (params.schema ? "strict" : "relaxed");
|
|
600
610
|
if (mode === "strict" && !params.schema) {
|
|
601
611
|
throw new Error('schema is required when mode is "strict"');
|
|
602
612
|
}
|
|
603
613
|
const extractMetadata = shouldExtractMetadata(params.derivedOptions);
|
|
604
614
|
const shouldEmbedSchema = params.embedSchemaInPrompt !== false && params.schema;
|
|
605
|
-
let enhancedInput =
|
|
615
|
+
let enhancedInput = normalizedInput;
|
|
606
616
|
if (shouldEmbedSchema) {
|
|
607
617
|
const jsonSchema = this.translator.convertZodIfNeeded(params.schema);
|
|
608
618
|
const enhancedText = params.derivedOptions ? combineSchemaUserAndDerivedPrompts(
|
|
609
619
|
jsonSchema,
|
|
610
|
-
|
|
620
|
+
normalizedInput.text || "",
|
|
611
621
|
params.derivedOptions
|
|
612
622
|
) : combineSchemaAndUserPrompt(
|
|
613
623
|
jsonSchema,
|
|
614
|
-
|
|
624
|
+
normalizedInput.text || ""
|
|
615
625
|
);
|
|
616
626
|
enhancedInput = {
|
|
617
|
-
...
|
|
627
|
+
...normalizedInput,
|
|
618
628
|
text: enhancedText
|
|
619
629
|
};
|
|
620
630
|
} else if (params.derivedOptions) {
|
|
@@ -622,8 +632,8 @@ var AnthropicProvider = class {
|
|
|
622
632
|
const derivedPrompt = buildLLMDerivedFeaturesPrompt2(params.derivedOptions);
|
|
623
633
|
if (derivedPrompt) {
|
|
624
634
|
enhancedInput = {
|
|
625
|
-
...
|
|
626
|
-
text: (
|
|
635
|
+
...normalizedInput,
|
|
636
|
+
text: (normalizedInput.text || "") + "\n\n" + derivedPrompt
|
|
627
637
|
};
|
|
628
638
|
}
|
|
629
639
|
}
|
|
@@ -1596,25 +1606,30 @@ var XAIProvider = class {
|
|
|
1596
1606
|
}
|
|
1597
1607
|
async completeJson(params) {
|
|
1598
1608
|
const startTime = Date.now();
|
|
1609
|
+
const rawInput = params.input ?? params.prompt;
|
|
1610
|
+
if (!rawInput) {
|
|
1611
|
+
throw new Error("Either input or prompt must be provided");
|
|
1612
|
+
}
|
|
1613
|
+
const normalizedInput = typeof rawInput === "string" ? { text: rawInput } : rawInput;
|
|
1599
1614
|
const mode = params.mode || (params.schema ? "strict" : "relaxed");
|
|
1600
1615
|
if (mode === "strict" && !params.schema) {
|
|
1601
1616
|
throw new Error('schema is required when mode is "strict"');
|
|
1602
1617
|
}
|
|
1603
1618
|
const extractMetadata = shouldExtractMetadata(params.derivedOptions);
|
|
1604
1619
|
const shouldEmbedSchema = params.embedSchemaInPrompt !== false && params.schema;
|
|
1605
|
-
let enhancedInput =
|
|
1620
|
+
let enhancedInput = normalizedInput;
|
|
1606
1621
|
if (shouldEmbedSchema) {
|
|
1607
1622
|
const jsonSchema = this.translator.convertZodIfNeeded(params.schema);
|
|
1608
1623
|
const enhancedText = params.derivedOptions ? combineSchemaUserAndDerivedPrompts(
|
|
1609
1624
|
jsonSchema,
|
|
1610
|
-
|
|
1625
|
+
normalizedInput.text || "",
|
|
1611
1626
|
params.derivedOptions
|
|
1612
1627
|
) : combineSchemaAndUserPrompt(
|
|
1613
1628
|
jsonSchema,
|
|
1614
|
-
|
|
1629
|
+
normalizedInput.text || ""
|
|
1615
1630
|
);
|
|
1616
1631
|
enhancedInput = {
|
|
1617
|
-
...
|
|
1632
|
+
...normalizedInput,
|
|
1618
1633
|
text: enhancedText
|
|
1619
1634
|
};
|
|
1620
1635
|
} else if (params.derivedOptions) {
|
|
@@ -1622,8 +1637,8 @@ var XAIProvider = class {
|
|
|
1622
1637
|
const derivedPrompt = buildLLMDerivedFeaturesPrompt2(params.derivedOptions);
|
|
1623
1638
|
if (derivedPrompt) {
|
|
1624
1639
|
enhancedInput = {
|
|
1625
|
-
...
|
|
1626
|
-
text: (
|
|
1640
|
+
...normalizedInput,
|
|
1641
|
+
text: (normalizedInput.text || "") + "\n\n" + derivedPrompt
|
|
1627
1642
|
};
|
|
1628
1643
|
}
|
|
1629
1644
|
}
|