@solvers-hub/llm-json 0.1.9 → 0.1.10
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/README.md +255 -2
- package/docs/assets/highlight.css +42 -0
- package/docs/classes/LlmJson.html +5 -5
- package/docs/index.html +46 -4
- package/docs/interfaces/ExtractOptions.html +3 -3
- package/docs/interfaces/ExtractResult.html +4 -4
- package/docs/interfaces/JsonBlock.html +6 -6
- package/docs/interfaces/JsonParseError.html +4 -4
- package/docs/interfaces/SchemaDefinition.html +3 -3
- package/docs/interfaces/ValidationResult.html +5 -5
- package/docs-md/COMPREHENSIVE_GUIDE.md +669 -0
- package/examples/advanced-patterns-example.ts +533 -0
- package/examples/zod-integration-example.ts +431 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -102,14 +102,267 @@ console.log(result.validatedJson);
|
|
|
102
102
|
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
+
## Advanced Usage
|
|
106
|
+
|
|
107
|
+
### Using with Zod Schemas
|
|
108
|
+
|
|
109
|
+
While llm-json uses JSON Schema internally, you can easily integrate with Zod using the `zod-to-json-schema` library:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npm install zod zod-to-json-schema
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { LlmJson } from '@solvers-hub/llm-json';
|
|
117
|
+
import { z } from 'zod';
|
|
118
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
119
|
+
|
|
120
|
+
// Define your Zod schema
|
|
121
|
+
const productSchema = z.object({
|
|
122
|
+
productId: z.string(),
|
|
123
|
+
quantity: z.number().min(0)
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Convert to JSON Schema
|
|
127
|
+
const llmJson = new LlmJson({
|
|
128
|
+
attemptCorrection: true,
|
|
129
|
+
schemas: [{
|
|
130
|
+
name: 'product',
|
|
131
|
+
schema: zodToJsonSchema(productSchema)
|
|
132
|
+
}]
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Process LLM output
|
|
136
|
+
const result = llmJson.extract('Found product: {"productId": "abc-123", "quantity": 10}');
|
|
137
|
+
|
|
138
|
+
// Get validated result
|
|
139
|
+
if (result.validatedJson[0]?.isValid) {
|
|
140
|
+
const validatedProduct = productSchema.parse(result.validatedJson[0].json);
|
|
141
|
+
console.log(validatedProduct); // Type-safe!
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Handling Nested Validation Errors
|
|
146
|
+
|
|
147
|
+
When validating complex nested schemas, you can identify specific validation failures:
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
const playlistSchema = {
|
|
151
|
+
name: 'playlist',
|
|
152
|
+
schema: {
|
|
153
|
+
type: 'object',
|
|
154
|
+
properties: {
|
|
155
|
+
playlistId: { type: 'string' },
|
|
156
|
+
tracks: {
|
|
157
|
+
type: 'array',
|
|
158
|
+
items: {
|
|
159
|
+
type: 'object',
|
|
160
|
+
properties: {
|
|
161
|
+
id: { type: 'string' },
|
|
162
|
+
title: { type: 'string' },
|
|
163
|
+
duration: { type: 'number' }
|
|
164
|
+
},
|
|
165
|
+
required: ['id', 'title', 'duration']
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
required: ['playlistId', 'tracks']
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const result = llmJson.extract(llmOutput);
|
|
174
|
+
|
|
175
|
+
if (!result.validatedJson[0]?.isValid) {
|
|
176
|
+
// Identify which array item failed
|
|
177
|
+
result.validatedJson[0].validationErrors?.forEach(error => {
|
|
178
|
+
console.log('Path:', error.instancePath); // e.g., "/tracks/1/duration"
|
|
179
|
+
console.log('Message:', error.message);
|
|
180
|
+
|
|
181
|
+
// Extract the failed item index
|
|
182
|
+
const match = error.instancePath?.match(/\/tracks\/(\d+)/);
|
|
183
|
+
if (match) {
|
|
184
|
+
const failedIndex = parseInt(match[1]);
|
|
185
|
+
console.log('Failed track:', result.json[0].tracks[failedIndex]);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Two-Stage Parsing for Performance
|
|
192
|
+
|
|
193
|
+
For high-throughput pipelines, use a two-stage strategy:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
class OptimizedParser {
|
|
197
|
+
private fastParser = new LlmJson({ attemptCorrection: false }); // Stage 1
|
|
198
|
+
private fallbackParser = new LlmJson({ attemptCorrection: true }); // Stage 2
|
|
199
|
+
|
|
200
|
+
parse(input: string) {
|
|
201
|
+
// Stage 1: Fast path (no correction)
|
|
202
|
+
const result = this.fastParser.extract(input);
|
|
203
|
+
|
|
204
|
+
// Only use Stage 2 if Stage 1 failed AND input contains JSON-like patterns
|
|
205
|
+
if (result.json.length === 0 && this.hasJsonPattern(input)) {
|
|
206
|
+
return this.fallbackParser.extract(input); // Stage 2: Fallback with correction
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private hasJsonPattern(input: string): boolean {
|
|
213
|
+
return /\{[^}]*:/.test(input) || /\[[^\]]*\{/.test(input);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**Trigger conditions for Stage 2:**
|
|
219
|
+
- Stage 1 returns empty `json` array
|
|
220
|
+
- Input contains JSON-like patterns (`{`, `[`, `:`, etc.)
|
|
221
|
+
- Distinguishes between "no JSON" vs "malformed JSON"
|
|
222
|
+
|
|
223
|
+
### Streaming/Chunked Input Handling
|
|
224
|
+
|
|
225
|
+
For real-time LLM streaming, buffer chunks until complete JSON is detected:
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
class StreamingHandler {
|
|
229
|
+
private buffer = '';
|
|
230
|
+
private llmJson = new LlmJson({ attemptCorrection: true });
|
|
231
|
+
|
|
232
|
+
processChunk(chunk: string) {
|
|
233
|
+
this.buffer += chunk;
|
|
234
|
+
|
|
235
|
+
// Detect complete JSON by counting braces
|
|
236
|
+
const complete = this.findCompleteJson(this.buffer);
|
|
237
|
+
|
|
238
|
+
if (complete) {
|
|
239
|
+
const result = this.llmJson.extract(complete.json);
|
|
240
|
+
this.buffer = complete.remaining;
|
|
241
|
+
return result.json;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return []; // Still buffering
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private findCompleteJson(text: string): { json: string; remaining: string } | null {
|
|
248
|
+
let depth = 0;
|
|
249
|
+
let start = text.indexOf('{');
|
|
250
|
+
if (start === -1) return null;
|
|
251
|
+
|
|
252
|
+
for (let i = start; i < text.length; i++) {
|
|
253
|
+
if (text[i] === '{') depth++;
|
|
254
|
+
if (text[i] === '}') depth--;
|
|
255
|
+
if (depth === 0) {
|
|
256
|
+
return {
|
|
257
|
+
json: text.substring(start, i + 1),
|
|
258
|
+
remaining: text.substring(i + 1)
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return null; // Incomplete
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
**Primary challenges:**
|
|
268
|
+
1. Detecting JSON boundaries in incomplete streams
|
|
269
|
+
2. Handling braces inside strings (must track string state)
|
|
270
|
+
3. Supporting nested objects (depth counting)
|
|
271
|
+
4. Managing buffer size for long streams
|
|
272
|
+
|
|
273
|
+
### Processing Multiple Schema Types
|
|
274
|
+
|
|
275
|
+
Build a typed processor for different data types:
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
class LogProcessor {
|
|
279
|
+
private llmJson: LlmJson;
|
|
280
|
+
|
|
281
|
+
constructor(schemas: { errorLog: any; infoLog: any }) {
|
|
282
|
+
this.llmJson = new LlmJson({
|
|
283
|
+
attemptCorrection: true,
|
|
284
|
+
schemas: [
|
|
285
|
+
{ name: 'errorLog', schema: schemas.errorLog },
|
|
286
|
+
{ name: 'infoLog', schema: schemas.infoLog }
|
|
287
|
+
]
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
process(logEntry: string): { errors: any[]; infos: any[] } {
|
|
292
|
+
const result = this.llmJson.extract(logEntry);
|
|
293
|
+
|
|
294
|
+
const errors: any[] = [];
|
|
295
|
+
const infos: any[] = [];
|
|
296
|
+
|
|
297
|
+
result.validatedJson?.forEach(validated => {
|
|
298
|
+
if (validated.isValid) {
|
|
299
|
+
if (validated.matchedSchema === 'errorLog') {
|
|
300
|
+
errors.push(validated.json);
|
|
301
|
+
} else if (validated.matchedSchema === 'infoLog') {
|
|
302
|
+
infos.push(validated.json);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
return { errors, infos };
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
105
312
|
## Examples
|
|
106
313
|
|
|
107
|
-
See the [examples](examples) directory for
|
|
314
|
+
See the [examples](examples) directory for comprehensive examples:
|
|
108
315
|
|
|
109
|
-
|
|
316
|
+
- **[example.ts](examples/example.ts)** - Basic extraction and correction
|
|
317
|
+
- **[array-example.ts](examples/array-example.ts)** - Extracting arrays from LLM output
|
|
318
|
+
- **[schema-validation-example.ts](examples/schema-validation-example.ts)** - JSON Schema validation
|
|
319
|
+
- **[schema-validation-examples.ts](examples/schema-validation-examples.ts)** - Complex nested schemas
|
|
320
|
+
- **[zod-integration-example.ts](examples/zod-integration-example.ts)** - Using Zod schemas with llm-json
|
|
321
|
+
- **[advanced-patterns-example.ts](examples/advanced-patterns-example.ts)** - Streaming, two-stage parsing, error detection
|
|
322
|
+
|
|
323
|
+
Run examples:
|
|
110
324
|
|
|
111
325
|
```bash
|
|
112
326
|
npm run example:run -- examples/example.ts
|
|
327
|
+
npm run example:run -- examples/zod-integration-example.ts
|
|
328
|
+
npm run example:run -- examples/advanced-patterns-example.ts
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## API Reference
|
|
332
|
+
|
|
333
|
+
### `ExtractResult`
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
interface ExtractResult {
|
|
337
|
+
text: string[]; // Non-JSON text segments
|
|
338
|
+
json: any[]; // Extracted JSON objects/arrays
|
|
339
|
+
validatedJson?: Array<{ // Validation results (if schemas provided)
|
|
340
|
+
json: any;
|
|
341
|
+
matchedSchema: string | null;
|
|
342
|
+
isValid: boolean;
|
|
343
|
+
validationErrors?: Array<{
|
|
344
|
+
instancePath?: string; // Path to failed property (e.g., "/tracks/1/duration")
|
|
345
|
+
schemaPath?: string; // Path in schema
|
|
346
|
+
message?: string; // Error description
|
|
347
|
+
}>;
|
|
348
|
+
}>;
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Distinguishing Parse Failures from Empty Input
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
function diagnoseResult(input: string, result: ExtractResult): string {
|
|
356
|
+
// Case 1: Success
|
|
357
|
+
if (result.json.length > 0) return 'success';
|
|
358
|
+
|
|
359
|
+
// Case 2: No JSON-like patterns = genuinely empty
|
|
360
|
+
const hasJsonPattern = /\{[^}]*:/.test(input) || /\[[^\]]*\{/.test(input);
|
|
361
|
+
if (!hasJsonPattern) return 'no_json';
|
|
362
|
+
|
|
363
|
+
// Case 3: Has JSON patterns but extraction failed = parse failure
|
|
364
|
+
return 'parse_failure';
|
|
365
|
+
}
|
|
113
366
|
```
|
|
114
367
|
|
|
115
368
|
## License
|
|
@@ -15,6 +15,18 @@
|
|
|
15
15
|
--dark-hl-6: #4FC1FF;
|
|
16
16
|
--light-hl-7: #008000;
|
|
17
17
|
--dark-hl-7: #6A9955;
|
|
18
|
+
--light-hl-8: #098658;
|
|
19
|
+
--dark-hl-8: #B5CEA8;
|
|
20
|
+
--light-hl-9: #811F3F;
|
|
21
|
+
--dark-hl-9: #D16969;
|
|
22
|
+
--light-hl-10: #EE0000;
|
|
23
|
+
--dark-hl-10: #D7BA7D;
|
|
24
|
+
--light-hl-11: #D16969;
|
|
25
|
+
--dark-hl-11: #CE9178;
|
|
26
|
+
--light-hl-12: #000000;
|
|
27
|
+
--dark-hl-12: #D7BA7D;
|
|
28
|
+
--light-hl-13: #267F99;
|
|
29
|
+
--dark-hl-13: #4EC9B0;
|
|
18
30
|
--light-code-background: #FFFFFF;
|
|
19
31
|
--dark-code-background: #1E1E1E;
|
|
20
32
|
}
|
|
@@ -28,6 +40,12 @@
|
|
|
28
40
|
--hl-5: var(--light-hl-5);
|
|
29
41
|
--hl-6: var(--light-hl-6);
|
|
30
42
|
--hl-7: var(--light-hl-7);
|
|
43
|
+
--hl-8: var(--light-hl-8);
|
|
44
|
+
--hl-9: var(--light-hl-9);
|
|
45
|
+
--hl-10: var(--light-hl-10);
|
|
46
|
+
--hl-11: var(--light-hl-11);
|
|
47
|
+
--hl-12: var(--light-hl-12);
|
|
48
|
+
--hl-13: var(--light-hl-13);
|
|
31
49
|
--code-background: var(--light-code-background);
|
|
32
50
|
} }
|
|
33
51
|
|
|
@@ -40,6 +58,12 @@
|
|
|
40
58
|
--hl-5: var(--dark-hl-5);
|
|
41
59
|
--hl-6: var(--dark-hl-6);
|
|
42
60
|
--hl-7: var(--dark-hl-7);
|
|
61
|
+
--hl-8: var(--dark-hl-8);
|
|
62
|
+
--hl-9: var(--dark-hl-9);
|
|
63
|
+
--hl-10: var(--dark-hl-10);
|
|
64
|
+
--hl-11: var(--dark-hl-11);
|
|
65
|
+
--hl-12: var(--dark-hl-12);
|
|
66
|
+
--hl-13: var(--dark-hl-13);
|
|
43
67
|
--code-background: var(--dark-code-background);
|
|
44
68
|
} }
|
|
45
69
|
|
|
@@ -52,6 +76,12 @@
|
|
|
52
76
|
--hl-5: var(--light-hl-5);
|
|
53
77
|
--hl-6: var(--light-hl-6);
|
|
54
78
|
--hl-7: var(--light-hl-7);
|
|
79
|
+
--hl-8: var(--light-hl-8);
|
|
80
|
+
--hl-9: var(--light-hl-9);
|
|
81
|
+
--hl-10: var(--light-hl-10);
|
|
82
|
+
--hl-11: var(--light-hl-11);
|
|
83
|
+
--hl-12: var(--light-hl-12);
|
|
84
|
+
--hl-13: var(--light-hl-13);
|
|
55
85
|
--code-background: var(--light-code-background);
|
|
56
86
|
}
|
|
57
87
|
|
|
@@ -64,6 +94,12 @@
|
|
|
64
94
|
--hl-5: var(--dark-hl-5);
|
|
65
95
|
--hl-6: var(--dark-hl-6);
|
|
66
96
|
--hl-7: var(--dark-hl-7);
|
|
97
|
+
--hl-8: var(--dark-hl-8);
|
|
98
|
+
--hl-9: var(--dark-hl-9);
|
|
99
|
+
--hl-10: var(--dark-hl-10);
|
|
100
|
+
--hl-11: var(--dark-hl-11);
|
|
101
|
+
--hl-12: var(--dark-hl-12);
|
|
102
|
+
--hl-13: var(--dark-hl-13);
|
|
67
103
|
--code-background: var(--dark-code-background);
|
|
68
104
|
}
|
|
69
105
|
|
|
@@ -75,4 +111,10 @@
|
|
|
75
111
|
.hl-5 { color: var(--hl-5); }
|
|
76
112
|
.hl-6 { color: var(--hl-6); }
|
|
77
113
|
.hl-7 { color: var(--hl-7); }
|
|
114
|
+
.hl-8 { color: var(--hl-8); }
|
|
115
|
+
.hl-9 { color: var(--hl-9); }
|
|
116
|
+
.hl-10 { color: var(--hl-10); }
|
|
117
|
+
.hl-11 { color: var(--hl-11); }
|
|
118
|
+
.hl-12 { color: var(--hl-12); }
|
|
119
|
+
.hl-13 { color: var(--hl-13); }
|
|
78
120
|
pre, code { background: var(--code-background); }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>LlmJson | @solvers-hub/llm-json</title><meta name="description" content="Documentation for @solvers-hub/llm-json"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@solvers-hub/llm-json</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@solvers-hub/llm-json</a></li><li><a href="LlmJson.html">LlmJson</a></li></ul><h1>Class LlmJson</h1></div><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><p>Main factory class for the LLM-JSON extractor SDK.</p>
|
|
2
|
-
</div><div class="tsd-comment tsd-typography"></div></section><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/
|
|
2
|
+
</div><div class="tsd-comment tsd-typography"></div></section><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/7b170770f3e486493c63e2e309803f04c81a473a/src/index.ts#L8">index.ts:8</a></li></ul></aside><section class="tsd-panel-group tsd-index-group"><section class="tsd-panel tsd-index-panel"><details class="tsd-index-content tsd-index-accordion" open><summary class="tsd-accordion-summary tsd-index-summary"><h5 class="tsd-index-heading uppercase" role="button" aria-expanded="false" tabIndex="0"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-chevronSmall"></use></svg> Index</h5></summary><div class="tsd-accordion-details"><section class="tsd-index-section"><h3 class="tsd-index-heading">Constructors</h3><div class="tsd-index-list"><a href="LlmJson.html#constructor" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-512"></use></svg><span>constructor</span></a>
|
|
3
3
|
</div></section><section class="tsd-index-section"><h3 class="tsd-index-heading">Properties</h3><div class="tsd-index-list"><a href="LlmJson.html#arrayExtractor" class="tsd-index-link tsd-is-private"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>array<wbr/>Extractor</span></a>
|
|
4
4
|
<a href="LlmJson.html#objectExtractor" class="tsd-index-link tsd-is-private"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>object<wbr/>Extractor</span></a>
|
|
5
5
|
<a href="LlmJson.html#instance" class="tsd-index-link tsd-is-private"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>instance</span></a>
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
<a href="LlmJson.html#getInstance" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-2048"></use></svg><span>get<wbr/>Instance</span></a>
|
|
9
9
|
</div></section></div></details></section></section><section class="tsd-panel-group tsd-member-group"><h2>Constructors</h2><section class="tsd-panel tsd-member"><a id="constructor" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>constructor</span><a href="#constructor" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures"><li class="tsd-signature tsd-anchor-link"><a id="constructor.new_LlmJson" class="tsd-anchor"></a><span class="tsd-kind-constructor-signature">new <wbr/>Llm<wbr/>Json</span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">options</span><span class="tsd-signature-symbol">?</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="LlmJson.html" class="tsd-signature-type tsd-kind-class">LlmJson</a><a href="#constructor.new_LlmJson" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></li><li class="tsd-description"><div class="tsd-comment tsd-typography"><p>Creates a new LlmJson instance with the specified options.</p>
|
|
10
10
|
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">options</span>: <a href="../interfaces/ExtractOptions.html" class="tsd-signature-type tsd-kind-interface">ExtractOptions</a><span class="tsd-signature-symbol"> = {}</span></span><div class="tsd-comment tsd-typography"><p>Configuration options for extraction.</p>
|
|
11
|
-
</div><div class="tsd-comment tsd-typography"></div></li></ul></div><h4 class="tsd-returns-title">Returns <a href="LlmJson.html" class="tsd-signature-type tsd-kind-class">LlmJson</a></h4><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/
|
|
11
|
+
</div><div class="tsd-comment tsd-typography"></div></li></ul></div><h4 class="tsd-returns-title">Returns <a href="LlmJson.html" class="tsd-signature-type tsd-kind-class">LlmJson</a></h4><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/7b170770f3e486493c63e2e309803f04c81a473a/src/index.ts#L17">index.ts:17</a></li></ul></aside></li></ul></section></section><section class="tsd-panel-group tsd-member-group"><h2>Properties</h2><section class="tsd-panel tsd-member tsd-is-private"><a id="arrayExtractor" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagPrivate">Private</code> <span>array<wbr/>Extractor</span><a href="#arrayExtractor" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">array<wbr/>Extractor</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">JsonArrayExtractor</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/7b170770f3e486493c63e2e309803f04c81a473a/src/index.ts#L11">index.ts:11</a></li></ul></aside></section><section class="tsd-panel tsd-member tsd-is-private"><a id="objectExtractor" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagPrivate">Private</code> <span>object<wbr/>Extractor</span><a href="#objectExtractor" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">object<wbr/>Extractor</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">JsonExtractor</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/7b170770f3e486493c63e2e309803f04c81a473a/src/index.ts#L10">index.ts:10</a></li></ul></aside></section><section class="tsd-panel tsd-member tsd-is-private"><a id="instance" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagStatic">Static</code> <code class="tsd-tag ts-flagPrivate">Private</code> <span>instance</span><a href="#instance" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">instance</span><span class="tsd-signature-symbol">:</span> <a href="LlmJson.html" class="tsd-signature-type tsd-kind-class">LlmJson</a></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/7b170770f3e486493c63e2e309803f04c81a473a/src/index.ts#L9">index.ts:9</a></li></ul></aside></section></section><section class="tsd-panel-group tsd-member-group"><h2>Methods</h2><section class="tsd-panel tsd-member"><a id="extract" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>extract</span><a href="#extract" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures"><li class="tsd-signature tsd-anchor-link"><a id="extract.extract-1" class="tsd-anchor"></a><span class="tsd-kind-call-signature">extract</span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">input</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../interfaces/ExtractResult.html" class="tsd-signature-type tsd-kind-interface">ExtractResult</a><a href="#extract.extract-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></li><li class="tsd-description"><div class="tsd-comment tsd-typography"><p>Extract JSON objects and text from a string input.</p>
|
|
12
12
|
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">input</span>: <span class="tsd-signature-type">string</span></span><div class="tsd-comment tsd-typography"><p>The input string that may contain JSON.</p>
|
|
13
13
|
</div><div class="tsd-comment tsd-typography"></div></li></ul></div><h4 class="tsd-returns-title">Returns <a href="../interfaces/ExtractResult.html" class="tsd-signature-type tsd-kind-interface">ExtractResult</a></h4><p>An object containing arrays of extracted text and JSON.</p>
|
|
14
|
-
<div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/
|
|
14
|
+
<div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/7b170770f3e486493c63e2e309803f04c81a473a/src/index.ts#L39">index.ts:39</a></li></ul></aside></li></ul></section><section class="tsd-panel tsd-member"><a id="extractAll" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>extract<wbr/>All</span><a href="#extractAll" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures"><li class="tsd-signature tsd-anchor-link"><a id="extractAll.extractAll-1" class="tsd-anchor"></a><span class="tsd-kind-call-signature">extract<wbr/>All</span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">input</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../interfaces/ExtractResult.html" class="tsd-signature-type tsd-kind-interface">ExtractResult</a><a href="#extractAll.extractAll-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></li><li class="tsd-description"><div class="tsd-comment tsd-typography"><p>Extract JSON objects, arrays, and text from a string input.</p>
|
|
15
15
|
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">input</span>: <span class="tsd-signature-type">string</span></span><div class="tsd-comment tsd-typography"><p>The input string that may contain JSON.</p>
|
|
16
16
|
</div><div class="tsd-comment tsd-typography"></div></li></ul></div><h4 class="tsd-returns-title">Returns <a href="../interfaces/ExtractResult.html" class="tsd-signature-type tsd-kind-interface">ExtractResult</a></h4><p>An object containing arrays of extracted text and JSON.</p>
|
|
17
|
-
<div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/
|
|
17
|
+
<div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/7b170770f3e486493c63e2e309803f04c81a473a/src/index.ts#L48">index.ts:48</a></li></ul></aside></li></ul></section><section class="tsd-panel tsd-member"><a id="getInstance" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagStatic">Static</code> <span>get<wbr/>Instance</span><a href="#getInstance" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures"><li class="tsd-signature tsd-anchor-link"><a id="getInstance.getInstance-1" class="tsd-anchor"></a><span class="tsd-kind-call-signature">get<wbr/>Instance</span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">options</span><span class="tsd-signature-symbol">?</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="LlmJson.html" class="tsd-signature-type tsd-kind-class">LlmJson</a><a href="#getInstance.getInstance-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></li><li class="tsd-description"><div class="tsd-comment tsd-typography"><p>Get or create a singleton instance of LlmJson.</p>
|
|
18
18
|
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">options</span>: <a href="../interfaces/ExtractOptions.html" class="tsd-signature-type tsd-kind-interface">ExtractOptions</a><span class="tsd-signature-symbol"> = {}</span></span><div class="tsd-comment tsd-typography"><p>Configuration options for extraction.</p>
|
|
19
19
|
</div><div class="tsd-comment tsd-typography"></div></li></ul></div><h4 class="tsd-returns-title">Returns <a href="LlmJson.html" class="tsd-signature-type tsd-kind-class">LlmJson</a></h4><p>The LlmJson singleton instance.</p>
|
|
20
|
-
<div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/
|
|
20
|
+
<div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/7b170770f3e486493c63e2e309803f04c81a473a/src/index.ts#L27">index.ts:27</a></li></ul></aside></li></ul></section></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-index-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#constructor" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-512"></use></svg><span>constructor</span></a><a href="#arrayExtractor" class="tsd-is-private"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>array<wbr/>Extractor</span></a><a href="#objectExtractor" class="tsd-is-private"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>object<wbr/>Extractor</span></a><a href="#instance" class="tsd-is-private"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>instance</span></a><a href="#extract" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-2048"></use></svg><span>extract</span></a><a href="#extractAll" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-2048"></use></svg><span>extract<wbr/>All</span></a><a href="#getInstance" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-2048"></use></svg><span>get<wbr/>Instance</span></a></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>@solvers-hub/llm-json</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|