@langchain/core 0.1.59 → 0.1.60
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/chat_history.cjs +49 -1
- package/dist/chat_history.d.ts +27 -0
- package/dist/chat_history.js +47 -0
- package/dist/stores.cjs +81 -1
- package/dist/stores.d.ts +48 -0
- package/dist/stores.js +79 -0
- package/dist/structured_query/base.cjs +139 -0
- package/dist/structured_query/base.d.ts +69 -0
- package/dist/structured_query/base.js +134 -0
- package/dist/structured_query/functional.cjs +198 -0
- package/dist/structured_query/functional.d.ts +87 -0
- package/dist/structured_query/functional.js +194 -0
- package/dist/structured_query/index.cjs +20 -0
- package/dist/structured_query/index.d.ts +4 -0
- package/dist/structured_query/index.js +4 -0
- package/dist/structured_query/ir.cjs +141 -0
- package/dist/structured_query/ir.d.ts +138 -0
- package/dist/structured_query/ir.js +132 -0
- package/dist/structured_query/utils.cjs +94 -0
- package/dist/structured_query/utils.d.ts +29 -0
- package/dist/structured_query/utils.js +85 -0
- package/dist/tools.cjs +12 -1
- package/dist/tools.d.ts +9 -0
- package/dist/tools.js +10 -0
- package/package.json +14 -1
- package/structured_query.cjs +1 -0
- package/structured_query.d.cts +1 -0
- package/structured_query.d.ts +1 -0
- package/structured_query.js +1 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StructuredQuery = exports.Operation = exports.Comparison = exports.FilterDirective = exports.Expression = exports.Visitor = exports.Comparators = exports.Operators = void 0;
|
|
4
|
+
exports.Operators = {
|
|
5
|
+
and: "and",
|
|
6
|
+
or: "or",
|
|
7
|
+
not: "not",
|
|
8
|
+
};
|
|
9
|
+
exports.Comparators = {
|
|
10
|
+
eq: "eq",
|
|
11
|
+
ne: "ne",
|
|
12
|
+
lt: "lt",
|
|
13
|
+
gt: "gt",
|
|
14
|
+
lte: "lte",
|
|
15
|
+
gte: "gte",
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Abstract class for visiting expressions. Subclasses must implement
|
|
19
|
+
* visitOperation, visitComparison, and visitStructuredQuery methods.
|
|
20
|
+
*/
|
|
21
|
+
class Visitor {
|
|
22
|
+
}
|
|
23
|
+
exports.Visitor = Visitor;
|
|
24
|
+
/**
|
|
25
|
+
* Abstract class representing an expression. Subclasses must implement
|
|
26
|
+
* the exprName property and the accept method.
|
|
27
|
+
*/
|
|
28
|
+
class Expression {
|
|
29
|
+
accept(visitor) {
|
|
30
|
+
if (this.exprName === "Operation") {
|
|
31
|
+
return visitor.visitOperation(this);
|
|
32
|
+
}
|
|
33
|
+
else if (this.exprName === "Comparison") {
|
|
34
|
+
return visitor.visitComparison(this);
|
|
35
|
+
}
|
|
36
|
+
else if (this.exprName === "StructuredQuery") {
|
|
37
|
+
return visitor.visitStructuredQuery(this);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw new Error("Unknown Expression type");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.Expression = Expression;
|
|
45
|
+
/**
|
|
46
|
+
* Abstract class representing a filter directive. It extends the
|
|
47
|
+
* Expression class.
|
|
48
|
+
*/
|
|
49
|
+
class FilterDirective extends Expression {
|
|
50
|
+
}
|
|
51
|
+
exports.FilterDirective = FilterDirective;
|
|
52
|
+
/**
|
|
53
|
+
* Class representing a comparison filter directive. It extends the
|
|
54
|
+
* FilterDirective class.
|
|
55
|
+
*/
|
|
56
|
+
class Comparison extends FilterDirective {
|
|
57
|
+
constructor(comparator, attribute, value) {
|
|
58
|
+
super();
|
|
59
|
+
Object.defineProperty(this, "comparator", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: comparator
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(this, "attribute", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: attribute
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(this, "value", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
configurable: true,
|
|
74
|
+
writable: true,
|
|
75
|
+
value: value
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(this, "exprName", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: "Comparison"
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.Comparison = Comparison;
|
|
86
|
+
/**
|
|
87
|
+
* Class representing an operation filter directive. It extends the
|
|
88
|
+
* FilterDirective class.
|
|
89
|
+
*/
|
|
90
|
+
class Operation extends FilterDirective {
|
|
91
|
+
constructor(operator, args) {
|
|
92
|
+
super();
|
|
93
|
+
Object.defineProperty(this, "operator", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
configurable: true,
|
|
96
|
+
writable: true,
|
|
97
|
+
value: operator
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(this, "args", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
configurable: true,
|
|
102
|
+
writable: true,
|
|
103
|
+
value: args
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(this, "exprName", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
configurable: true,
|
|
108
|
+
writable: true,
|
|
109
|
+
value: "Operation"
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.Operation = Operation;
|
|
114
|
+
/**
|
|
115
|
+
* Class representing a structured query expression. It extends the
|
|
116
|
+
* Expression class.
|
|
117
|
+
*/
|
|
118
|
+
class StructuredQuery extends Expression {
|
|
119
|
+
constructor(query, filter) {
|
|
120
|
+
super();
|
|
121
|
+
Object.defineProperty(this, "query", {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
configurable: true,
|
|
124
|
+
writable: true,
|
|
125
|
+
value: query
|
|
126
|
+
});
|
|
127
|
+
Object.defineProperty(this, "filter", {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
configurable: true,
|
|
130
|
+
writable: true,
|
|
131
|
+
value: filter
|
|
132
|
+
});
|
|
133
|
+
Object.defineProperty(this, "exprName", {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
configurable: true,
|
|
136
|
+
writable: true,
|
|
137
|
+
value: "StructuredQuery"
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.StructuredQuery = StructuredQuery;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { VectorStore } from "../vectorstores.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents logical AND operator.
|
|
4
|
+
*/
|
|
5
|
+
export type AND = "and";
|
|
6
|
+
/**
|
|
7
|
+
* Represents logical OR operator.
|
|
8
|
+
*/
|
|
9
|
+
export type OR = "or";
|
|
10
|
+
/**
|
|
11
|
+
* Represents logical NOT operator.
|
|
12
|
+
*/
|
|
13
|
+
export type NOT = "not";
|
|
14
|
+
/**
|
|
15
|
+
* Represents a logical operator which can be AND, OR, or NOT.
|
|
16
|
+
*/
|
|
17
|
+
export type Operator = AND | OR | NOT;
|
|
18
|
+
/**
|
|
19
|
+
* Represents equality comparison operator.
|
|
20
|
+
*/
|
|
21
|
+
export type EQ = "eq";
|
|
22
|
+
/**
|
|
23
|
+
* Represents inequality comparison operator.
|
|
24
|
+
*/
|
|
25
|
+
export type NE = "ne";
|
|
26
|
+
/**
|
|
27
|
+
* Represents less than comparison operator.
|
|
28
|
+
*/
|
|
29
|
+
export type LT = "lt";
|
|
30
|
+
/**
|
|
31
|
+
* Represents greater than comparison operator.
|
|
32
|
+
*/
|
|
33
|
+
export type GT = "gt";
|
|
34
|
+
/**
|
|
35
|
+
* Represents less than or equal to comparison operator.
|
|
36
|
+
*/
|
|
37
|
+
export type LTE = "lte";
|
|
38
|
+
/**
|
|
39
|
+
* Represents greater than or equal to comparison operator.
|
|
40
|
+
*/
|
|
41
|
+
export type GTE = "gte";
|
|
42
|
+
/**
|
|
43
|
+
* Represents a comparison operator which can be EQ, NE, LT, GT, LTE, or
|
|
44
|
+
* GTE.
|
|
45
|
+
*/
|
|
46
|
+
export type Comparator = EQ | NE | LT | GT | LTE | GTE;
|
|
47
|
+
export declare const Operators: {
|
|
48
|
+
[key: string]: Operator;
|
|
49
|
+
};
|
|
50
|
+
export declare const Comparators: {
|
|
51
|
+
[key: string]: Comparator;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Represents the result of visiting an operation or comparison
|
|
55
|
+
* expression.
|
|
56
|
+
*/
|
|
57
|
+
export type VisitorResult = VisitorOperationResult | VisitorComparisonResult;
|
|
58
|
+
/**
|
|
59
|
+
* Represents the result of visiting an operation expression.
|
|
60
|
+
*/
|
|
61
|
+
export type VisitorOperationResult = {
|
|
62
|
+
[operator: string]: VisitorResult[];
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Represents the result of visiting a comparison expression.
|
|
66
|
+
*/
|
|
67
|
+
export type VisitorComparisonResult = {
|
|
68
|
+
[attr: string]: {
|
|
69
|
+
[comparator: string]: string | number;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Represents the result of visiting a structured query expression.
|
|
74
|
+
*/
|
|
75
|
+
export type VisitorStructuredQueryResult = {
|
|
76
|
+
filter?: VisitorComparisonResult | VisitorOperationResult;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Abstract class for visiting expressions. Subclasses must implement
|
|
80
|
+
* visitOperation, visitComparison, and visitStructuredQuery methods.
|
|
81
|
+
*/
|
|
82
|
+
export declare abstract class Visitor<T extends VectorStore = VectorStore> {
|
|
83
|
+
VisitOperationOutput: object;
|
|
84
|
+
VisitComparisonOutput: object;
|
|
85
|
+
VisitStructuredQueryOutput: {
|
|
86
|
+
filter?: T["FilterType"];
|
|
87
|
+
};
|
|
88
|
+
abstract allowedOperators: Operator[];
|
|
89
|
+
abstract allowedComparators: Comparator[];
|
|
90
|
+
abstract visitOperation(operation: Operation): this["VisitOperationOutput"];
|
|
91
|
+
abstract visitComparison(comparison: Comparison): this["VisitComparisonOutput"];
|
|
92
|
+
abstract visitStructuredQuery(structuredQuery: StructuredQuery): this["VisitStructuredQueryOutput"];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Abstract class representing an expression. Subclasses must implement
|
|
96
|
+
* the exprName property and the accept method.
|
|
97
|
+
*/
|
|
98
|
+
export declare abstract class Expression {
|
|
99
|
+
abstract exprName: "Operation" | "Comparison" | "StructuredQuery";
|
|
100
|
+
accept(visitor: Visitor): object;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Abstract class representing a filter directive. It extends the
|
|
104
|
+
* Expression class.
|
|
105
|
+
*/
|
|
106
|
+
export declare abstract class FilterDirective extends Expression {
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Class representing a comparison filter directive. It extends the
|
|
110
|
+
* FilterDirective class.
|
|
111
|
+
*/
|
|
112
|
+
export declare class Comparison extends FilterDirective {
|
|
113
|
+
comparator: Comparator;
|
|
114
|
+
attribute: string;
|
|
115
|
+
value: string | number;
|
|
116
|
+
exprName: "Comparison";
|
|
117
|
+
constructor(comparator: Comparator, attribute: string, value: string | number);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Class representing an operation filter directive. It extends the
|
|
121
|
+
* FilterDirective class.
|
|
122
|
+
*/
|
|
123
|
+
export declare class Operation extends FilterDirective {
|
|
124
|
+
operator: Operator;
|
|
125
|
+
args?: FilterDirective[] | undefined;
|
|
126
|
+
exprName: "Operation";
|
|
127
|
+
constructor(operator: Operator, args?: FilterDirective[] | undefined);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Class representing a structured query expression. It extends the
|
|
131
|
+
* Expression class.
|
|
132
|
+
*/
|
|
133
|
+
export declare class StructuredQuery extends Expression {
|
|
134
|
+
query: string;
|
|
135
|
+
filter?: FilterDirective | undefined;
|
|
136
|
+
exprName: "StructuredQuery";
|
|
137
|
+
constructor(query: string, filter?: FilterDirective | undefined);
|
|
138
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export const Operators = {
|
|
2
|
+
and: "and",
|
|
3
|
+
or: "or",
|
|
4
|
+
not: "not",
|
|
5
|
+
};
|
|
6
|
+
export const Comparators = {
|
|
7
|
+
eq: "eq",
|
|
8
|
+
ne: "ne",
|
|
9
|
+
lt: "lt",
|
|
10
|
+
gt: "gt",
|
|
11
|
+
lte: "lte",
|
|
12
|
+
gte: "gte",
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Abstract class for visiting expressions. Subclasses must implement
|
|
16
|
+
* visitOperation, visitComparison, and visitStructuredQuery methods.
|
|
17
|
+
*/
|
|
18
|
+
export class Visitor {
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Abstract class representing an expression. Subclasses must implement
|
|
22
|
+
* the exprName property and the accept method.
|
|
23
|
+
*/
|
|
24
|
+
export class Expression {
|
|
25
|
+
accept(visitor) {
|
|
26
|
+
if (this.exprName === "Operation") {
|
|
27
|
+
return visitor.visitOperation(this);
|
|
28
|
+
}
|
|
29
|
+
else if (this.exprName === "Comparison") {
|
|
30
|
+
return visitor.visitComparison(this);
|
|
31
|
+
}
|
|
32
|
+
else if (this.exprName === "StructuredQuery") {
|
|
33
|
+
return visitor.visitStructuredQuery(this);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
throw new Error("Unknown Expression type");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Abstract class representing a filter directive. It extends the
|
|
42
|
+
* Expression class.
|
|
43
|
+
*/
|
|
44
|
+
export class FilterDirective extends Expression {
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Class representing a comparison filter directive. It extends the
|
|
48
|
+
* FilterDirective class.
|
|
49
|
+
*/
|
|
50
|
+
export class Comparison extends FilterDirective {
|
|
51
|
+
constructor(comparator, attribute, value) {
|
|
52
|
+
super();
|
|
53
|
+
Object.defineProperty(this, "comparator", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: comparator
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(this, "attribute", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: attribute
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(this, "value", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: value
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(this, "exprName", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
configurable: true,
|
|
74
|
+
writable: true,
|
|
75
|
+
value: "Comparison"
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Class representing an operation filter directive. It extends the
|
|
81
|
+
* FilterDirective class.
|
|
82
|
+
*/
|
|
83
|
+
export class Operation extends FilterDirective {
|
|
84
|
+
constructor(operator, args) {
|
|
85
|
+
super();
|
|
86
|
+
Object.defineProperty(this, "operator", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
configurable: true,
|
|
89
|
+
writable: true,
|
|
90
|
+
value: operator
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(this, "args", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
configurable: true,
|
|
95
|
+
writable: true,
|
|
96
|
+
value: args
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(this, "exprName", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
configurable: true,
|
|
101
|
+
writable: true,
|
|
102
|
+
value: "Operation"
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Class representing a structured query expression. It extends the
|
|
108
|
+
* Expression class.
|
|
109
|
+
*/
|
|
110
|
+
export class StructuredQuery extends Expression {
|
|
111
|
+
constructor(query, filter) {
|
|
112
|
+
super();
|
|
113
|
+
Object.defineProperty(this, "query", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: query
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(this, "filter", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
configurable: true,
|
|
122
|
+
writable: true,
|
|
123
|
+
value: filter
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(this, "exprName", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
configurable: true,
|
|
128
|
+
writable: true,
|
|
129
|
+
value: "StructuredQuery"
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.castValue = exports.isString = exports.isFloat = exports.isInt = exports.isFilterEmpty = exports.isObject = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the provided argument is an object and not an array.
|
|
6
|
+
*/
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
function isObject(obj) {
|
|
9
|
+
return obj && typeof obj === "object" && !Array.isArray(obj);
|
|
10
|
+
}
|
|
11
|
+
exports.isObject = isObject;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a provided filter is empty. The filter can be a function, an
|
|
14
|
+
* object, a string, or undefined.
|
|
15
|
+
*/
|
|
16
|
+
function isFilterEmpty(
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
filter) {
|
|
19
|
+
if (!filter)
|
|
20
|
+
return true;
|
|
21
|
+
// for Milvus
|
|
22
|
+
if (typeof filter === "string" && filter.length > 0) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (typeof filter === "function") {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return isObject(filter) && Object.keys(filter).length === 0;
|
|
29
|
+
}
|
|
30
|
+
exports.isFilterEmpty = isFilterEmpty;
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the provided value is an integer.
|
|
33
|
+
*/
|
|
34
|
+
function isInt(value) {
|
|
35
|
+
if (typeof value === "number") {
|
|
36
|
+
return value % 1 === 0;
|
|
37
|
+
}
|
|
38
|
+
else if (typeof value === "string") {
|
|
39
|
+
const numberValue = parseInt(value, 10);
|
|
40
|
+
return (!Number.isNaN(numberValue) &&
|
|
41
|
+
numberValue % 1 === 0 &&
|
|
42
|
+
numberValue.toString() === value);
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
exports.isInt = isInt;
|
|
47
|
+
/**
|
|
48
|
+
* Checks if the provided value is a floating-point number.
|
|
49
|
+
*/
|
|
50
|
+
function isFloat(value) {
|
|
51
|
+
if (typeof value === "number") {
|
|
52
|
+
return value % 1 !== 0;
|
|
53
|
+
}
|
|
54
|
+
else if (typeof value === "string") {
|
|
55
|
+
const numberValue = parseFloat(value);
|
|
56
|
+
return (!Number.isNaN(numberValue) &&
|
|
57
|
+
numberValue % 1 !== 0 &&
|
|
58
|
+
numberValue.toString() === value);
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
exports.isFloat = isFloat;
|
|
63
|
+
/**
|
|
64
|
+
* Checks if the provided value is a string that cannot be parsed into a
|
|
65
|
+
* number.
|
|
66
|
+
*/
|
|
67
|
+
function isString(value) {
|
|
68
|
+
return (typeof value === "string" &&
|
|
69
|
+
(Number.isNaN(parseFloat(value)) || parseFloat(value).toString() !== value));
|
|
70
|
+
}
|
|
71
|
+
exports.isString = isString;
|
|
72
|
+
/**
|
|
73
|
+
* Casts a value that might be string or number to actual string or number.
|
|
74
|
+
* Since LLM might return back an integer/float as a string, we need to cast
|
|
75
|
+
* it back to a number, as many vector databases can't handle number as string
|
|
76
|
+
* values as a comparator.
|
|
77
|
+
*/
|
|
78
|
+
function castValue(input) {
|
|
79
|
+
let value;
|
|
80
|
+
if (isString(input)) {
|
|
81
|
+
value = input;
|
|
82
|
+
}
|
|
83
|
+
else if (isInt(input)) {
|
|
84
|
+
value = parseInt(input, 10);
|
|
85
|
+
}
|
|
86
|
+
else if (isFloat(input)) {
|
|
87
|
+
value = parseFloat(input);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
throw new Error("Unsupported value type");
|
|
91
|
+
}
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
exports.castValue = castValue;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the provided argument is an object and not an array.
|
|
3
|
+
*/
|
|
4
|
+
export declare function isObject(obj: any): obj is object;
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a provided filter is empty. The filter can be a function, an
|
|
7
|
+
* object, a string, or undefined.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isFilterEmpty(filter: ((q: any) => any) | object | string | undefined): filter is undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the provided value is an integer.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isInt(value: unknown): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if the provided value is a floating-point number.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isFloat(value: unknown): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if the provided value is a string that cannot be parsed into a
|
|
20
|
+
* number.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isString(value: unknown): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Casts a value that might be string or number to actual string or number.
|
|
25
|
+
* Since LLM might return back an integer/float as a string, we need to cast
|
|
26
|
+
* it back to a number, as many vector databases can't handle number as string
|
|
27
|
+
* values as a comparator.
|
|
28
|
+
*/
|
|
29
|
+
export declare function castValue(input: unknown): string | number;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the provided argument is an object and not an array.
|
|
3
|
+
*/
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
export function isObject(obj) {
|
|
6
|
+
return obj && typeof obj === "object" && !Array.isArray(obj);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Checks if a provided filter is empty. The filter can be a function, an
|
|
10
|
+
* object, a string, or undefined.
|
|
11
|
+
*/
|
|
12
|
+
export function isFilterEmpty(
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
filter) {
|
|
15
|
+
if (!filter)
|
|
16
|
+
return true;
|
|
17
|
+
// for Milvus
|
|
18
|
+
if (typeof filter === "string" && filter.length > 0) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (typeof filter === "function") {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return isObject(filter) && Object.keys(filter).length === 0;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks if the provided value is an integer.
|
|
28
|
+
*/
|
|
29
|
+
export function isInt(value) {
|
|
30
|
+
if (typeof value === "number") {
|
|
31
|
+
return value % 1 === 0;
|
|
32
|
+
}
|
|
33
|
+
else if (typeof value === "string") {
|
|
34
|
+
const numberValue = parseInt(value, 10);
|
|
35
|
+
return (!Number.isNaN(numberValue) &&
|
|
36
|
+
numberValue % 1 === 0 &&
|
|
37
|
+
numberValue.toString() === value);
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Checks if the provided value is a floating-point number.
|
|
43
|
+
*/
|
|
44
|
+
export function isFloat(value) {
|
|
45
|
+
if (typeof value === "number") {
|
|
46
|
+
return value % 1 !== 0;
|
|
47
|
+
}
|
|
48
|
+
else if (typeof value === "string") {
|
|
49
|
+
const numberValue = parseFloat(value);
|
|
50
|
+
return (!Number.isNaN(numberValue) &&
|
|
51
|
+
numberValue % 1 !== 0 &&
|
|
52
|
+
numberValue.toString() === value);
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Checks if the provided value is a string that cannot be parsed into a
|
|
58
|
+
* number.
|
|
59
|
+
*/
|
|
60
|
+
export function isString(value) {
|
|
61
|
+
return (typeof value === "string" &&
|
|
62
|
+
(Number.isNaN(parseFloat(value)) || parseFloat(value).toString() !== value));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Casts a value that might be string or number to actual string or number.
|
|
66
|
+
* Since LLM might return back an integer/float as a string, we need to cast
|
|
67
|
+
* it back to a number, as many vector databases can't handle number as string
|
|
68
|
+
* values as a comparator.
|
|
69
|
+
*/
|
|
70
|
+
export function castValue(input) {
|
|
71
|
+
let value;
|
|
72
|
+
if (isString(input)) {
|
|
73
|
+
value = input;
|
|
74
|
+
}
|
|
75
|
+
else if (isInt(input)) {
|
|
76
|
+
value = parseInt(input, 10);
|
|
77
|
+
}
|
|
78
|
+
else if (isFloat(input)) {
|
|
79
|
+
value = parseFloat(input);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
throw new Error("Unsupported value type");
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
}
|
package/dist/tools.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DynamicStructuredTool = exports.DynamicTool = exports.Tool = exports.StructuredTool = exports.ToolInputParsingException = void 0;
|
|
3
|
+
exports.BaseToolkit = exports.DynamicStructuredTool = exports.DynamicTool = exports.Tool = exports.StructuredTool = exports.ToolInputParsingException = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const manager_js_1 = require("./callbacks/manager.cjs");
|
|
6
6
|
const base_js_1 = require("./language_models/base.cjs");
|
|
@@ -212,3 +212,14 @@ class DynamicStructuredTool extends StructuredTool {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
exports.DynamicStructuredTool = DynamicStructuredTool;
|
|
215
|
+
/**
|
|
216
|
+
* Abstract base class for toolkits in LangChain. Toolkits are collections
|
|
217
|
+
* of tools that agents can use. Subclasses must implement the `tools`
|
|
218
|
+
* property to provide the specific tools for the toolkit.
|
|
219
|
+
*/
|
|
220
|
+
class BaseToolkit {
|
|
221
|
+
getTools() {
|
|
222
|
+
return this.tools;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.BaseToolkit = BaseToolkit;
|
package/dist/tools.d.ts
CHANGED
|
@@ -149,3 +149,12 @@ export declare class DynamicStructuredTool<T extends z.ZodObject<any, any, any,
|
|
|
149
149
|
tags?: string[]): Promise<string>;
|
|
150
150
|
protected _call(arg: z.output<T>, runManager?: CallbackManagerForToolRun, config?: RunnableConfig): Promise<string>;
|
|
151
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Abstract base class for toolkits in LangChain. Toolkits are collections
|
|
154
|
+
* of tools that agents can use. Subclasses must implement the `tools`
|
|
155
|
+
* property to provide the specific tools for the toolkit.
|
|
156
|
+
*/
|
|
157
|
+
export declare abstract class BaseToolkit {
|
|
158
|
+
abstract tools: StructuredToolInterface[];
|
|
159
|
+
getTools(): StructuredToolInterface[];
|
|
160
|
+
}
|
package/dist/tools.js
CHANGED
|
@@ -204,3 +204,13 @@ export class DynamicStructuredTool extends StructuredTool {
|
|
|
204
204
|
return this.func(arg, runManager, config);
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Abstract base class for toolkits in LangChain. Toolkits are collections
|
|
209
|
+
* of tools that agents can use. Subclasses must implement the `tools`
|
|
210
|
+
* property to provide the specific tools for the toolkit.
|
|
211
|
+
*/
|
|
212
|
+
export class BaseToolkit {
|
|
213
|
+
getTools() {
|
|
214
|
+
return this.tools;
|
|
215
|
+
}
|
|
216
|
+
}
|