langchain 0.0.133 → 0.0.135
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/agents/chat_convo/outputParser.cjs +13 -10
- package/dist/agents/chat_convo/outputParser.js +13 -10
- package/dist/callbacks/base.d.ts +6 -3
- package/dist/callbacks/handlers/tracer.cjs +2 -2
- package/dist/callbacks/handlers/tracer.d.ts +2 -2
- package/dist/callbacks/handlers/tracer.js +2 -2
- package/dist/callbacks/index.cjs +2 -1
- package/dist/callbacks/index.d.ts +1 -1
- package/dist/callbacks/index.js +1 -1
- package/dist/callbacks/manager.cjs +2 -2
- package/dist/callbacks/manager.d.ts +2 -2
- package/dist/callbacks/manager.js +2 -2
- package/dist/chains/sql_db/sql_db_chain.d.ts +1 -1
- package/dist/chains/sql_db/sql_db_prompt.d.ts +6 -6
- package/dist/chat_models/openai.cjs +10 -5
- package/dist/chat_models/openai.js +10 -5
- package/dist/document_loaders/web/recursive_url.cjs +177 -0
- package/dist/document_loaders/web/recursive_url.d.ts +27 -0
- package/dist/document_loaders/web/recursive_url.js +173 -0
- package/dist/hub.cjs +16 -0
- package/dist/hub.d.ts +4 -0
- package/dist/hub.js +11 -0
- package/dist/llms/bedrock.cjs +63 -19
- package/dist/llms/bedrock.d.ts +9 -1
- package/dist/llms/bedrock.js +63 -19
- package/dist/llms/writer.cjs +167 -0
- package/dist/llms/writer.d.ts +60 -0
- package/dist/llms/writer.js +163 -0
- package/dist/load/import_constants.cjs +4 -0
- package/dist/load/import_constants.js +4 -0
- package/dist/load/import_map.cjs +2 -1
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/memory/summary_buffer.d.ts +1 -1
- package/dist/retrievers/score_threshold.cjs +45 -0
- package/dist/retrievers/score_threshold.d.ts +15 -0
- package/dist/retrievers/score_threshold.js +41 -0
- package/dist/sql_db.cjs +8 -1
- package/dist/sql_db.d.ts +1 -0
- package/dist/sql_db.js +8 -1
- package/dist/stores/message/mongodb.cjs +48 -0
- package/dist/stores/message/mongodb.d.ts +15 -0
- package/dist/stores/message/mongodb.js +44 -0
- package/dist/tools/sql.cjs +9 -3
- package/dist/tools/sql.d.ts +0 -1
- package/dist/tools/sql.js +9 -3
- package/dist/util/sql_utils.cjs +8 -2
- package/dist/util/sql_utils.d.ts +2 -1
- package/dist/util/sql_utils.js +8 -2
- package/dist/vectorstores/googlevertexai.cjs +2 -1
- package/dist/vectorstores/googlevertexai.js +2 -1
- package/dist/vectorstores/myscale.cjs +2 -2
- package/dist/vectorstores/myscale.d.ts +1 -1
- package/dist/vectorstores/myscale.js +2 -2
- package/document_loaders/web/recursive_url.cjs +1 -0
- package/document_loaders/web/recursive_url.d.ts +1 -0
- package/document_loaders/web/recursive_url.js +1 -0
- package/hub.cjs +1 -0
- package/hub.d.ts +1 -0
- package/hub.js +1 -0
- package/llms/writer.cjs +1 -0
- package/llms/writer.d.ts +1 -0
- package/llms/writer.js +1 -0
- package/package.json +61 -1
- package/retrievers/score_threshold.cjs +1 -0
- package/retrievers/score_threshold.d.ts +1 -0
- package/retrievers/score_threshold.js +1 -0
- package/stores/message/mongodb.cjs +1 -0
- package/stores/message/mongodb.d.ts +1 -0
- package/stores/message/mongodb.js +1 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { BaseLLMParams, LLM } from "./base.js";
|
|
2
|
+
/**
|
|
3
|
+
* Interface for the input parameters specific to the Writer model.
|
|
4
|
+
*/
|
|
5
|
+
export interface WriterInput extends BaseLLMParams {
|
|
6
|
+
/** Writer API key */
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
/** Writer organization ID */
|
|
9
|
+
orgId?: string | number;
|
|
10
|
+
/** Model to use */
|
|
11
|
+
model?: string;
|
|
12
|
+
/** Sampling temperature to use */
|
|
13
|
+
temperature?: number;
|
|
14
|
+
/** Minimum number of tokens to generate. */
|
|
15
|
+
minTokens?: number;
|
|
16
|
+
/** Maximum number of tokens to generate in the completion. */
|
|
17
|
+
maxTokens?: number;
|
|
18
|
+
/** Generates this many completions server-side and returns the "best"." */
|
|
19
|
+
bestOf?: number;
|
|
20
|
+
/** Penalizes repeated tokens according to frequency. */
|
|
21
|
+
frequencyPenalty?: number;
|
|
22
|
+
/** Whether to return log probabilities. */
|
|
23
|
+
logprobs?: number;
|
|
24
|
+
/** Number of completions to generate. */
|
|
25
|
+
n?: number;
|
|
26
|
+
/** Penalizes repeated tokens regardless of frequency. */
|
|
27
|
+
presencePenalty?: number;
|
|
28
|
+
/** Total probability mass of tokens to consider at each step. */
|
|
29
|
+
topP?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Class representing a Writer Large Language Model (LLM). It interacts
|
|
33
|
+
* with the Writer API to generate text completions.
|
|
34
|
+
*/
|
|
35
|
+
export declare class Writer extends LLM implements WriterInput {
|
|
36
|
+
static lc_name(): string;
|
|
37
|
+
get lc_secrets(): {
|
|
38
|
+
[key: string]: string;
|
|
39
|
+
} | undefined;
|
|
40
|
+
get lc_aliases(): {
|
|
41
|
+
[key: string]: string;
|
|
42
|
+
} | undefined;
|
|
43
|
+
lc_serializable: boolean;
|
|
44
|
+
apiKey: string;
|
|
45
|
+
orgId: number;
|
|
46
|
+
model: string;
|
|
47
|
+
temperature?: number;
|
|
48
|
+
minTokens?: number;
|
|
49
|
+
maxTokens?: number;
|
|
50
|
+
bestOf?: number;
|
|
51
|
+
frequencyPenalty?: number;
|
|
52
|
+
logprobs?: number;
|
|
53
|
+
n?: number;
|
|
54
|
+
presencePenalty?: number;
|
|
55
|
+
topP?: number;
|
|
56
|
+
constructor(fields?: WriterInput);
|
|
57
|
+
_llmType(): string;
|
|
58
|
+
/** @ignore */
|
|
59
|
+
_call(prompt: string, options: this["ParsedCallOptions"]): Promise<string>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { Writer as WriterClient } from "@writerai/writer-sdk";
|
|
2
|
+
import { LLM } from "./base.js";
|
|
3
|
+
import { getEnvironmentVariable } from "../util/env.js";
|
|
4
|
+
/**
|
|
5
|
+
* Class representing a Writer Large Language Model (LLM). It interacts
|
|
6
|
+
* with the Writer API to generate text completions.
|
|
7
|
+
*/
|
|
8
|
+
export class Writer extends LLM {
|
|
9
|
+
static lc_name() {
|
|
10
|
+
return "Writer";
|
|
11
|
+
}
|
|
12
|
+
get lc_secrets() {
|
|
13
|
+
return {
|
|
14
|
+
apiKey: "WRITER_API_KEY",
|
|
15
|
+
orgId: "WRITER_ORG_ID",
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
get lc_aliases() {
|
|
19
|
+
return {
|
|
20
|
+
apiKey: "writer_api_key",
|
|
21
|
+
orgId: "writer_org_id",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
constructor(fields) {
|
|
25
|
+
super(fields ?? {});
|
|
26
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: true
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(this, "apiKey", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: void 0
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(this, "orgId", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true,
|
|
42
|
+
value: void 0
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(this, "model", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
writable: true,
|
|
48
|
+
value: "palmyra-instruct"
|
|
49
|
+
});
|
|
50
|
+
Object.defineProperty(this, "temperature", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
configurable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
value: void 0
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(this, "minTokens", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: void 0
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(this, "maxTokens", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: void 0
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(this, "bestOf", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: true,
|
|
71
|
+
writable: true,
|
|
72
|
+
value: void 0
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(this, "frequencyPenalty", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
configurable: true,
|
|
77
|
+
writable: true,
|
|
78
|
+
value: void 0
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(this, "logprobs", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
configurable: true,
|
|
83
|
+
writable: true,
|
|
84
|
+
value: void 0
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(this, "n", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
configurable: true,
|
|
89
|
+
writable: true,
|
|
90
|
+
value: void 0
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(this, "presencePenalty", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
configurable: true,
|
|
95
|
+
writable: true,
|
|
96
|
+
value: void 0
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(this, "topP", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
configurable: true,
|
|
101
|
+
writable: true,
|
|
102
|
+
value: void 0
|
|
103
|
+
});
|
|
104
|
+
const apiKey = fields?.apiKey ?? getEnvironmentVariable("WRITER_API_KEY");
|
|
105
|
+
const orgId = fields?.orgId ?? getEnvironmentVariable("WRITER_ORG_ID");
|
|
106
|
+
if (!apiKey) {
|
|
107
|
+
throw new Error("Please set the WRITER_API_KEY environment variable or pass it to the constructor as the apiKey field.");
|
|
108
|
+
}
|
|
109
|
+
if (!orgId) {
|
|
110
|
+
throw new Error("Please set the WRITER_ORG_ID environment variable or pass it to the constructor as the orgId field.");
|
|
111
|
+
}
|
|
112
|
+
this.apiKey = apiKey;
|
|
113
|
+
this.orgId = typeof orgId === "string" ? parseInt(orgId, 10) : orgId;
|
|
114
|
+
this.model = fields?.model ?? this.model;
|
|
115
|
+
this.temperature = fields?.temperature ?? this.temperature;
|
|
116
|
+
this.minTokens = fields?.minTokens ?? this.minTokens;
|
|
117
|
+
this.maxTokens = fields?.maxTokens ?? this.maxTokens;
|
|
118
|
+
this.bestOf = fields?.bestOf ?? this.bestOf;
|
|
119
|
+
this.frequencyPenalty = fields?.frequencyPenalty ?? this.frequencyPenalty;
|
|
120
|
+
this.logprobs = fields?.logprobs ?? this.logprobs;
|
|
121
|
+
this.n = fields?.n ?? this.n;
|
|
122
|
+
this.presencePenalty = fields?.presencePenalty ?? this.presencePenalty;
|
|
123
|
+
this.topP = fields?.topP ?? this.topP;
|
|
124
|
+
}
|
|
125
|
+
_llmType() {
|
|
126
|
+
return "writer";
|
|
127
|
+
}
|
|
128
|
+
/** @ignore */
|
|
129
|
+
async _call(prompt, options) {
|
|
130
|
+
const sdk = new WriterClient({
|
|
131
|
+
security: {
|
|
132
|
+
apiKey: this.apiKey,
|
|
133
|
+
},
|
|
134
|
+
organizationId: this.orgId,
|
|
135
|
+
});
|
|
136
|
+
return this.caller.callWithOptions({ signal: options.signal }, async () => {
|
|
137
|
+
try {
|
|
138
|
+
const res = await sdk.completions.create({
|
|
139
|
+
completionRequest: {
|
|
140
|
+
prompt,
|
|
141
|
+
stop: options.stop,
|
|
142
|
+
temperature: this.temperature,
|
|
143
|
+
minTokens: this.minTokens,
|
|
144
|
+
maxTokens: this.maxTokens,
|
|
145
|
+
bestOf: this.bestOf,
|
|
146
|
+
n: this.n,
|
|
147
|
+
frequencyPenalty: this.frequencyPenalty,
|
|
148
|
+
logprobs: this.logprobs,
|
|
149
|
+
presencePenalty: this.presencePenalty,
|
|
150
|
+
topP: this.topP,
|
|
151
|
+
},
|
|
152
|
+
modelId: this.model,
|
|
153
|
+
});
|
|
154
|
+
return (res.completionResponse?.choices?.[0].text ?? "No completion found.");
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
158
|
+
e.response = e.rawResponse;
|
|
159
|
+
throw e;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -29,6 +29,7 @@ exports.optionalImportEntrypoints = [
|
|
|
29
29
|
"langchain/llms/googlepalm",
|
|
30
30
|
"langchain/llms/sagemaker_endpoint",
|
|
31
31
|
"langchain/llms/bedrock",
|
|
32
|
+
"langchain/llms/writer",
|
|
32
33
|
"langchain/prompts/load",
|
|
33
34
|
"langchain/vectorstores/analyticdb",
|
|
34
35
|
"langchain/vectorstores/elasticsearch",
|
|
@@ -69,6 +70,7 @@ exports.optionalImportEntrypoints = [
|
|
|
69
70
|
"langchain/document_loaders/web/github",
|
|
70
71
|
"langchain/document_loaders/web/notiondb",
|
|
71
72
|
"langchain/document_loaders/web/notionapi",
|
|
73
|
+
"langchain/document_loaders/web/recursive_url",
|
|
72
74
|
"langchain/document_loaders/web/s3",
|
|
73
75
|
"langchain/document_loaders/web/sonix_audio",
|
|
74
76
|
"langchain/document_loaders/web/confluence",
|
|
@@ -109,11 +111,13 @@ exports.optionalImportEntrypoints = [
|
|
|
109
111
|
"langchain/stores/message/dynamodb",
|
|
110
112
|
"langchain/stores/message/firestore",
|
|
111
113
|
"langchain/stores/message/momento",
|
|
114
|
+
"langchain/stores/message/mongodb",
|
|
112
115
|
"langchain/stores/message/redis",
|
|
113
116
|
"langchain/stores/message/ioredis",
|
|
114
117
|
"langchain/stores/message/upstash_redis",
|
|
115
118
|
"langchain/stores/message/planetscale",
|
|
116
119
|
"langchain/stores/message/xata",
|
|
117
120
|
"langchain/storage/ioredis",
|
|
121
|
+
"langchain/hub",
|
|
118
122
|
"langchain/experimental/multimodal_embeddings/googlevertexai",
|
|
119
123
|
];
|
|
@@ -26,6 +26,7 @@ export const optionalImportEntrypoints = [
|
|
|
26
26
|
"langchain/llms/googlepalm",
|
|
27
27
|
"langchain/llms/sagemaker_endpoint",
|
|
28
28
|
"langchain/llms/bedrock",
|
|
29
|
+
"langchain/llms/writer",
|
|
29
30
|
"langchain/prompts/load",
|
|
30
31
|
"langchain/vectorstores/analyticdb",
|
|
31
32
|
"langchain/vectorstores/elasticsearch",
|
|
@@ -66,6 +67,7 @@ export const optionalImportEntrypoints = [
|
|
|
66
67
|
"langchain/document_loaders/web/github",
|
|
67
68
|
"langchain/document_loaders/web/notiondb",
|
|
68
69
|
"langchain/document_loaders/web/notionapi",
|
|
70
|
+
"langchain/document_loaders/web/recursive_url",
|
|
69
71
|
"langchain/document_loaders/web/s3",
|
|
70
72
|
"langchain/document_loaders/web/sonix_audio",
|
|
71
73
|
"langchain/document_loaders/web/confluence",
|
|
@@ -106,11 +108,13 @@ export const optionalImportEntrypoints = [
|
|
|
106
108
|
"langchain/stores/message/dynamodb",
|
|
107
109
|
"langchain/stores/message/firestore",
|
|
108
110
|
"langchain/stores/message/momento",
|
|
111
|
+
"langchain/stores/message/mongodb",
|
|
109
112
|
"langchain/stores/message/redis",
|
|
110
113
|
"langchain/stores/message/ioredis",
|
|
111
114
|
"langchain/stores/message/upstash_redis",
|
|
112
115
|
"langchain/stores/message/planetscale",
|
|
113
116
|
"langchain/stores/message/xata",
|
|
114
117
|
"langchain/storage/ioredis",
|
|
118
|
+
"langchain/hub",
|
|
115
119
|
"langchain/experimental/multimodal_embeddings/googlevertexai",
|
|
116
120
|
];
|
package/dist/load/import_map.cjs
CHANGED
|
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.retrievers__hyde = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__parent_document = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = exports.retrievers__remote = exports.output_parsers = exports.callbacks = exports.schema__storage = exports.schema__runnable = exports.schema__retriever = exports.schema__query_constructor = exports.schema__output_parser = exports.schema = exports.chat_models__ollama = exports.chat_models__baiduwenxin = exports.chat_models__anthropic = exports.chat_models__openai = exports.chat_models__base = exports.document_transformers__openai_functions = exports.document_loaders__web__sort_xyz_blockchain = exports.document_loaders__web__serpapi = exports.document_loaders__base = exports.document = exports.memory = exports.text_splitter = exports.vectorstores__xata = exports.vectorstores__vectara = exports.vectorstores__prisma = exports.vectorstores__memory = exports.vectorstores__base = exports.prompts = exports.llms__ollama = exports.llms__aleph_alpha = exports.llms__ai21 = exports.llms__openai = exports.llms__base = exports.embeddings__openai = exports.embeddings__fake = exports.embeddings__cache_backed = exports.embeddings__base = exports.chains__openai_functions = exports.chains = exports.tools = exports.base_language = exports.agents__toolkits = exports.agents = exports.load__serializable = void 0;
|
|
28
|
-
exports.evaluation = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__math = exports.storage__in_memory = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = void 0;
|
|
28
|
+
exports.evaluation = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__math = exports.storage__in_memory = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = void 0;
|
|
29
29
|
exports.load__serializable = __importStar(require("../load/serializable.cjs"));
|
|
30
30
|
exports.agents = __importStar(require("../agents/index.cjs"));
|
|
31
31
|
exports.agents__toolkits = __importStar(require("../agents/toolkits/index.cjs"));
|
|
@@ -76,6 +76,7 @@ exports.retrievers__parent_document = __importStar(require("../retrievers/parent
|
|
|
76
76
|
exports.retrievers__time_weighted = __importStar(require("../retrievers/time_weighted.cjs"));
|
|
77
77
|
exports.retrievers__document_compressors__chain_extract = __importStar(require("../retrievers/document_compressors/chain_extract.cjs"));
|
|
78
78
|
exports.retrievers__hyde = __importStar(require("../retrievers/hyde.cjs"));
|
|
79
|
+
exports.retrievers__score_threshold = __importStar(require("../retrievers/score_threshold.cjs"));
|
|
79
80
|
exports.retrievers__vespa = __importStar(require("../retrievers/vespa.cjs"));
|
|
80
81
|
exports.cache = __importStar(require("../cache/index.cjs"));
|
|
81
82
|
exports.stores__doc__in_memory = __importStar(require("../stores/doc/in_memory.cjs"));
|
|
@@ -48,6 +48,7 @@ export * as retrievers__parent_document from "../retrievers/parent_document.js";
|
|
|
48
48
|
export * as retrievers__time_weighted from "../retrievers/time_weighted.js";
|
|
49
49
|
export * as retrievers__document_compressors__chain_extract from "../retrievers/document_compressors/chain_extract.js";
|
|
50
50
|
export * as retrievers__hyde from "../retrievers/hyde.js";
|
|
51
|
+
export * as retrievers__score_threshold from "../retrievers/score_threshold.js";
|
|
51
52
|
export * as retrievers__vespa from "../retrievers/vespa.js";
|
|
52
53
|
export * as cache from "../cache/index.js";
|
|
53
54
|
export * as stores__doc__in_memory from "../stores/doc/in_memory.js";
|
package/dist/load/import_map.js
CHANGED
|
@@ -49,6 +49,7 @@ export * as retrievers__parent_document from "../retrievers/parent_document.js";
|
|
|
49
49
|
export * as retrievers__time_weighted from "../retrievers/time_weighted.js";
|
|
50
50
|
export * as retrievers__document_compressors__chain_extract from "../retrievers/document_compressors/chain_extract.js";
|
|
51
51
|
export * as retrievers__hyde from "../retrievers/hyde.js";
|
|
52
|
+
export * as retrievers__score_threshold from "../retrievers/score_threshold.js";
|
|
52
53
|
export * as retrievers__vespa from "../retrievers/vespa.js";
|
|
53
54
|
export * as cache from "../cache/index.js";
|
|
54
55
|
export * as stores__doc__in_memory from "../stores/doc/in_memory.js";
|
|
@@ -26,7 +26,7 @@ export declare class ConversationSummaryBufferMemory extends BaseConversationSum
|
|
|
26
26
|
* @param _ InputValues object, not used in this method.
|
|
27
27
|
* @returns Promise that resolves with MemoryVariables object containing the loaded chat messages.
|
|
28
28
|
*/
|
|
29
|
-
loadMemoryVariables(_
|
|
29
|
+
loadMemoryVariables(_?: InputValues): Promise<MemoryVariables>;
|
|
30
30
|
/**
|
|
31
31
|
* Method that saves the context of the conversation, including the input
|
|
32
32
|
* and output values, and prunes the memory if it exceeds the maximum
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScoreThresholdRetriever = void 0;
|
|
4
|
+
const base_js_1 = require("../vectorstores/base.cjs");
|
|
5
|
+
class ScoreThresholdRetriever extends base_js_1.VectorStoreRetriever {
|
|
6
|
+
constructor(input) {
|
|
7
|
+
super(input);
|
|
8
|
+
Object.defineProperty(this, "minSimilarityScore", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: void 0
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(this, "kIncrement", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: 10
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "maxK", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: 100
|
|
25
|
+
});
|
|
26
|
+
this.maxK = input.maxK ?? this.maxK;
|
|
27
|
+
this.minSimilarityScore =
|
|
28
|
+
input.minSimilarityScore ?? this.minSimilarityScore;
|
|
29
|
+
this.kIncrement = input.kIncrement ?? this.kIncrement;
|
|
30
|
+
}
|
|
31
|
+
async getRelevantDocuments(query) {
|
|
32
|
+
let currentK = 0;
|
|
33
|
+
let filteredResults = [];
|
|
34
|
+
do {
|
|
35
|
+
currentK += this.kIncrement;
|
|
36
|
+
const results = await this.vectorStore.similaritySearchWithScore(query, currentK, this.filter);
|
|
37
|
+
filteredResults = results.filter(([, score]) => score >= this.minSimilarityScore);
|
|
38
|
+
} while (filteredResults.length >= currentK && currentK < this.maxK);
|
|
39
|
+
return filteredResults.map((documents) => documents[0]).slice(0, this.maxK);
|
|
40
|
+
}
|
|
41
|
+
static fromVectorStore(vectorStore, options) {
|
|
42
|
+
return new this({ ...options, vectorStore });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.ScoreThresholdRetriever = ScoreThresholdRetriever;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { VectorStore, VectorStoreRetriever, VectorStoreRetrieverInput } from "../vectorstores/base.js";
|
|
2
|
+
import { Document } from "../document.js";
|
|
3
|
+
export type ScoreThresholdRetrieverInput<V extends VectorStore> = Omit<VectorStoreRetrieverInput<V>, "k"> & {
|
|
4
|
+
maxK?: number;
|
|
5
|
+
kIncrement?: number;
|
|
6
|
+
minSimilarityScore: number;
|
|
7
|
+
};
|
|
8
|
+
export declare class ScoreThresholdRetriever<V extends VectorStore> extends VectorStoreRetriever<V> {
|
|
9
|
+
minSimilarityScore: number;
|
|
10
|
+
kIncrement: number;
|
|
11
|
+
maxK: number;
|
|
12
|
+
constructor(input: ScoreThresholdRetrieverInput<V>);
|
|
13
|
+
getRelevantDocuments(query: string): Promise<Document[]>;
|
|
14
|
+
static fromVectorStore<V extends VectorStore>(vectorStore: V, options: Omit<ScoreThresholdRetrieverInput<V>, "vectorStore">): ScoreThresholdRetriever<V>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { VectorStoreRetriever, } from "../vectorstores/base.js";
|
|
2
|
+
export class ScoreThresholdRetriever extends VectorStoreRetriever {
|
|
3
|
+
constructor(input) {
|
|
4
|
+
super(input);
|
|
5
|
+
Object.defineProperty(this, "minSimilarityScore", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: void 0
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(this, "kIncrement", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: 10
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "maxK", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: 100
|
|
22
|
+
});
|
|
23
|
+
this.maxK = input.maxK ?? this.maxK;
|
|
24
|
+
this.minSimilarityScore =
|
|
25
|
+
input.minSimilarityScore ?? this.minSimilarityScore;
|
|
26
|
+
this.kIncrement = input.kIncrement ?? this.kIncrement;
|
|
27
|
+
}
|
|
28
|
+
async getRelevantDocuments(query) {
|
|
29
|
+
let currentK = 0;
|
|
30
|
+
let filteredResults = [];
|
|
31
|
+
do {
|
|
32
|
+
currentK += this.kIncrement;
|
|
33
|
+
const results = await this.vectorStore.similaritySearchWithScore(query, currentK, this.filter);
|
|
34
|
+
filteredResults = results.filter(([, score]) => score >= this.minSimilarityScore);
|
|
35
|
+
} while (filteredResults.length >= currentK && currentK < this.maxK);
|
|
36
|
+
return filteredResults.map((documents) => documents[0]).slice(0, this.maxK);
|
|
37
|
+
}
|
|
38
|
+
static fromVectorStore(vectorStore, options) {
|
|
39
|
+
return new this({ ...options, vectorStore });
|
|
40
|
+
}
|
|
41
|
+
}
|
package/dist/sql_db.cjs
CHANGED
|
@@ -51,6 +51,12 @@ class SqlDatabase extends serializable_js_1.Serializable {
|
|
|
51
51
|
writable: true,
|
|
52
52
|
value: 3
|
|
53
53
|
});
|
|
54
|
+
Object.defineProperty(this, "customDescription", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
configurable: true,
|
|
57
|
+
writable: true,
|
|
58
|
+
value: void 0
|
|
59
|
+
});
|
|
54
60
|
this.appDataSource = fields.appDataSource;
|
|
55
61
|
this.appDataSourceOptions = fields.appDataSource.options;
|
|
56
62
|
if (fields?.includesTables && fields?.ignoreTables) {
|
|
@@ -60,6 +66,7 @@ class SqlDatabase extends serializable_js_1.Serializable {
|
|
|
60
66
|
this.ignoreTables = fields?.ignoreTables ?? [];
|
|
61
67
|
this.sampleRowsInTableInfo =
|
|
62
68
|
fields?.sampleRowsInTableInfo ?? this.sampleRowsInTableInfo;
|
|
69
|
+
this.customDescription = Object.fromEntries(Object.entries(fields?.customDescription ?? {}).filter(([key, _]) => this.allTables.map((table) => table.tableName).includes(key)));
|
|
63
70
|
}
|
|
64
71
|
static async fromDataSourceParams(fields) {
|
|
65
72
|
const sqlDatabase = new SqlDatabase(fields);
|
|
@@ -100,7 +107,7 @@ class SqlDatabase extends serializable_js_1.Serializable {
|
|
|
100
107
|
(0, sql_utils_js_1.verifyListTablesExistInDatabase)(this.allTables, targetTables, "Wrong target table name:");
|
|
101
108
|
selectedTables = this.allTables.filter((currentTable) => targetTables.includes(currentTable.tableName));
|
|
102
109
|
}
|
|
103
|
-
return (0, sql_utils_js_1.generateTableInfoFromTables)(selectedTables, this.appDataSource, this.sampleRowsInTableInfo);
|
|
110
|
+
return (0, sql_utils_js_1.generateTableInfoFromTables)(selectedTables, this.appDataSource, this.sampleRowsInTableInfo, this.customDescription);
|
|
104
111
|
}
|
|
105
112
|
/**
|
|
106
113
|
* Execute a SQL command and return a string representing the results.
|
package/dist/sql_db.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare class SqlDatabase extends Serializable implements SqlDatabaseOpti
|
|
|
11
11
|
includesTables: Array<string>;
|
|
12
12
|
ignoreTables: Array<string>;
|
|
13
13
|
sampleRowsInTableInfo: number;
|
|
14
|
+
customDescription?: Record<string, string>;
|
|
14
15
|
protected constructor(fields: SqlDatabaseDataSourceParams);
|
|
15
16
|
static fromDataSourceParams(fields: SqlDatabaseDataSourceParams): Promise<SqlDatabase>;
|
|
16
17
|
static fromOptionsParams(fields: SqlDatabaseOptionsParams): Promise<SqlDatabase>;
|
package/dist/sql_db.js
CHANGED
|
@@ -48,6 +48,12 @@ export class SqlDatabase extends Serializable {
|
|
|
48
48
|
writable: true,
|
|
49
49
|
value: 3
|
|
50
50
|
});
|
|
51
|
+
Object.defineProperty(this, "customDescription", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: void 0
|
|
56
|
+
});
|
|
51
57
|
this.appDataSource = fields.appDataSource;
|
|
52
58
|
this.appDataSourceOptions = fields.appDataSource.options;
|
|
53
59
|
if (fields?.includesTables && fields?.ignoreTables) {
|
|
@@ -57,6 +63,7 @@ export class SqlDatabase extends Serializable {
|
|
|
57
63
|
this.ignoreTables = fields?.ignoreTables ?? [];
|
|
58
64
|
this.sampleRowsInTableInfo =
|
|
59
65
|
fields?.sampleRowsInTableInfo ?? this.sampleRowsInTableInfo;
|
|
66
|
+
this.customDescription = Object.fromEntries(Object.entries(fields?.customDescription ?? {}).filter(([key, _]) => this.allTables.map((table) => table.tableName).includes(key)));
|
|
60
67
|
}
|
|
61
68
|
static async fromDataSourceParams(fields) {
|
|
62
69
|
const sqlDatabase = new SqlDatabase(fields);
|
|
@@ -97,7 +104,7 @@ export class SqlDatabase extends Serializable {
|
|
|
97
104
|
verifyListTablesExistInDatabase(this.allTables, targetTables, "Wrong target table name:");
|
|
98
105
|
selectedTables = this.allTables.filter((currentTable) => targetTables.includes(currentTable.tableName));
|
|
99
106
|
}
|
|
100
|
-
return generateTableInfoFromTables(selectedTables, this.appDataSource, this.sampleRowsInTableInfo);
|
|
107
|
+
return generateTableInfoFromTables(selectedTables, this.appDataSource, this.sampleRowsInTableInfo, this.customDescription);
|
|
101
108
|
}
|
|
102
109
|
/**
|
|
103
110
|
* Execute a SQL command and return a string representing the results.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongoDBChatMessageHistory = void 0;
|
|
4
|
+
const mongodb_1 = require("mongodb");
|
|
5
|
+
const index_js_1 = require("../../schema/index.cjs");
|
|
6
|
+
const utils_js_1 = require("./utils.cjs");
|
|
7
|
+
class MongoDBChatMessageHistory extends index_js_1.BaseListChatMessageHistory {
|
|
8
|
+
constructor({ collection, sessionId }) {
|
|
9
|
+
super();
|
|
10
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: ["langchain", "stores", "message", "mongodb"]
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(this, "collection", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: void 0
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "sessionId", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
this.collection = collection;
|
|
29
|
+
this.sessionId = sessionId;
|
|
30
|
+
}
|
|
31
|
+
async getMessages() {
|
|
32
|
+
const document = await this.collection.findOne({
|
|
33
|
+
_id: new mongodb_1.ObjectId(this.sessionId),
|
|
34
|
+
});
|
|
35
|
+
const messages = document?.messages || [];
|
|
36
|
+
return (0, utils_js_1.mapStoredMessagesToChatMessages)(messages);
|
|
37
|
+
}
|
|
38
|
+
async addMessage(message) {
|
|
39
|
+
const messages = (0, utils_js_1.mapChatMessagesToStoredMessages)([message]);
|
|
40
|
+
await this.collection.updateOne({ _id: new mongodb_1.ObjectId(this.sessionId) }, {
|
|
41
|
+
$push: { messages: { $each: messages } },
|
|
42
|
+
}, { upsert: true });
|
|
43
|
+
}
|
|
44
|
+
async clear() {
|
|
45
|
+
await this.collection.deleteOne({ _id: new mongodb_1.ObjectId(this.sessionId) });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.MongoDBChatMessageHistory = MongoDBChatMessageHistory;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Collection, Document as MongoDBDocument } from "mongodb";
|
|
2
|
+
import { BaseMessage, BaseListChatMessageHistory } from "../../schema/index.js";
|
|
3
|
+
export interface MongoDBChatMessageHistoryInput {
|
|
4
|
+
collection: Collection<MongoDBDocument>;
|
|
5
|
+
sessionId: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class MongoDBChatMessageHistory extends BaseListChatMessageHistory {
|
|
8
|
+
lc_namespace: string[];
|
|
9
|
+
private collection;
|
|
10
|
+
private sessionId;
|
|
11
|
+
constructor({ collection, sessionId }: MongoDBChatMessageHistoryInput);
|
|
12
|
+
getMessages(): Promise<BaseMessage[]>;
|
|
13
|
+
addMessage(message: BaseMessage): Promise<void>;
|
|
14
|
+
clear(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ObjectId } from "mongodb";
|
|
2
|
+
import { BaseListChatMessageHistory } from "../../schema/index.js";
|
|
3
|
+
import { mapChatMessagesToStoredMessages, mapStoredMessagesToChatMessages, } from "./utils.js";
|
|
4
|
+
export class MongoDBChatMessageHistory extends BaseListChatMessageHistory {
|
|
5
|
+
constructor({ collection, sessionId }) {
|
|
6
|
+
super();
|
|
7
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: ["langchain", "stores", "message", "mongodb"]
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "collection", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "sessionId", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
this.collection = collection;
|
|
26
|
+
this.sessionId = sessionId;
|
|
27
|
+
}
|
|
28
|
+
async getMessages() {
|
|
29
|
+
const document = await this.collection.findOne({
|
|
30
|
+
_id: new ObjectId(this.sessionId),
|
|
31
|
+
});
|
|
32
|
+
const messages = document?.messages || [];
|
|
33
|
+
return mapStoredMessagesToChatMessages(messages);
|
|
34
|
+
}
|
|
35
|
+
async addMessage(message) {
|
|
36
|
+
const messages = mapChatMessagesToStoredMessages([message]);
|
|
37
|
+
await this.collection.updateOne({ _id: new ObjectId(this.sessionId) }, {
|
|
38
|
+
$push: { messages: { $each: messages } },
|
|
39
|
+
}, { upsert: true });
|
|
40
|
+
}
|
|
41
|
+
async clear() {
|
|
42
|
+
await this.collection.deleteOne({ _id: new ObjectId(this.sessionId) });
|
|
43
|
+
}
|
|
44
|
+
}
|
package/dist/tools/sql.cjs
CHANGED
|
@@ -126,14 +126,20 @@ class ListTablesSqlTool extends base_js_1.Tool {
|
|
|
126
126
|
enumerable: true,
|
|
127
127
|
configurable: true,
|
|
128
128
|
writable: true,
|
|
129
|
-
value: `Input is an empty string, output is a comma
|
|
129
|
+
value: `Input is an empty string, output is a comma-separated list of tables in the database.`
|
|
130
130
|
});
|
|
131
131
|
this.db = db;
|
|
132
132
|
}
|
|
133
|
-
/** @ignore */
|
|
134
133
|
async _call(_) {
|
|
135
134
|
try {
|
|
136
|
-
|
|
135
|
+
let selectedTables = this.db.allTables;
|
|
136
|
+
if (this.db.includesTables.length > 0) {
|
|
137
|
+
selectedTables = selectedTables.filter((currentTable) => this.db.includesTables.includes(currentTable.tableName));
|
|
138
|
+
}
|
|
139
|
+
if (this.db.ignoreTables.length > 0) {
|
|
140
|
+
selectedTables = selectedTables.filter((currentTable) => !this.db.ignoreTables.includes(currentTable.tableName));
|
|
141
|
+
}
|
|
142
|
+
const tables = selectedTables.map((table) => table.tableName);
|
|
137
143
|
return tables.join(", ");
|
|
138
144
|
}
|
|
139
145
|
catch (error) {
|
package/dist/tools/sql.d.ts
CHANGED