@solvers-hub/llm-json 0.1.6 → 0.1.8
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/LICENSE +1 -1
- package/README.md +117 -108
- package/dist/{src/corrector.js → corrector.js} +11 -12
- package/dist/{src/extractor.d.ts → extractor.d.ts} +1 -1
- package/dist/{src/extractor.js → extractor.js} +12 -23
- package/dist/{src/validator.js → validator.js} +3 -0
- package/docs/classes/LlmJson.html +5 -5
- package/docs/index.html +9 -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/README.md +108 -59
- package/docs-md/classes/LlmJson.md +147 -147
- package/docs-md/interfaces/ExtractOptions.md +49 -29
- package/docs-md/interfaces/ExtractResult.md +49 -36
- package/docs-md/interfaces/JsonBlock.md +75 -75
- package/docs-md/interfaces/JsonParseError.md +49 -49
- package/docs-md/interfaces/SchemaDefinition.md +36 -0
- package/docs-md/interfaces/ValidationResult.md +62 -0
- package/docs-md/modules.md +28 -26
- package/examples/array-example.ts +69 -0
- package/{dist/examples/example.js → examples/example.ts} +48 -43
- package/examples/schema-validation-example.ts +140 -0
- package/examples/schema-validation-examples.ts +248 -0
- package/package.json +6 -6
- package/dist/examples/example.d.ts +0 -1
- /package/dist/{src/array-extractor.d.ts → array-extractor.d.ts} +0 -0
- /package/dist/{src/array-extractor.js → array-extractor.js} +0 -0
- /package/dist/{src/corrector.d.ts → corrector.d.ts} +0 -0
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/index.js → index.js} +0 -0
- /package/dist/{src/types.d.ts → types.d.ts} +0 -0
- /package/dist/{src/types.js → types.js} +0 -0
- /package/dist/{src/validator.d.ts → validator.d.ts} +0 -0
|
@@ -1,36 +1,49 @@
|
|
|
1
|
-
[@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / ExtractResult
|
|
2
|
-
|
|
3
|
-
# Interface: ExtractResult
|
|
4
|
-
|
|
5
|
-
Result of the JSON extraction.
|
|
6
|
-
|
|
7
|
-
## Table of contents
|
|
8
|
-
|
|
9
|
-
### Properties
|
|
10
|
-
|
|
11
|
-
- [json](ExtractResult.md#json)
|
|
12
|
-
- [text](ExtractResult.md#text)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
[@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / ExtractResult
|
|
2
|
+
|
|
3
|
+
# Interface: ExtractResult
|
|
4
|
+
|
|
5
|
+
Result of the JSON extraction.
|
|
6
|
+
|
|
7
|
+
## Table of contents
|
|
8
|
+
|
|
9
|
+
### Properties
|
|
10
|
+
|
|
11
|
+
- [json](ExtractResult.md#json)
|
|
12
|
+
- [text](ExtractResult.md#text)
|
|
13
|
+
- [validatedJson](ExtractResult.md#validatedjson)
|
|
14
|
+
|
|
15
|
+
## Properties
|
|
16
|
+
|
|
17
|
+
### json
|
|
18
|
+
|
|
19
|
+
• **json**: `any`[]
|
|
20
|
+
|
|
21
|
+
Array of parsed JSON objects extracted from the input.
|
|
22
|
+
|
|
23
|
+
#### Defined in
|
|
24
|
+
|
|
25
|
+
[types.ts:71](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L71)
|
|
26
|
+
|
|
27
|
+
___
|
|
28
|
+
|
|
29
|
+
### text
|
|
30
|
+
|
|
31
|
+
• **text**: `string`[]
|
|
32
|
+
|
|
33
|
+
Array of text blocks extracted from the input.
|
|
34
|
+
|
|
35
|
+
#### Defined in
|
|
36
|
+
|
|
37
|
+
[types.ts:66](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L66)
|
|
38
|
+
|
|
39
|
+
___
|
|
40
|
+
|
|
41
|
+
### validatedJson
|
|
42
|
+
|
|
43
|
+
• `Optional` **validatedJson**: [`ValidationResult`](ValidationResult.md)[]
|
|
44
|
+
|
|
45
|
+
Array of validated JSON results, only present if schemas were provided.
|
|
46
|
+
|
|
47
|
+
#### Defined in
|
|
48
|
+
|
|
49
|
+
[types.ts:76](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L76)
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
[@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / JsonBlock
|
|
2
|
-
|
|
3
|
-
# Interface: JsonBlock
|
|
4
|
-
|
|
5
|
-
Information about a detected JSON block.
|
|
6
|
-
|
|
7
|
-
## Table of contents
|
|
8
|
-
|
|
9
|
-
### Properties
|
|
10
|
-
|
|
11
|
-
- [endIndex](JsonBlock.md#endindex)
|
|
12
|
-
- [parsed](JsonBlock.md#parsed)
|
|
13
|
-
- [raw](JsonBlock.md#raw)
|
|
14
|
-
- [startIndex](JsonBlock.md#startindex)
|
|
15
|
-
- [wasCorrected](JsonBlock.md#wascorrected)
|
|
16
|
-
|
|
17
|
-
## Properties
|
|
18
|
-
|
|
19
|
-
### endIndex
|
|
20
|
-
|
|
21
|
-
• **endIndex**: `number`
|
|
22
|
-
|
|
23
|
-
The end index of the JSON block in the input string.
|
|
24
|
-
|
|
25
|
-
#### Defined in
|
|
26
|
-
|
|
27
|
-
[types.ts:
|
|
28
|
-
|
|
29
|
-
___
|
|
30
|
-
|
|
31
|
-
### parsed
|
|
32
|
-
|
|
33
|
-
• `Optional` **parsed**: `any`
|
|
34
|
-
|
|
35
|
-
The parsed JSON object.
|
|
36
|
-
|
|
37
|
-
#### Defined in
|
|
38
|
-
|
|
39
|
-
[types.ts:
|
|
40
|
-
|
|
41
|
-
___
|
|
42
|
-
|
|
43
|
-
### raw
|
|
44
|
-
|
|
45
|
-
• **raw**: `string`
|
|
46
|
-
|
|
47
|
-
The raw JSON string.
|
|
48
|
-
|
|
49
|
-
#### Defined in
|
|
50
|
-
|
|
51
|
-
[types.ts:
|
|
52
|
-
|
|
53
|
-
___
|
|
54
|
-
|
|
55
|
-
### startIndex
|
|
56
|
-
|
|
57
|
-
• **startIndex**: `number`
|
|
58
|
-
|
|
59
|
-
The start index of the JSON block in the input string.
|
|
60
|
-
|
|
61
|
-
#### Defined in
|
|
62
|
-
|
|
63
|
-
[types.ts:
|
|
64
|
-
|
|
65
|
-
___
|
|
66
|
-
|
|
67
|
-
### wasCorrected
|
|
68
|
-
|
|
69
|
-
• `Optional` **wasCorrected**: `boolean`
|
|
70
|
-
|
|
71
|
-
Whether the JSON was corrected.
|
|
72
|
-
|
|
73
|
-
#### Defined in
|
|
74
|
-
|
|
75
|
-
[types.ts:
|
|
1
|
+
[@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / JsonBlock
|
|
2
|
+
|
|
3
|
+
# Interface: JsonBlock
|
|
4
|
+
|
|
5
|
+
Information about a detected JSON block.
|
|
6
|
+
|
|
7
|
+
## Table of contents
|
|
8
|
+
|
|
9
|
+
### Properties
|
|
10
|
+
|
|
11
|
+
- [endIndex](JsonBlock.md#endindex)
|
|
12
|
+
- [parsed](JsonBlock.md#parsed)
|
|
13
|
+
- [raw](JsonBlock.md#raw)
|
|
14
|
+
- [startIndex](JsonBlock.md#startindex)
|
|
15
|
+
- [wasCorrected](JsonBlock.md#wascorrected)
|
|
16
|
+
|
|
17
|
+
## Properties
|
|
18
|
+
|
|
19
|
+
### endIndex
|
|
20
|
+
|
|
21
|
+
• **endIndex**: `number`
|
|
22
|
+
|
|
23
|
+
The end index of the JSON block in the input string.
|
|
24
|
+
|
|
25
|
+
#### Defined in
|
|
26
|
+
|
|
27
|
+
[types.ts:96](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L96)
|
|
28
|
+
|
|
29
|
+
___
|
|
30
|
+
|
|
31
|
+
### parsed
|
|
32
|
+
|
|
33
|
+
• `Optional` **parsed**: `any`
|
|
34
|
+
|
|
35
|
+
The parsed JSON object.
|
|
36
|
+
|
|
37
|
+
#### Defined in
|
|
38
|
+
|
|
39
|
+
[types.ts:106](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L106)
|
|
40
|
+
|
|
41
|
+
___
|
|
42
|
+
|
|
43
|
+
### raw
|
|
44
|
+
|
|
45
|
+
• **raw**: `string`
|
|
46
|
+
|
|
47
|
+
The raw JSON string.
|
|
48
|
+
|
|
49
|
+
#### Defined in
|
|
50
|
+
|
|
51
|
+
[types.ts:86](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L86)
|
|
52
|
+
|
|
53
|
+
___
|
|
54
|
+
|
|
55
|
+
### startIndex
|
|
56
|
+
|
|
57
|
+
• **startIndex**: `number`
|
|
58
|
+
|
|
59
|
+
The start index of the JSON block in the input string.
|
|
60
|
+
|
|
61
|
+
#### Defined in
|
|
62
|
+
|
|
63
|
+
[types.ts:91](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L91)
|
|
64
|
+
|
|
65
|
+
___
|
|
66
|
+
|
|
67
|
+
### wasCorrected
|
|
68
|
+
|
|
69
|
+
• `Optional` **wasCorrected**: `boolean`
|
|
70
|
+
|
|
71
|
+
Whether the JSON was corrected.
|
|
72
|
+
|
|
73
|
+
#### Defined in
|
|
74
|
+
|
|
75
|
+
[types.ts:101](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L101)
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
[@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / JsonParseError
|
|
2
|
-
|
|
3
|
-
# Interface: JsonParseError
|
|
4
|
-
|
|
5
|
-
Error information for JSON parsing failures.
|
|
6
|
-
|
|
7
|
-
## Table of contents
|
|
8
|
-
|
|
9
|
-
### Properties
|
|
10
|
-
|
|
11
|
-
- [message](JsonParseError.md#message)
|
|
12
|
-
- [position](JsonParseError.md#position)
|
|
13
|
-
- [raw](JsonParseError.md#raw)
|
|
14
|
-
|
|
15
|
-
## Properties
|
|
16
|
-
|
|
17
|
-
### message
|
|
18
|
-
|
|
19
|
-
• **message**: `string`
|
|
20
|
-
|
|
21
|
-
The original error message.
|
|
22
|
-
|
|
23
|
-
#### Defined in
|
|
24
|
-
|
|
25
|
-
[types.ts:
|
|
26
|
-
|
|
27
|
-
___
|
|
28
|
-
|
|
29
|
-
### position
|
|
30
|
-
|
|
31
|
-
• `Optional` **position**: `number`
|
|
32
|
-
|
|
33
|
-
The position in the JSON string where the error occurred.
|
|
34
|
-
|
|
35
|
-
#### Defined in
|
|
36
|
-
|
|
37
|
-
[types.ts:
|
|
38
|
-
|
|
39
|
-
___
|
|
40
|
-
|
|
41
|
-
### raw
|
|
42
|
-
|
|
43
|
-
• **raw**: `string`
|
|
44
|
-
|
|
45
|
-
The raw JSON string that failed to parse.
|
|
46
|
-
|
|
47
|
-
#### Defined in
|
|
48
|
-
|
|
49
|
-
[types.ts:
|
|
1
|
+
[@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / JsonParseError
|
|
2
|
+
|
|
3
|
+
# Interface: JsonParseError
|
|
4
|
+
|
|
5
|
+
Error information for JSON parsing failures.
|
|
6
|
+
|
|
7
|
+
## Table of contents
|
|
8
|
+
|
|
9
|
+
### Properties
|
|
10
|
+
|
|
11
|
+
- [message](JsonParseError.md#message)
|
|
12
|
+
- [position](JsonParseError.md#position)
|
|
13
|
+
- [raw](JsonParseError.md#raw)
|
|
14
|
+
|
|
15
|
+
## Properties
|
|
16
|
+
|
|
17
|
+
### message
|
|
18
|
+
|
|
19
|
+
• **message**: `string`
|
|
20
|
+
|
|
21
|
+
The original error message.
|
|
22
|
+
|
|
23
|
+
#### Defined in
|
|
24
|
+
|
|
25
|
+
[types.ts:116](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L116)
|
|
26
|
+
|
|
27
|
+
___
|
|
28
|
+
|
|
29
|
+
### position
|
|
30
|
+
|
|
31
|
+
• `Optional` **position**: `number`
|
|
32
|
+
|
|
33
|
+
The position in the JSON string where the error occurred.
|
|
34
|
+
|
|
35
|
+
#### Defined in
|
|
36
|
+
|
|
37
|
+
[types.ts:126](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L126)
|
|
38
|
+
|
|
39
|
+
___
|
|
40
|
+
|
|
41
|
+
### raw
|
|
42
|
+
|
|
43
|
+
• **raw**: `string`
|
|
44
|
+
|
|
45
|
+
The raw JSON string that failed to parse.
|
|
46
|
+
|
|
47
|
+
#### Defined in
|
|
48
|
+
|
|
49
|
+
[types.ts:121](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L121)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / SchemaDefinition
|
|
2
|
+
|
|
3
|
+
# Interface: SchemaDefinition
|
|
4
|
+
|
|
5
|
+
Definition of a JSON schema for validation.
|
|
6
|
+
|
|
7
|
+
## Table of contents
|
|
8
|
+
|
|
9
|
+
### Properties
|
|
10
|
+
|
|
11
|
+
- [name](SchemaDefinition.md#name)
|
|
12
|
+
- [schema](SchemaDefinition.md#schema)
|
|
13
|
+
|
|
14
|
+
## Properties
|
|
15
|
+
|
|
16
|
+
### name
|
|
17
|
+
|
|
18
|
+
• **name**: `string`
|
|
19
|
+
|
|
20
|
+
A unique name for the schema to identify which schema matched.
|
|
21
|
+
|
|
22
|
+
#### Defined in
|
|
23
|
+
|
|
24
|
+
[types.ts:26](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L26)
|
|
25
|
+
|
|
26
|
+
___
|
|
27
|
+
|
|
28
|
+
### schema
|
|
29
|
+
|
|
30
|
+
• **schema**: `object`
|
|
31
|
+
|
|
32
|
+
The JSON schema object conforming to JSON Schema specification.
|
|
33
|
+
|
|
34
|
+
#### Defined in
|
|
35
|
+
|
|
36
|
+
[types.ts:31](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L31)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / ValidationResult
|
|
2
|
+
|
|
3
|
+
# Interface: ValidationResult
|
|
4
|
+
|
|
5
|
+
Result of schema validation for a JSON object.
|
|
6
|
+
|
|
7
|
+
## Table of contents
|
|
8
|
+
|
|
9
|
+
### Properties
|
|
10
|
+
|
|
11
|
+
- [isValid](ValidationResult.md#isvalid)
|
|
12
|
+
- [json](ValidationResult.md#json)
|
|
13
|
+
- [matchedSchema](ValidationResult.md#matchedschema)
|
|
14
|
+
- [validationErrors](ValidationResult.md#validationerrors)
|
|
15
|
+
|
|
16
|
+
## Properties
|
|
17
|
+
|
|
18
|
+
### isValid
|
|
19
|
+
|
|
20
|
+
• **isValid**: `boolean`
|
|
21
|
+
|
|
22
|
+
Whether the JSON is valid according to the matched schema.
|
|
23
|
+
|
|
24
|
+
#### Defined in
|
|
25
|
+
|
|
26
|
+
[types.ts:51](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L51)
|
|
27
|
+
|
|
28
|
+
___
|
|
29
|
+
|
|
30
|
+
### json
|
|
31
|
+
|
|
32
|
+
• **json**: `any`
|
|
33
|
+
|
|
34
|
+
The JSON object that was validated.
|
|
35
|
+
|
|
36
|
+
#### Defined in
|
|
37
|
+
|
|
38
|
+
[types.ts:41](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L41)
|
|
39
|
+
|
|
40
|
+
___
|
|
41
|
+
|
|
42
|
+
### matchedSchema
|
|
43
|
+
|
|
44
|
+
• **matchedSchema**: ``null`` \| `string`
|
|
45
|
+
|
|
46
|
+
The name of the schema that matched, or null if no schema matched.
|
|
47
|
+
|
|
48
|
+
#### Defined in
|
|
49
|
+
|
|
50
|
+
[types.ts:46](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L46)
|
|
51
|
+
|
|
52
|
+
___
|
|
53
|
+
|
|
54
|
+
### validationErrors
|
|
55
|
+
|
|
56
|
+
• `Optional` **validationErrors**: `any`[]
|
|
57
|
+
|
|
58
|
+
Validation errors if any, or undefined if validation passed.
|
|
59
|
+
|
|
60
|
+
#### Defined in
|
|
61
|
+
|
|
62
|
+
[types.ts:56](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L56)
|
package/docs-md/modules.md
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
[@solvers-hub/llm-json](README.md) / Exports
|
|
2
|
-
|
|
3
|
-
# @solvers-hub/llm-json
|
|
4
|
-
|
|
5
|
-
## Table of contents
|
|
6
|
-
|
|
7
|
-
### References
|
|
8
|
-
|
|
9
|
-
- [default](modules.md#default)
|
|
10
|
-
|
|
11
|
-
### Classes
|
|
12
|
-
|
|
13
|
-
- [LlmJson](classes/LlmJson.md)
|
|
14
|
-
|
|
15
|
-
### Interfaces
|
|
16
|
-
|
|
17
|
-
- [ExtractOptions](interfaces/ExtractOptions.md)
|
|
18
|
-
- [ExtractResult](interfaces/ExtractResult.md)
|
|
19
|
-
- [JsonBlock](interfaces/JsonBlock.md)
|
|
20
|
-
- [JsonParseError](interfaces/JsonParseError.md)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
[@solvers-hub/llm-json](README.md) / Exports
|
|
2
|
+
|
|
3
|
+
# @solvers-hub/llm-json
|
|
4
|
+
|
|
5
|
+
## Table of contents
|
|
6
|
+
|
|
7
|
+
### References
|
|
8
|
+
|
|
9
|
+
- [default](modules.md#default)
|
|
10
|
+
|
|
11
|
+
### Classes
|
|
12
|
+
|
|
13
|
+
- [LlmJson](classes/LlmJson.md)
|
|
14
|
+
|
|
15
|
+
### Interfaces
|
|
16
|
+
|
|
17
|
+
- [ExtractOptions](interfaces/ExtractOptions.md)
|
|
18
|
+
- [ExtractResult](interfaces/ExtractResult.md)
|
|
19
|
+
- [JsonBlock](interfaces/JsonBlock.md)
|
|
20
|
+
- [JsonParseError](interfaces/JsonParseError.md)
|
|
21
|
+
- [SchemaDefinition](interfaces/SchemaDefinition.md)
|
|
22
|
+
- [ValidationResult](interfaces/ValidationResult.md)
|
|
23
|
+
|
|
24
|
+
## References
|
|
25
|
+
|
|
26
|
+
### default
|
|
27
|
+
|
|
28
|
+
Renames and re-exports [LlmJson](classes/LlmJson.md)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import LlmJson from '../src/index';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Example demonstrating how to use the LLM-JSON library for arrays.
|
|
5
|
+
*/
|
|
6
|
+
function runArrayExample() {
|
|
7
|
+
// Create an instance with auto-correction enabled
|
|
8
|
+
const llmJson = new LlmJson({ attemptCorrection: true });
|
|
9
|
+
|
|
10
|
+
// Simple array example
|
|
11
|
+
const simpleArrayInput = `Here is a list of names: ["John", "Jane", "Bob"]`;
|
|
12
|
+
|
|
13
|
+
console.log("=== Simple Array Example ===");
|
|
14
|
+
|
|
15
|
+
// Using extract - might not properly handle standalone arrays
|
|
16
|
+
const simpleExtractResult = llmJson.extract(simpleArrayInput);
|
|
17
|
+
console.log("With extract():");
|
|
18
|
+
console.log("Text:", simpleExtractResult.text);
|
|
19
|
+
console.log("JSON:", JSON.stringify(simpleExtractResult.json, null, 2));
|
|
20
|
+
console.log();
|
|
21
|
+
|
|
22
|
+
// Using extractAll - properly handles arrays
|
|
23
|
+
const simpleExtractAllResult = llmJson.extractAll(simpleArrayInput);
|
|
24
|
+
console.log("With extractAll():");
|
|
25
|
+
console.log("Text:", simpleExtractAllResult.text);
|
|
26
|
+
console.log("JSON:", JSON.stringify(simpleExtractAllResult.json, null, 2));
|
|
27
|
+
console.log();
|
|
28
|
+
|
|
29
|
+
// Complex array example
|
|
30
|
+
const complexArrayInput = `Here's an array of users:
|
|
31
|
+
[
|
|
32
|
+
{
|
|
33
|
+
"name": "John Doe",
|
|
34
|
+
"age": 30,
|
|
35
|
+
"skills": ["JavaScript", "TypeScript"]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "Jane Smith",
|
|
39
|
+
"age": 28,
|
|
40
|
+
"skills": ["Python", "Machine Learning"]
|
|
41
|
+
}
|
|
42
|
+
]`;
|
|
43
|
+
|
|
44
|
+
console.log("=== Complex Array Example ===");
|
|
45
|
+
|
|
46
|
+
// Using extractAll - properly handles complex arrays
|
|
47
|
+
const complexResult = llmJson.extractAll(complexArrayInput);
|
|
48
|
+
console.log("With extractAll():");
|
|
49
|
+
console.log("Text:", complexResult.text);
|
|
50
|
+
console.log("JSON:", JSON.stringify(complexResult.json, null, 2));
|
|
51
|
+
console.log();
|
|
52
|
+
|
|
53
|
+
// Multiple JSON structures example
|
|
54
|
+
const mixedInput = `Here's an object: {"name": "John", "age": 30}
|
|
55
|
+
|
|
56
|
+
And here's an array: [1, 2, 3, 4, 5]
|
|
57
|
+
|
|
58
|
+
And another object: {"city": "New York", "country": "USA"}`;
|
|
59
|
+
|
|
60
|
+
console.log("=== Mixed JSON Types Example ===");
|
|
61
|
+
|
|
62
|
+
// Using extractAll - handles both objects and arrays
|
|
63
|
+
const mixedResult = llmJson.extractAll(mixedInput);
|
|
64
|
+
console.log("With extractAll():");
|
|
65
|
+
console.log("Text:", mixedResult.text);
|
|
66
|
+
console.log("JSON:", JSON.stringify(mixedResult.json, null, 2));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
runArrayExample();
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const llmJson = new index_1.default({ attemptCorrection: true });
|
|
13
|
-
// Example from the requirements
|
|
14
|
-
const input = `<research_planning>
|
|
1
|
+
import LlmJson from '../src/index';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Example demonstrating how to use the LLM-JSON library.
|
|
5
|
+
*/
|
|
6
|
+
function runExample() {
|
|
7
|
+
// Create an instance with auto-correction enabled
|
|
8
|
+
const llmJson = new LlmJson({ attemptCorrection: true });
|
|
9
|
+
|
|
10
|
+
// Example from the requirements
|
|
11
|
+
const input = `<research_planning>
|
|
15
12
|
a. Summary: The given organization is unnamed and works in the area of "something new," which suggests an innovative or emerging field. This could involve novel technologies, fresh market approaches, or unexplored domains. Without specific details, assumptions about the sector or industry may involve startups, tech innovation, or trendsetting industries. The focus and goals may lean toward exploration, user adoption, and refinement of novel concepts.
|
|
16
13
|
|
|
17
14
|
b. Potential Product Features:
|
|
@@ -56,27 +53,32 @@ e. Narrowing Down Objectives:
|
|
|
56
53
|
}
|
|
57
54
|
]
|
|
58
55
|
}
|
|
59
|
-
\`\`\``;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
console.log(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
console.log(
|
|
78
|
-
|
|
79
|
-
|
|
56
|
+
\`\`\``;
|
|
57
|
+
|
|
58
|
+
// Extract JSON and text
|
|
59
|
+
const result = llmJson.extract(input);
|
|
60
|
+
|
|
61
|
+
console.log("Extracted text:");
|
|
62
|
+
console.log("------------------");
|
|
63
|
+
result.text.forEach((text, index) => {
|
|
64
|
+
console.log(`Text block ${index + 1}:`);
|
|
65
|
+
console.log(text);
|
|
66
|
+
console.log();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
console.log("Extracted JSON:");
|
|
70
|
+
console.log("------------------");
|
|
71
|
+
result.json.forEach((json, index) => {
|
|
72
|
+
console.log(`JSON object ${index + 1}:`);
|
|
73
|
+
console.log(JSON.stringify(json, null, 2));
|
|
74
|
+
console.log();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Example with malformed JSON
|
|
78
|
+
console.log("\nExample with malformed JSON:");
|
|
79
|
+
console.log("---------------------------");
|
|
80
|
+
|
|
81
|
+
const malformedInput = `Here is some information:
|
|
80
82
|
|
|
81
83
|
{
|
|
82
84
|
name: "John",
|
|
@@ -86,11 +88,14 @@ e. Narrowing Down Objectives:
|
|
|
86
88
|
theme: "dark",
|
|
87
89
|
notifications: true,
|
|
88
90
|
}
|
|
89
|
-
}`;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
}`;
|
|
92
|
+
|
|
93
|
+
const malformedResult = llmJson.extract(malformedInput);
|
|
94
|
+
|
|
95
|
+
console.log("Text:");
|
|
96
|
+
console.log(malformedResult.text[0]);
|
|
97
|
+
console.log("\nCorrected JSON:");
|
|
98
|
+
console.log(JSON.stringify(malformedResult.json[0], null, 2));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
runExample();
|