langchain 0.0.76 → 0.0.77
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/chains/query_constructor/ir.cjs +1 -0
- package/chains/query_constructor/ir.d.ts +1 -0
- package/chains/query_constructor/ir.js +1 -0
- package/chains/query_constructor.cjs +1 -0
- package/chains/query_constructor.d.ts +1 -0
- package/chains/query_constructor.js +1 -0
- package/dist/agents/chat_convo/index.cjs +27 -11
- package/dist/agents/chat_convo/index.d.ts +4 -1
- package/dist/agents/chat_convo/index.js +28 -12
- package/dist/agents/chat_convo/outputParser.cjs +79 -7
- package/dist/agents/chat_convo/outputParser.d.ts +25 -13
- package/dist/agents/chat_convo/outputParser.js +77 -6
- package/dist/agents/chat_convo/prompt.cjs +11 -8
- package/dist/agents/chat_convo/prompt.d.ts +2 -2
- package/dist/agents/chat_convo/prompt.js +11 -8
- package/dist/callbacks/handlers/tracer_langchain.cjs +12 -4
- package/dist/callbacks/handlers/tracer_langchain.d.ts +4 -1
- package/dist/callbacks/handlers/tracer_langchain.js +12 -4
- package/dist/callbacks/manager.cjs +6 -2
- package/dist/callbacks/manager.js +6 -2
- package/dist/chains/query_constructor/index.cjs +105 -0
- package/dist/chains/query_constructor/index.d.ts +37 -0
- package/dist/chains/query_constructor/index.js +95 -0
- package/dist/chains/query_constructor/ir.cjs +116 -0
- package/dist/chains/query_constructor/ir.d.ts +60 -0
- package/dist/chains/query_constructor/ir.js +107 -0
- package/dist/chains/query_constructor/parser.cjs +103 -0
- package/dist/chains/query_constructor/parser.d.ts +12 -0
- package/dist/chains/query_constructor/parser.js +99 -0
- package/dist/chains/query_constructor/prompt.cjs +127 -0
- package/dist/chains/query_constructor/prompt.d.ts +15 -0
- package/dist/chains/query_constructor/prompt.js +124 -0
- package/dist/chains/sql_db/sql_db_chain.cjs +13 -0
- package/dist/chains/sql_db/sql_db_chain.d.ts +2 -0
- package/dist/chains/sql_db/sql_db_chain.js +13 -0
- package/dist/client/langchainplus.cjs +21 -15
- package/dist/client/langchainplus.d.ts +4 -2
- package/dist/client/langchainplus.js +21 -15
- package/dist/llms/sagemaker_endpoint.cjs +123 -0
- package/dist/llms/sagemaker_endpoint.d.ts +82 -0
- package/dist/llms/sagemaker_endpoint.js +118 -0
- package/dist/memory/buffer_memory.cjs +1 -1
- package/dist/memory/buffer_memory.js +1 -1
- package/dist/memory/buffer_window_memory.cjs +1 -1
- package/dist/memory/buffer_window_memory.js +1 -1
- package/dist/output_parsers/expression.cjs +68 -0
- package/dist/output_parsers/expression.d.ts +25 -0
- package/dist/output_parsers/expression.js +49 -0
- package/dist/output_parsers/expression_type_handlers/array_literal_expression_handler.cjs +26 -0
- package/dist/output_parsers/expression_type_handlers/array_literal_expression_handler.d.ts +7 -0
- package/dist/output_parsers/expression_type_handlers/array_literal_expression_handler.js +22 -0
- package/dist/output_parsers/expression_type_handlers/base.cjs +67 -0
- package/dist/output_parsers/expression_type_handlers/base.d.ts +23 -0
- package/dist/output_parsers/expression_type_handlers/base.js +62 -0
- package/dist/output_parsers/expression_type_handlers/boolean_literal_handler.cjs +24 -0
- package/dist/output_parsers/expression_type_handlers/boolean_literal_handler.d.ts +7 -0
- package/dist/output_parsers/expression_type_handlers/boolean_literal_handler.js +20 -0
- package/dist/output_parsers/expression_type_handlers/call_expression_handler.cjs +52 -0
- package/dist/output_parsers/expression_type_handlers/call_expression_handler.d.ts +7 -0
- package/dist/output_parsers/expression_type_handlers/call_expression_handler.js +48 -0
- package/dist/output_parsers/expression_type_handlers/factory.cjs +56 -0
- package/dist/output_parsers/expression_type_handlers/factory.d.ts +9 -0
- package/dist/output_parsers/expression_type_handlers/factory.js +52 -0
- package/dist/output_parsers/expression_type_handlers/identifier_handler.cjs +22 -0
- package/dist/output_parsers/expression_type_handlers/identifier_handler.d.ts +7 -0
- package/dist/output_parsers/expression_type_handlers/identifier_handler.js +18 -0
- package/dist/output_parsers/expression_type_handlers/member_expression_handler.cjs +45 -0
- package/dist/output_parsers/expression_type_handlers/member_expression_handler.d.ts +7 -0
- package/dist/output_parsers/expression_type_handlers/member_expression_handler.js +41 -0
- package/dist/output_parsers/expression_type_handlers/numeric_literal_handler.cjs +24 -0
- package/dist/output_parsers/expression_type_handlers/numeric_literal_handler.d.ts +7 -0
- package/dist/output_parsers/expression_type_handlers/numeric_literal_handler.js +20 -0
- package/dist/output_parsers/expression_type_handlers/object_literal_expression_handler.cjs +29 -0
- package/dist/output_parsers/expression_type_handlers/object_literal_expression_handler.d.ts +7 -0
- package/dist/output_parsers/expression_type_handlers/object_literal_expression_handler.js +25 -0
- package/dist/output_parsers/expression_type_handlers/property_assignment_handler.cjs +36 -0
- package/dist/output_parsers/expression_type_handlers/property_assignment_handler.d.ts +7 -0
- package/dist/output_parsers/expression_type_handlers/property_assignment_handler.js +32 -0
- package/dist/output_parsers/expression_type_handlers/string_literal_handler.cjs +22 -0
- package/dist/output_parsers/expression_type_handlers/string_literal_handler.d.ts +7 -0
- package/dist/output_parsers/expression_type_handlers/string_literal_handler.js +18 -0
- package/dist/output_parsers/expression_type_handlers/types.cjs +2 -0
- package/dist/output_parsers/expression_type_handlers/types.d.ts +41 -0
- package/dist/output_parsers/expression_type_handlers/types.js +1 -0
- package/dist/output_parsers/index.cjs +2 -1
- package/dist/output_parsers/index.d.ts +1 -1
- package/dist/output_parsers/index.js +1 -1
- package/dist/output_parsers/structured.cjs +81 -23
- package/dist/output_parsers/structured.d.ts +18 -0
- package/dist/output_parsers/structured.js +79 -22
- package/dist/retrievers/self_query/index.cjs +79 -0
- package/dist/retrievers/self_query/index.d.ts +33 -0
- package/dist/retrievers/self_query/index.js +74 -0
- package/dist/retrievers/self_query/translator.cjs +72 -0
- package/dist/retrievers/self_query/translator.d.ts +14 -0
- package/dist/retrievers/self_query/translator.js +67 -0
- package/dist/schema/query_constructor.cjs +26 -0
- package/dist/schema/query_constructor.d.ts +6 -0
- package/dist/schema/query_constructor.js +22 -0
- package/dist/tools/json.cjs +3 -1
- package/dist/tools/json.js +3 -1
- package/dist/util/event-source-parse.cjs +31 -5
- package/dist/util/event-source-parse.d.ts +3 -3
- package/dist/util/event-source-parse.js +31 -5
- package/llms/sagemaker_endpoint.cjs +1 -0
- package/llms/sagemaker_endpoint.d.ts +1 -0
- package/llms/sagemaker_endpoint.js +1 -0
- package/output_parsers/expression.cjs +1 -0
- package/output_parsers/expression.d.ts +1 -0
- package/output_parsers/expression.js +1 -0
- package/package.json +61 -3
- package/retrievers/self_query.cjs +1 -0
- package/retrievers/self_query.d.ts +1 -0
- package/retrievers/self_query.js +1 -0
- package/schema/query_constructor.cjs +1 -0
- package/schema/query_constructor.d.ts +1 -0
- package/schema/query_constructor.js +1 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemberExpressionHandler = void 0;
|
|
4
|
+
const base_js_1 = require("./base.cjs");
|
|
5
|
+
class MemberExpressionHandler extends base_js_1.NodeHandler {
|
|
6
|
+
async accepts(node) {
|
|
7
|
+
if (base_js_1.ASTParser.isMemberExpression(node)) {
|
|
8
|
+
return node;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async handle(node) {
|
|
15
|
+
if (!this.parentHandler) {
|
|
16
|
+
throw new Error("ArrayLiteralExpressionHandler must have a parent handler");
|
|
17
|
+
}
|
|
18
|
+
const { object, property } = node;
|
|
19
|
+
let prop;
|
|
20
|
+
if (base_js_1.ASTParser.isIdentifier(property)) {
|
|
21
|
+
prop = property.name.replace(/^["'](.+(?=["']$))["']$/, "$1");
|
|
22
|
+
}
|
|
23
|
+
else if (base_js_1.ASTParser.isStringLiteral(property)) {
|
|
24
|
+
prop = `${property.value}`.replace(/^["'](.+(?=["']$))["']$/, "$1");
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new Error("Invalid property key type");
|
|
28
|
+
}
|
|
29
|
+
let identifier;
|
|
30
|
+
if (base_js_1.ASTParser.isIdentifier(object)) {
|
|
31
|
+
identifier = object.name.replace(/^["'](.+(?=["']$))["']$/, "$1");
|
|
32
|
+
}
|
|
33
|
+
else if (base_js_1.ASTParser.isLiteral(object)) {
|
|
34
|
+
identifier = `${object.value}`.replace(/^["'](.+(?=["']$))["']$/, "$1");
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new Error("Invalid object type");
|
|
38
|
+
}
|
|
39
|
+
if (object.type !== "Identifier" && object.type !== "Literal") {
|
|
40
|
+
throw new Error("ArrayExpression is not supported");
|
|
41
|
+
}
|
|
42
|
+
return { type: "member_expression", identifier, property: prop };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.MemberExpressionHandler = MemberExpressionHandler;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ESTree } from "meriyah";
|
|
2
|
+
import { NodeHandler } from "./base.js";
|
|
3
|
+
import { MemberExpressionType } from "./types.js";
|
|
4
|
+
export declare class MemberExpressionHandler extends NodeHandler {
|
|
5
|
+
accepts(node: ESTree.Node): Promise<ESTree.MemberExpression | boolean>;
|
|
6
|
+
handle(node: ESTree.MemberExpression): Promise<MemberExpressionType>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { NodeHandler, ASTParser } from "./base.js";
|
|
2
|
+
export class MemberExpressionHandler extends NodeHandler {
|
|
3
|
+
async accepts(node) {
|
|
4
|
+
if (ASTParser.isMemberExpression(node)) {
|
|
5
|
+
return node;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
async handle(node) {
|
|
12
|
+
if (!this.parentHandler) {
|
|
13
|
+
throw new Error("ArrayLiteralExpressionHandler must have a parent handler");
|
|
14
|
+
}
|
|
15
|
+
const { object, property } = node;
|
|
16
|
+
let prop;
|
|
17
|
+
if (ASTParser.isIdentifier(property)) {
|
|
18
|
+
prop = property.name.replace(/^["'](.+(?=["']$))["']$/, "$1");
|
|
19
|
+
}
|
|
20
|
+
else if (ASTParser.isStringLiteral(property)) {
|
|
21
|
+
prop = `${property.value}`.replace(/^["'](.+(?=["']$))["']$/, "$1");
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error("Invalid property key type");
|
|
25
|
+
}
|
|
26
|
+
let identifier;
|
|
27
|
+
if (ASTParser.isIdentifier(object)) {
|
|
28
|
+
identifier = object.name.replace(/^["'](.+(?=["']$))["']$/, "$1");
|
|
29
|
+
}
|
|
30
|
+
else if (ASTParser.isLiteral(object)) {
|
|
31
|
+
identifier = `${object.value}`.replace(/^["'](.+(?=["']$))["']$/, "$1");
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
throw new Error("Invalid object type");
|
|
35
|
+
}
|
|
36
|
+
if (object.type !== "Identifier" && object.type !== "Literal") {
|
|
37
|
+
throw new Error("ArrayExpression is not supported");
|
|
38
|
+
}
|
|
39
|
+
return { type: "member_expression", identifier, property: prop };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumericLiteralHandler = void 0;
|
|
4
|
+
const base_js_1 = require("./base.cjs");
|
|
5
|
+
class NumericLiteralHandler extends base_js_1.NodeHandler {
|
|
6
|
+
async accepts(node) {
|
|
7
|
+
if (base_js_1.ASTParser.isNumericLiteral(node)) {
|
|
8
|
+
return node;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async handle(node) {
|
|
15
|
+
if (!this.parentHandler) {
|
|
16
|
+
throw new Error("ArrayLiteralExpressionHandler must have a parent handler");
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
type: "numeric_literal",
|
|
20
|
+
value: Number(node.value),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.NumericLiteralHandler = NumericLiteralHandler;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ESTree } from "meriyah";
|
|
2
|
+
import { NodeHandler } from "./base.js";
|
|
3
|
+
import { NumericLiteralType } from "./types.js";
|
|
4
|
+
export declare class NumericLiteralHandler extends NodeHandler {
|
|
5
|
+
accepts(node: ESTree.Node): Promise<ESTree.Literal | boolean>;
|
|
6
|
+
handle(node: ESTree.Literal): Promise<NumericLiteralType>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NodeHandler, ASTParser } from "./base.js";
|
|
2
|
+
export class NumericLiteralHandler extends NodeHandler {
|
|
3
|
+
async accepts(node) {
|
|
4
|
+
if (ASTParser.isNumericLiteral(node)) {
|
|
5
|
+
return node;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
async handle(node) {
|
|
12
|
+
if (!this.parentHandler) {
|
|
13
|
+
throw new Error("ArrayLiteralExpressionHandler must have a parent handler");
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
type: "numeric_literal",
|
|
17
|
+
value: Number(node.value),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObjectLiteralExpressionHandler = void 0;
|
|
4
|
+
const base_js_1 = require("./base.cjs");
|
|
5
|
+
const property_assignment_handler_js_1 = require("./property_assignment_handler.cjs");
|
|
6
|
+
class ObjectLiteralExpressionHandler extends base_js_1.NodeHandler {
|
|
7
|
+
async accepts(node) {
|
|
8
|
+
if (base_js_1.ASTParser.isObjectExpression(node)) {
|
|
9
|
+
return node;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async handle(node) {
|
|
16
|
+
if (!this.parentHandler) {
|
|
17
|
+
throw new Error("ArrayLiteralExpressionHandler must have a parent handler");
|
|
18
|
+
}
|
|
19
|
+
const values = [];
|
|
20
|
+
const { properties } = node;
|
|
21
|
+
for (const property of properties) {
|
|
22
|
+
if (base_js_1.ASTParser.isProperty(property)) {
|
|
23
|
+
values.push(await new property_assignment_handler_js_1.PropertyAssignmentHandler(this.parentHandler).handle(property));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { type: "object_literal", values };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ObjectLiteralExpressionHandler = ObjectLiteralExpressionHandler;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ESTree } from "meriyah";
|
|
2
|
+
import { NodeHandler } from "./base.js";
|
|
3
|
+
import { ObjectLiteralType } from "./types.js";
|
|
4
|
+
export declare class ObjectLiteralExpressionHandler extends NodeHandler {
|
|
5
|
+
accepts(node: ESTree.Node): Promise<ESTree.ObjectExpression | boolean>;
|
|
6
|
+
handle(node: ESTree.ObjectExpression): Promise<ObjectLiteralType>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { NodeHandler, ASTParser } from "./base.js";
|
|
2
|
+
import { PropertyAssignmentHandler } from "./property_assignment_handler.js";
|
|
3
|
+
export class ObjectLiteralExpressionHandler extends NodeHandler {
|
|
4
|
+
async accepts(node) {
|
|
5
|
+
if (ASTParser.isObjectExpression(node)) {
|
|
6
|
+
return node;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
async handle(node) {
|
|
13
|
+
if (!this.parentHandler) {
|
|
14
|
+
throw new Error("ArrayLiteralExpressionHandler must have a parent handler");
|
|
15
|
+
}
|
|
16
|
+
const values = [];
|
|
17
|
+
const { properties } = node;
|
|
18
|
+
for (const property of properties) {
|
|
19
|
+
if (ASTParser.isProperty(property)) {
|
|
20
|
+
values.push(await new PropertyAssignmentHandler(this.parentHandler).handle(property));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return { type: "object_literal", values };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PropertyAssignmentHandler = void 0;
|
|
4
|
+
const base_js_1 = require("./base.cjs");
|
|
5
|
+
class PropertyAssignmentHandler extends base_js_1.NodeHandler {
|
|
6
|
+
async accepts(node) {
|
|
7
|
+
if (base_js_1.ASTParser.isProperty(node)) {
|
|
8
|
+
return node;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async handle(node) {
|
|
15
|
+
if (!this.parentHandler) {
|
|
16
|
+
throw new Error("ArrayLiteralExpressionHandler must have a parent handler");
|
|
17
|
+
}
|
|
18
|
+
let name;
|
|
19
|
+
if (base_js_1.ASTParser.isIdentifier(node.key)) {
|
|
20
|
+
name = node.key.name;
|
|
21
|
+
}
|
|
22
|
+
else if (base_js_1.ASTParser.isStringLiteral(node.key)) {
|
|
23
|
+
name = node.key.value;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new Error("Invalid property key type");
|
|
27
|
+
}
|
|
28
|
+
if (!name) {
|
|
29
|
+
throw new Error("Invalid property key");
|
|
30
|
+
}
|
|
31
|
+
const identifier = `${name}`.replace(/^["'](.+(?=["']$))["']$/, "$1");
|
|
32
|
+
const value = await this.parentHandler.handle(node.value);
|
|
33
|
+
return { type: "property_assignment", identifier, value };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.PropertyAssignmentHandler = PropertyAssignmentHandler;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ESTree } from "meriyah";
|
|
2
|
+
import { NodeHandler } from "./base.js";
|
|
3
|
+
import { PropertyAssignmentType } from "./types.js";
|
|
4
|
+
export declare class PropertyAssignmentHandler extends NodeHandler {
|
|
5
|
+
accepts(node: ESTree.Node): Promise<ESTree.Property | boolean>;
|
|
6
|
+
handle(node: ESTree.Property): Promise<PropertyAssignmentType>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { NodeHandler, ASTParser } from "./base.js";
|
|
2
|
+
export class PropertyAssignmentHandler extends NodeHandler {
|
|
3
|
+
async accepts(node) {
|
|
4
|
+
if (ASTParser.isProperty(node)) {
|
|
5
|
+
return node;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
async handle(node) {
|
|
12
|
+
if (!this.parentHandler) {
|
|
13
|
+
throw new Error("ArrayLiteralExpressionHandler must have a parent handler");
|
|
14
|
+
}
|
|
15
|
+
let name;
|
|
16
|
+
if (ASTParser.isIdentifier(node.key)) {
|
|
17
|
+
name = node.key.name;
|
|
18
|
+
}
|
|
19
|
+
else if (ASTParser.isStringLiteral(node.key)) {
|
|
20
|
+
name = node.key.value;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new Error("Invalid property key type");
|
|
24
|
+
}
|
|
25
|
+
if (!name) {
|
|
26
|
+
throw new Error("Invalid property key");
|
|
27
|
+
}
|
|
28
|
+
const identifier = `${name}`.replace(/^["'](.+(?=["']$))["']$/, "$1");
|
|
29
|
+
const value = await this.parentHandler.handle(node.value);
|
|
30
|
+
return { type: "property_assignment", identifier, value };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringLiteralHandler = void 0;
|
|
4
|
+
const base_js_1 = require("./base.cjs");
|
|
5
|
+
class StringLiteralHandler extends base_js_1.NodeHandler {
|
|
6
|
+
async accepts(node) {
|
|
7
|
+
if (base_js_1.ASTParser.isStringLiteral(node)) {
|
|
8
|
+
return node;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async handle(node) {
|
|
15
|
+
if (!this.parentHandler) {
|
|
16
|
+
throw new Error("ArrayLiteralExpressionHandler must have a parent handler");
|
|
17
|
+
}
|
|
18
|
+
const text = `${node.value}`.replace(/^["'](.+(?=["']$))["']$/, "$1");
|
|
19
|
+
return { type: "string_literal", value: text };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.StringLiteralHandler = StringLiteralHandler;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ESTree } from "meriyah";
|
|
2
|
+
import { NodeHandler } from "./base.js";
|
|
3
|
+
import { StringLiteralType } from "./types.js";
|
|
4
|
+
export declare class StringLiteralHandler extends NodeHandler {
|
|
5
|
+
accepts(node: ESTree.Node): Promise<ESTree.Literal | boolean>;
|
|
6
|
+
handle(node: ESTree.Literal): Promise<StringLiteralType>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NodeHandler, ASTParser } from "./base.js";
|
|
2
|
+
export class StringLiteralHandler extends NodeHandler {
|
|
3
|
+
async accepts(node) {
|
|
4
|
+
if (ASTParser.isStringLiteral(node)) {
|
|
5
|
+
return node;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
async handle(node) {
|
|
12
|
+
if (!this.parentHandler) {
|
|
13
|
+
throw new Error("ArrayLiteralExpressionHandler must have a parent handler");
|
|
14
|
+
}
|
|
15
|
+
const text = `${node.value}`.replace(/^["'](.+(?=["']$))["']$/, "$1");
|
|
16
|
+
return { type: "string_literal", value: text };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type ArgumentsType = IdentifierType | StringLiteralType | NumericLiteralType | ArrayLiteralType | ObjectLiteralType | CallExpressionType | BooleanLiteralType;
|
|
2
|
+
export type ParsedType = ArgumentsType | PropertyAssignmentType;
|
|
3
|
+
export type ArrayLiteralType = {
|
|
4
|
+
type: "array_literal";
|
|
5
|
+
values: ArgumentsType[];
|
|
6
|
+
};
|
|
7
|
+
export type BooleanLiteralType = {
|
|
8
|
+
type: "boolean_literal";
|
|
9
|
+
value: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type CallExpressionType = {
|
|
12
|
+
type: "call_expression";
|
|
13
|
+
funcCall: string | MemberExpressionType;
|
|
14
|
+
args?: ArgumentsType[];
|
|
15
|
+
};
|
|
16
|
+
export type NumericLiteralType = {
|
|
17
|
+
type: "numeric_literal";
|
|
18
|
+
value: number;
|
|
19
|
+
};
|
|
20
|
+
export type ObjectLiteralType = {
|
|
21
|
+
type: "object_literal";
|
|
22
|
+
values: PropertyAssignmentType[];
|
|
23
|
+
};
|
|
24
|
+
export type MemberExpressionType = {
|
|
25
|
+
type: "member_expression";
|
|
26
|
+
identifier: string;
|
|
27
|
+
property: string;
|
|
28
|
+
};
|
|
29
|
+
export type PropertyAssignmentType = {
|
|
30
|
+
type: "property_assignment";
|
|
31
|
+
identifier: string;
|
|
32
|
+
value: ArgumentsType;
|
|
33
|
+
};
|
|
34
|
+
export type StringLiteralType = {
|
|
35
|
+
type: "string_literal";
|
|
36
|
+
value: string;
|
|
37
|
+
};
|
|
38
|
+
export type IdentifierType = {
|
|
39
|
+
type: "identifier";
|
|
40
|
+
value: string;
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CustomListOutputParser = exports.RouterOutputParser = exports.CombiningOutputParser = exports.OutputFixingParser = exports.JsonMarkdownStructuredOutputParser = exports.StructuredOutputParser = exports.RegexParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
|
|
3
|
+
exports.CustomListOutputParser = exports.RouterOutputParser = exports.CombiningOutputParser = exports.OutputFixingParser = exports.JsonMarkdownStructuredOutputParser = exports.AsymmetricStructuredOutputParser = exports.StructuredOutputParser = exports.RegexParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
|
|
4
4
|
var list_js_1 = require("./list.cjs");
|
|
5
5
|
Object.defineProperty(exports, "ListOutputParser", { enumerable: true, get: function () { return list_js_1.ListOutputParser; } });
|
|
6
6
|
Object.defineProperty(exports, "CommaSeparatedListOutputParser", { enumerable: true, get: function () { return list_js_1.CommaSeparatedListOutputParser; } });
|
|
@@ -8,6 +8,7 @@ var regex_js_1 = require("./regex.cjs");
|
|
|
8
8
|
Object.defineProperty(exports, "RegexParser", { enumerable: true, get: function () { return regex_js_1.RegexParser; } });
|
|
9
9
|
var structured_js_1 = require("./structured.cjs");
|
|
10
10
|
Object.defineProperty(exports, "StructuredOutputParser", { enumerable: true, get: function () { return structured_js_1.StructuredOutputParser; } });
|
|
11
|
+
Object.defineProperty(exports, "AsymmetricStructuredOutputParser", { enumerable: true, get: function () { return structured_js_1.AsymmetricStructuredOutputParser; } });
|
|
11
12
|
Object.defineProperty(exports, "JsonMarkdownStructuredOutputParser", { enumerable: true, get: function () { return structured_js_1.JsonMarkdownStructuredOutputParser; } });
|
|
12
13
|
var fix_js_1 = require("./fix.cjs");
|
|
13
14
|
Object.defineProperty(exports, "OutputFixingParser", { enumerable: true, get: function () { return fix_js_1.OutputFixingParser; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { ListOutputParser, CommaSeparatedListOutputParser } from "./list.js";
|
|
2
2
|
export { RegexParser } from "./regex.js";
|
|
3
|
-
export { StructuredOutputParser, JsonMarkdownStructuredOutputParser, JsonMarkdownFormatInstructionsOptions, JsonMarkdownStructuredOutputParserInput, } from "./structured.js";
|
|
3
|
+
export { StructuredOutputParser, AsymmetricStructuredOutputParser, JsonMarkdownStructuredOutputParser, JsonMarkdownFormatInstructionsOptions, JsonMarkdownStructuredOutputParserInput, } from "./structured.js";
|
|
4
4
|
export { OutputFixingParser } from "./fix.js";
|
|
5
5
|
export { CombiningOutputParser } from "./combining.js";
|
|
6
6
|
export { RouterOutputParser, RouterOutputParserInput } from "./router.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { ListOutputParser, CommaSeparatedListOutputParser } from "./list.js";
|
|
2
2
|
export { RegexParser } from "./regex.js";
|
|
3
|
-
export { StructuredOutputParser, JsonMarkdownStructuredOutputParser, } from "./structured.js";
|
|
3
|
+
export { StructuredOutputParser, AsymmetricStructuredOutputParser, JsonMarkdownStructuredOutputParser, } from "./structured.js";
|
|
4
4
|
export { OutputFixingParser } from "./fix.js";
|
|
5
5
|
export { CombiningOutputParser } from "./combining.js";
|
|
6
6
|
export { RouterOutputParser } from "./router.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JsonMarkdownStructuredOutputParser = exports.StructuredOutputParser = void 0;
|
|
3
|
+
exports.AsymmetricStructuredOutputParser = exports.JsonMarkdownStructuredOutputParser = exports.StructuredOutputParser = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
6
6
|
const output_parser_js_1 = require("../schema/output_parser.cjs");
|
|
@@ -63,31 +63,89 @@ class JsonMarkdownStructuredOutputParser extends StructuredOutputParser {
|
|
|
63
63
|
}
|
|
64
64
|
_schemaToInstruction(schemaInput, indent = 2) {
|
|
65
65
|
const schema = schemaInput;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
if ("type" in schema) {
|
|
67
|
+
let nullable = false;
|
|
68
|
+
let type;
|
|
69
|
+
if (Array.isArray(schema.type)) {
|
|
70
|
+
const nullIdx = schema.type.findIndex((type) => type === "null");
|
|
71
|
+
if (nullIdx !== -1) {
|
|
72
|
+
nullable = true;
|
|
73
|
+
schema.type.splice(nullIdx, 1);
|
|
74
|
+
}
|
|
75
|
+
type = schema.type.join(" | ");
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
type = schema.type;
|
|
79
|
+
}
|
|
80
|
+
if (schema.type === "object" && schema.properties) {
|
|
81
|
+
const description = schema.description
|
|
82
|
+
? ` // ${schema.description}`
|
|
83
|
+
: "";
|
|
84
|
+
const properties = Object.entries(schema.properties)
|
|
85
|
+
.map(([key, value]) => {
|
|
86
|
+
const isOptional = schema.required?.includes(key)
|
|
87
|
+
? ""
|
|
88
|
+
: " (optional)";
|
|
89
|
+
return `${" ".repeat(indent)}"${key}": ${this._schemaToInstruction(value, indent + 2)}${isOptional}`;
|
|
90
|
+
})
|
|
91
|
+
.join("\n");
|
|
92
|
+
return `{\n${properties}\n${" ".repeat(indent - 2)}}${description}`;
|
|
93
|
+
}
|
|
94
|
+
if (schema.type === "array" && schema.items) {
|
|
95
|
+
const description = schema.description
|
|
96
|
+
? ` // ${schema.description}`
|
|
97
|
+
: "";
|
|
98
|
+
return `array[\n${" ".repeat(indent)}${this._schemaToInstruction(schema.items, indent + 2)}\n${" ".repeat(indent - 2)}] ${description}`;
|
|
99
|
+
}
|
|
100
|
+
const isNullable = nullable ? " (nullable)" : "";
|
|
73
101
|
const description = schema.description ? ` // ${schema.description}` : "";
|
|
74
|
-
|
|
75
|
-
.map(([key, value]) => {
|
|
76
|
-
const isOptional = schema.required?.includes(key)
|
|
77
|
-
? ""
|
|
78
|
-
: " (optional)";
|
|
79
|
-
return `${" ".repeat(indent)}"${key}": ${this._schemaToInstruction(value, indent + 2)}${isOptional}`;
|
|
80
|
-
})
|
|
81
|
-
.join("\n");
|
|
82
|
-
return `{\n${properties}\n${" ".repeat(indent - 2)}}${description}`;
|
|
102
|
+
return `${type}${description}${isNullable}`;
|
|
83
103
|
}
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
104
|
+
if ("anyOf" in schema) {
|
|
105
|
+
return schema.anyOf
|
|
106
|
+
.map((s) => this._schemaToInstruction(s, indent))
|
|
107
|
+
.join(`\n${" ".repeat(indent - 2)}`);
|
|
87
108
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
109
|
+
throw new Error("unsupported schema type");
|
|
110
|
+
}
|
|
111
|
+
static fromZodSchema(schema) {
|
|
112
|
+
return new this(schema);
|
|
113
|
+
}
|
|
114
|
+
static fromNamesAndDescriptions(schemas) {
|
|
115
|
+
const zodSchema = zod_1.z.object(Object.fromEntries(Object.entries(schemas).map(([name, description]) => [name, zod_1.z.string().describe(description)])));
|
|
116
|
+
return new this(zodSchema);
|
|
91
117
|
}
|
|
92
118
|
}
|
|
93
119
|
exports.JsonMarkdownStructuredOutputParser = JsonMarkdownStructuredOutputParser;
|
|
120
|
+
class AsymmetricStructuredOutputParser extends output_parser_js_1.BaseOutputParser {
|
|
121
|
+
constructor(inputSchema) {
|
|
122
|
+
super();
|
|
123
|
+
Object.defineProperty(this, "inputSchema", {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
configurable: true,
|
|
126
|
+
writable: true,
|
|
127
|
+
value: inputSchema
|
|
128
|
+
});
|
|
129
|
+
Object.defineProperty(this, "structuredInputParser", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
configurable: true,
|
|
132
|
+
writable: true,
|
|
133
|
+
value: void 0
|
|
134
|
+
});
|
|
135
|
+
this.structuredInputParser = new JsonMarkdownStructuredOutputParser(inputSchema);
|
|
136
|
+
}
|
|
137
|
+
async parse(text) {
|
|
138
|
+
let parsedInput;
|
|
139
|
+
try {
|
|
140
|
+
parsedInput = await this.structuredInputParser.parse(text);
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
throw new output_parser_js_1.OutputParserException(`Failed to parse. Text: "${text}". Error: ${e}`, text);
|
|
144
|
+
}
|
|
145
|
+
return this.outputProcessor(parsedInput);
|
|
146
|
+
}
|
|
147
|
+
getFormatInstructions() {
|
|
148
|
+
return this.structuredInputParser.getFormatInstructions();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.AsymmetricStructuredOutputParser = AsymmetricStructuredOutputParser;
|
|
@@ -25,4 +25,22 @@ export declare class StructuredOutputParser<T extends z.ZodTypeAny> extends Base
|
|
|
25
25
|
export declare class JsonMarkdownStructuredOutputParser<T extends z.ZodTypeAny> extends StructuredOutputParser<T> {
|
|
26
26
|
getFormatInstructions(options?: JsonMarkdownFormatInstructionsOptions): string;
|
|
27
27
|
private _schemaToInstruction;
|
|
28
|
+
static fromZodSchema<T extends z.ZodTypeAny>(schema: T): JsonMarkdownStructuredOutputParser<T>;
|
|
29
|
+
static fromNamesAndDescriptions<S extends {
|
|
30
|
+
[key: string]: string;
|
|
31
|
+
}>(schemas: S): JsonMarkdownStructuredOutputParser<z.ZodObject<{
|
|
32
|
+
[k: string]: z.ZodString;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
[x: string]: string;
|
|
35
|
+
}, {
|
|
36
|
+
[x: string]: string;
|
|
37
|
+
}>>;
|
|
38
|
+
}
|
|
39
|
+
export declare abstract class AsymmetricStructuredOutputParser<T extends z.ZodTypeAny, Y = unknown> extends BaseOutputParser<Y> {
|
|
40
|
+
inputSchema: T;
|
|
41
|
+
private structuredInputParser;
|
|
42
|
+
constructor(inputSchema: T);
|
|
43
|
+
abstract outputProcessor(input: z.infer<T>): Promise<Y>;
|
|
44
|
+
parse(text: string): Promise<Y>;
|
|
45
|
+
getFormatInstructions(): string;
|
|
28
46
|
}
|