langchain 0.1.35 → 0.1.36
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/chains/openai_functions/base.cjs +2 -0
- package/dist/chains/openai_functions/base.d.ts +2 -0
- package/dist/chains/openai_functions/base.js +2 -0
- package/dist/chains/query_constructor/index.cjs +5 -8
- package/dist/chains/query_constructor/index.d.ts +5 -4
- package/dist/chains/query_constructor/index.js +3 -6
- package/dist/chains/query_constructor/ir.cjs +15 -139
- package/dist/chains/query_constructor/ir.d.ts +1 -138
- package/dist/chains/query_constructor/ir.js +1 -132
- package/dist/chains/query_constructor/prompt.cjs +2 -2
- package/dist/chains/query_constructor/prompt.d.ts +1 -1
- package/dist/chains/query_constructor/prompt.js +1 -1
- package/dist/document_loaders/web/firecrawl.cjs +88 -0
- package/dist/document_loaders/web/firecrawl.d.ts +48 -0
- package/dist/document_loaders/web/firecrawl.js +81 -0
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/output_parsers/expression.cjs +1 -1
- package/dist/output_parsers/expression.d.ts +1 -1
- package/dist/output_parsers/expression.js +1 -1
- package/dist/retrievers/self_query/base.cjs +3 -136
- package/dist/retrievers/self_query/base.d.ts +1 -69
- package/dist/retrievers/self_query/base.js +1 -134
- package/dist/retrievers/self_query/chroma.cjs +9 -10
- package/dist/retrievers/self_query/chroma.d.ts +1 -1
- package/dist/retrievers/self_query/chroma.js +1 -2
- package/dist/retrievers/self_query/functional.cjs +2 -195
- package/dist/retrievers/self_query/functional.d.ts +1 -87
- package/dist/retrievers/self_query/functional.js +1 -194
- package/dist/retrievers/self_query/index.cjs +9 -13
- package/dist/retrievers/self_query/index.d.ts +11 -8
- package/dist/retrievers/self_query/index.js +7 -11
- package/dist/retrievers/self_query/pinecone.cjs +9 -10
- package/dist/retrievers/self_query/pinecone.d.ts +1 -1
- package/dist/retrievers/self_query/pinecone.js +1 -2
- package/dist/retrievers/self_query/supabase.cjs +28 -30
- package/dist/retrievers/self_query/supabase.d.ts +1 -2
- package/dist/retrievers/self_query/supabase.js +1 -3
- package/dist/retrievers/self_query/supabase_utils.cjs +2 -2
- package/dist/retrievers/self_query/supabase_utils.d.ts +1 -1
- package/dist/retrievers/self_query/supabase_utils.js +1 -1
- package/dist/retrievers/self_query/vectara.cjs +15 -17
- package/dist/retrievers/self_query/vectara.d.ts +1 -2
- package/dist/retrievers/self_query/vectara.js +1 -3
- package/dist/retrievers/self_query/weaviate.cjs +19 -21
- package/dist/retrievers/self_query/weaviate.d.ts +1 -2
- package/dist/retrievers/self_query/weaviate.js +1 -3
- package/dist/storage/in_memory.cjs +2 -81
- package/dist/storage/in_memory.d.ts +1 -49
- package/dist/storage/in_memory.js +1 -80
- package/dist/text_splitter.cjs +15 -727
- package/dist/text_splitter.d.ts +1 -77
- package/dist/text_splitter.js +1 -720
- package/document_loaders/web/firecrawl.cjs +1 -0
- package/document_loaders/web/firecrawl.d.cts +1 -0
- package/document_loaders/web/firecrawl.d.ts +1 -0
- package/document_loaders/web/firecrawl.js +1 -0
- package/package.json +22 -3
- package/dist/retrievers/self_query/utils.cjs +0 -94
- package/dist/retrievers/self_query/utils.d.ts +0 -29
- package/dist/retrievers/self_query/utils.js +0 -85
|
@@ -71,6 +71,8 @@ function isZodSchema(schema) {
|
|
|
71
71
|
return typeof schema.safeParse === "function";
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
+
* @deprecated Prefer the `.withStructuredOutput` method on chat model classes.
|
|
75
|
+
*
|
|
74
76
|
* Create a runnable that uses an OpenAI function to get a structured output.
|
|
75
77
|
* @param config Params required to create the runnable.
|
|
76
78
|
* @returns A runnable sequence that will pass the given function to the model when run.
|
|
@@ -98,6 +98,8 @@ export type CreateStructuredOutputRunnableConfig<RunInput extends Record<string,
|
|
|
98
98
|
outputParser?: BaseOutputParser<RunOutput>;
|
|
99
99
|
};
|
|
100
100
|
/**
|
|
101
|
+
* @deprecated Prefer the `.withStructuredOutput` method on chat model classes.
|
|
102
|
+
*
|
|
101
103
|
* Create a runnable that uses an OpenAI function to get a structured output.
|
|
102
104
|
* @param config Params required to create the runnable.
|
|
103
105
|
* @returns A runnable sequence that will pass the given function to the model when run.
|
|
@@ -67,6 +67,8 @@ function isZodSchema(schema) {
|
|
|
67
67
|
return typeof schema.safeParse === "function";
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
+
* @deprecated Prefer the `.withStructuredOutput` method on chat model classes.
|
|
71
|
+
*
|
|
70
72
|
* Create a runnable that uses an OpenAI function to get a structured output.
|
|
71
73
|
* @param config Params required to create the runnable.
|
|
72
74
|
* @returns A runnable sequence that will pass the given function to the model when run.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.loadQueryConstructorRunnable = exports.formatAttributeInfo = exports.StructuredQueryOutputParser = exports.EXAMPLE_PROMPT = exports.DEFAULT_SUFFIX = exports.DEFAULT_SCHEMA = exports.DEFAULT_PREFIX = exports.DEFAULT_EXAMPLES = exports.QueryTransformer = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const prompts_1 = require("@langchain/core/prompts");
|
|
6
6
|
const parser_js_1 = require("./parser.cjs");
|
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "DEFAULT_PREFIX", { enumerable: true, get: functi
|
|
|
12
12
|
Object.defineProperty(exports, "DEFAULT_SCHEMA", { enumerable: true, get: function () { return prompt_js_1.DEFAULT_SCHEMA; } });
|
|
13
13
|
Object.defineProperty(exports, "DEFAULT_SUFFIX", { enumerable: true, get: function () { return prompt_js_1.DEFAULT_SUFFIX; } });
|
|
14
14
|
Object.defineProperty(exports, "EXAMPLE_PROMPT", { enumerable: true, get: function () { return prompt_js_1.EXAMPLE_PROMPT; } });
|
|
15
|
-
const llm_chain_js_1 = require("../llm_chain.cjs");
|
|
16
15
|
const structured_js_1 = require("../../output_parsers/structured.cjs");
|
|
17
16
|
const queryInputSchema = /* #__PURE__ */ zod_1.z.object({
|
|
18
17
|
query: /* #__PURE__ */ zod_1.z
|
|
@@ -119,11 +118,9 @@ function _getPrompt(documentContents, attributeInfo, allowedComparators, allowed
|
|
|
119
118
|
outputParser,
|
|
120
119
|
});
|
|
121
120
|
}
|
|
122
|
-
function
|
|
121
|
+
function loadQueryConstructorRunnable(opts) {
|
|
123
122
|
const prompt = _getPrompt(opts.documentContents, opts.attributeInfo, opts.allowedComparators, opts.allowedOperators, opts.examples);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
prompt,
|
|
127
|
-
});
|
|
123
|
+
const outputParser = StructuredQueryOutputParser.fromComponents(opts.allowedComparators, opts.allowedOperators);
|
|
124
|
+
return prompt.pipe(opts.llm).pipe(outputParser);
|
|
128
125
|
}
|
|
129
|
-
exports.
|
|
126
|
+
exports.loadQueryConstructorRunnable = loadQueryConstructorRunnable;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { BaseLanguageModelInterface } from "@langchain/core/language_models/base";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import type { BaseLanguageModelInterface } from "@langchain/core/language_models/base";
|
|
3
3
|
import { InputValues } from "@langchain/core/utils/types";
|
|
4
4
|
import { QueryTransformer, TraverseType } from "./parser.js";
|
|
5
5
|
import { Comparator, Operator, StructuredQuery } from "./ir.js";
|
|
6
6
|
import { DEFAULT_EXAMPLES, DEFAULT_PREFIX, DEFAULT_SCHEMA, DEFAULT_SUFFIX, EXAMPLE_PROMPT } from "./prompt.js";
|
|
7
|
-
import { LLMChain } from "../llm_chain.js";
|
|
8
7
|
import { AsymmetricStructuredOutputParser } from "../../output_parsers/structured.js";
|
|
9
8
|
import { AttributeInfo } from "../../schema/query_constructor.js";
|
|
10
9
|
export { QueryTransformer, type TraverseType };
|
|
@@ -50,7 +49,7 @@ export declare function formatAttributeInfo(info: AttributeInfo[]): string;
|
|
|
50
49
|
/**
|
|
51
50
|
* A type that represents options for the query constructor chain.
|
|
52
51
|
*/
|
|
53
|
-
export type
|
|
52
|
+
export type QueryConstructorRunnableOptions = {
|
|
54
53
|
llm: BaseLanguageModelInterface;
|
|
55
54
|
documentContents: string;
|
|
56
55
|
attributeInfo: AttributeInfo[];
|
|
@@ -58,4 +57,6 @@ export type QueryConstructorChainOptions = {
|
|
|
58
57
|
allowedComparators?: Comparator[];
|
|
59
58
|
allowedOperators?: Operator[];
|
|
60
59
|
};
|
|
61
|
-
|
|
60
|
+
/** @deprecated */
|
|
61
|
+
export type QueryConstructorChainOptions = QueryConstructorRunnableOptions;
|
|
62
|
+
export declare function loadQueryConstructorRunnable(opts: QueryConstructorRunnableOptions): import("@langchain/core/runnables").Runnable<any, StructuredQuery, import("@langchain/core/runnables").RunnableConfig>;
|
|
@@ -3,7 +3,6 @@ import { interpolateFString, FewShotPromptTemplate, } from "@langchain/core/prom
|
|
|
3
3
|
import { QueryTransformer } from "./parser.js";
|
|
4
4
|
import { Comparators, Operators, StructuredQuery, } from "./ir.js";
|
|
5
5
|
import { DEFAULT_EXAMPLES, DEFAULT_PREFIX, DEFAULT_SCHEMA, DEFAULT_SUFFIX, EXAMPLE_PROMPT, } from "./prompt.js";
|
|
6
|
-
import { LLMChain } from "../llm_chain.js";
|
|
7
6
|
import { AsymmetricStructuredOutputParser } from "../../output_parsers/structured.js";
|
|
8
7
|
export { QueryTransformer };
|
|
9
8
|
export { DEFAULT_EXAMPLES, DEFAULT_PREFIX, DEFAULT_SCHEMA, DEFAULT_SUFFIX, EXAMPLE_PROMPT, };
|
|
@@ -110,10 +109,8 @@ function _getPrompt(documentContents, attributeInfo, allowedComparators, allowed
|
|
|
110
109
|
outputParser,
|
|
111
110
|
});
|
|
112
111
|
}
|
|
113
|
-
export function
|
|
112
|
+
export function loadQueryConstructorRunnable(opts) {
|
|
114
113
|
const prompt = _getPrompt(opts.documentContents, opts.attributeInfo, opts.allowedComparators, opts.allowedOperators, opts.examples);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
prompt,
|
|
118
|
-
});
|
|
114
|
+
const outputParser = StructuredQueryOutputParser.fromComponents(opts.allowedComparators, opts.allowedOperators);
|
|
115
|
+
return prompt.pipe(opts.llm).pipe(outputParser);
|
|
119
116
|
}
|
|
@@ -1,141 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
});
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
83
7
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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;
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@langchain/core/structured_query"), exports);
|
|
@@ -1,138 +1 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
export * from "@langchain/core/structured_query";
|
|
@@ -1,132 +1 @@
|
|
|
1
|
-
export
|
|
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
|
-
}
|
|
1
|
+
export * from "@langchain/core/structured_query";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_SUFFIX = exports.DEFAULT_PREFIX = exports.DEFAULT_SCHEMA = exports.EXAMPLE_PROMPT = exports.EXAMPLE_PROMPT_TEMPLATE = exports.DEFAULT_EXAMPLES = exports.NO_FILTER_ANSWER = exports.FULL_ANSWER = exports.SONG_DATA_SOURCE = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_js_1 = require("../../prompts/index.cjs");
|
|
5
5
|
exports.SONG_DATA_SOURCE = `\
|
|
6
6
|
\`\`\`json
|
|
7
7
|
{
|
|
@@ -65,7 +65,7 @@ User Query:
|
|
|
65
65
|
Structured Request:
|
|
66
66
|
{structured_request}
|
|
67
67
|
`;
|
|
68
|
-
exports.EXAMPLE_PROMPT = new
|
|
68
|
+
exports.EXAMPLE_PROMPT = new index_js_1.PromptTemplate({
|
|
69
69
|
inputVariables: ["i", "data_source", "user_query", "structured_request"],
|
|
70
70
|
template: exports.EXAMPLE_PROMPT_TEMPLATE,
|
|
71
71
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PromptTemplate } from "
|
|
1
|
+
import { PromptTemplate } from "../../prompts/index.js";
|
|
2
2
|
export declare const SONG_DATA_SOURCE: string;
|
|
3
3
|
export declare const FULL_ANSWER = "```json\n{{\n \"query\": \"teenager love\",\n \"filter\": \"and(or(eq(\\\"artist\\\", \\\"Taylor Swift\\\"), eq(\\\"artist\\\", \\\"Katy Perry\\\")), lt(\\\"length\\\", 180), eq(\\\"genre\\\", \\\"pop\\\"))\"\n}}";
|
|
4
4
|
export declare const NO_FILTER_ANSWER = "```json\n{{\n \"query\": \"\",\n \"filter\": \"NO_FILTER\"\n}}\n```";
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FireCrawlLoader = void 0;
|
|
7
|
+
const firecrawl_js_1 = __importDefault(require("@mendable/firecrawl-js"));
|
|
8
|
+
const documents_1 = require("@langchain/core/documents");
|
|
9
|
+
const env_1 = require("@langchain/core/utils/env");
|
|
10
|
+
const base_js_1 = require("../base.cjs");
|
|
11
|
+
/**
|
|
12
|
+
* Class representing a document loader for loading data from
|
|
13
|
+
* Firecrawl (firecrawl.dev). It extends the BaseDocumentLoader class.
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const loader = new FireCrawlLoader({
|
|
17
|
+
* url: "{url}",
|
|
18
|
+
* apiKey: "{apiKey}",
|
|
19
|
+
* mode: "crawl"
|
|
20
|
+
* });
|
|
21
|
+
* const docs = await loader.load();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
class FireCrawlLoader extends base_js_1.BaseDocumentLoader {
|
|
25
|
+
constructor(loaderParams) {
|
|
26
|
+
super();
|
|
27
|
+
Object.defineProperty(this, "apiKey", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(this, "url", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(this, "mode", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: void 0
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(this, "params", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: void 0
|
|
50
|
+
});
|
|
51
|
+
const { apiKey = (0, env_1.getEnvironmentVariable)("FIRECRAWL_API_KEY"), url, mode = "crawl", params, } = loaderParams;
|
|
52
|
+
if (!apiKey) {
|
|
53
|
+
throw new Error("Firecrawl API key not set. You can set it as FIRECRAWL_API_KEY in your .env file, or pass it to Firecrawl.");
|
|
54
|
+
}
|
|
55
|
+
this.apiKey = apiKey;
|
|
56
|
+
this.url = url;
|
|
57
|
+
this.mode = mode;
|
|
58
|
+
this.params = params;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Loads the data from the Firecrawl.
|
|
62
|
+
* @returns An array of Documents representing the retrieved data.
|
|
63
|
+
* @throws An error if the data could not be loaded.
|
|
64
|
+
*/
|
|
65
|
+
async load() {
|
|
66
|
+
const app = new firecrawl_js_1.default({ apiKey: this.apiKey });
|
|
67
|
+
let firecrawlDocs;
|
|
68
|
+
if (this.mode === "scrape") {
|
|
69
|
+
const response = await app.scrapeUrl(this.url, this.params);
|
|
70
|
+
if (!response.success) {
|
|
71
|
+
throw new Error(`Firecrawl: Failed to scrape URL. Error: ${response.error}`);
|
|
72
|
+
}
|
|
73
|
+
firecrawlDocs = [response.data];
|
|
74
|
+
}
|
|
75
|
+
else if (this.mode === "crawl") {
|
|
76
|
+
const response = await app.crawlUrl(this.url, this.params, true);
|
|
77
|
+
firecrawlDocs = response;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw new Error(`Unrecognized mode '${this.mode}'. Expected one of 'crawl', 'scrape'.`);
|
|
81
|
+
}
|
|
82
|
+
return firecrawlDocs.map((doc) => new documents_1.Document({
|
|
83
|
+
pageContent: doc.markdown || "",
|
|
84
|
+
metadata: doc.metadata || {},
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.FireCrawlLoader = FireCrawlLoader;
|