@langchain/core 0.3.50 → 0.3.51
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/utils/json.cjs +17 -4
- package/dist/utils/json.js +17 -4
- package/package.json +1 -1
package/dist/utils/json.cjs
CHANGED
|
@@ -4,13 +4,26 @@ exports.parsePartialJson = exports.parseJsonMarkdown = void 0;
|
|
|
4
4
|
function parseJsonMarkdown(s, parser = parsePartialJson) {
|
|
5
5
|
// eslint-disable-next-line no-param-reassign
|
|
6
6
|
s = s.trim();
|
|
7
|
-
const
|
|
8
|
-
if (
|
|
7
|
+
const firstFenceIndex = s.indexOf("```");
|
|
8
|
+
if (firstFenceIndex === -1) {
|
|
9
9
|
return parser(s);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
let contentAfterFence = s.substring(firstFenceIndex + 3);
|
|
12
|
+
if (contentAfterFence.startsWith("json\n")) {
|
|
13
|
+
contentAfterFence = contentAfterFence.substring(5);
|
|
13
14
|
}
|
|
15
|
+
else if (contentAfterFence.startsWith("json")) {
|
|
16
|
+
contentAfterFence = contentAfterFence.substring(4);
|
|
17
|
+
}
|
|
18
|
+
else if (contentAfterFence.startsWith("\n")) {
|
|
19
|
+
contentAfterFence = contentAfterFence.substring(1);
|
|
20
|
+
}
|
|
21
|
+
const closingFenceIndex = contentAfterFence.indexOf("```");
|
|
22
|
+
let finalContent = contentAfterFence;
|
|
23
|
+
if (closingFenceIndex !== -1) {
|
|
24
|
+
finalContent = contentAfterFence.substring(0, closingFenceIndex);
|
|
25
|
+
}
|
|
26
|
+
return parser(finalContent.trim());
|
|
14
27
|
}
|
|
15
28
|
exports.parseJsonMarkdown = parseJsonMarkdown;
|
|
16
29
|
// Adapted from https://github.com/KillianLucas/open-interpreter/blob/main/interpreter/core/llm/utils/parse_partial_json.py
|
package/dist/utils/json.js
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
export function parseJsonMarkdown(s, parser = parsePartialJson) {
|
|
2
2
|
// eslint-disable-next-line no-param-reassign
|
|
3
3
|
s = s.trim();
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
4
|
+
const firstFenceIndex = s.indexOf("```");
|
|
5
|
+
if (firstFenceIndex === -1) {
|
|
6
6
|
return parser(s);
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
let contentAfterFence = s.substring(firstFenceIndex + 3);
|
|
9
|
+
if (contentAfterFence.startsWith("json\n")) {
|
|
10
|
+
contentAfterFence = contentAfterFence.substring(5);
|
|
10
11
|
}
|
|
12
|
+
else if (contentAfterFence.startsWith("json")) {
|
|
13
|
+
contentAfterFence = contentAfterFence.substring(4);
|
|
14
|
+
}
|
|
15
|
+
else if (contentAfterFence.startsWith("\n")) {
|
|
16
|
+
contentAfterFence = contentAfterFence.substring(1);
|
|
17
|
+
}
|
|
18
|
+
const closingFenceIndex = contentAfterFence.indexOf("```");
|
|
19
|
+
let finalContent = contentAfterFence;
|
|
20
|
+
if (closingFenceIndex !== -1) {
|
|
21
|
+
finalContent = contentAfterFence.substring(0, closingFenceIndex);
|
|
22
|
+
}
|
|
23
|
+
return parser(finalContent.trim());
|
|
11
24
|
}
|
|
12
25
|
// Adapted from https://github.com/KillianLucas/open-interpreter/blob/main/interpreter/core/llm/utils/parse_partial_json.py
|
|
13
26
|
// MIT License
|