langchain 0.0.133 → 0.0.134
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/callbacks/index.cjs +2 -1
- package/dist/callbacks/index.d.ts +1 -1
- package/dist/callbacks/index.js +1 -1
- 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/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/load/import_constants.cjs +2 -0
- package/dist/load/import_constants.js +2 -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/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/package.json +32 -1
package/dist/callbacks/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.consumeCallback = exports.awaitAllCallbacks = exports.traceAsGroup = exports.TraceGroup = exports.CallbackManagerForToolRun = exports.CallbackManagerForLLMRun = exports.CallbackManagerForChainRun = exports.CallbackManager = exports.getTracingV2CallbackHandler = exports.getTracingCallbackHandler = exports.LangChainTracerV1 = exports.LangChainTracer = exports.ConsoleCallbackHandler = exports.BaseTracer = exports.BaseCallbackHandler = void 0;
|
|
3
|
+
exports.consumeCallback = exports.awaitAllCallbacks = exports.traceAsGroup = exports.TraceGroup = exports.CallbackManagerForToolRun = exports.CallbackManagerForLLMRun = exports.CallbackManagerForChainRun = exports.CallbackManagerForRetrieverRun = exports.CallbackManager = exports.getTracingV2CallbackHandler = exports.getTracingCallbackHandler = exports.LangChainTracerV1 = exports.LangChainTracer = exports.ConsoleCallbackHandler = exports.BaseTracer = exports.BaseCallbackHandler = void 0;
|
|
4
4
|
var base_js_1 = require("./base.cjs");
|
|
5
5
|
Object.defineProperty(exports, "BaseCallbackHandler", { enumerable: true, get: function () { return base_js_1.BaseCallbackHandler; } });
|
|
6
6
|
var tracer_js_1 = require("./handlers/tracer.cjs");
|
|
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "getTracingCallbackHandler", { enumerable: true,
|
|
|
16
16
|
Object.defineProperty(exports, "getTracingV2CallbackHandler", { enumerable: true, get: function () { return initialize_js_1.getTracingV2CallbackHandler; } });
|
|
17
17
|
var manager_js_1 = require("./manager.cjs");
|
|
18
18
|
Object.defineProperty(exports, "CallbackManager", { enumerable: true, get: function () { return manager_js_1.CallbackManager; } });
|
|
19
|
+
Object.defineProperty(exports, "CallbackManagerForRetrieverRun", { enumerable: true, get: function () { return manager_js_1.CallbackManagerForRetrieverRun; } });
|
|
19
20
|
Object.defineProperty(exports, "CallbackManagerForChainRun", { enumerable: true, get: function () { return manager_js_1.CallbackManagerForChainRun; } });
|
|
20
21
|
Object.defineProperty(exports, "CallbackManagerForLLMRun", { enumerable: true, get: function () { return manager_js_1.CallbackManagerForLLMRun; } });
|
|
21
22
|
Object.defineProperty(exports, "CallbackManagerForToolRun", { enumerable: true, get: function () { return manager_js_1.CallbackManagerForToolRun; } });
|
|
@@ -4,5 +4,5 @@ export { ConsoleCallbackHandler } from "./handlers/console.js";
|
|
|
4
4
|
export { LangChainTracer } from "./handlers/tracer_langchain.js";
|
|
5
5
|
export { LangChainTracerV1 } from "./handlers/tracer_langchain_v1.js";
|
|
6
6
|
export { getTracingCallbackHandler, getTracingV2CallbackHandler, } from "./handlers/initialize.js";
|
|
7
|
-
export { CallbackManager, CallbackManagerForChainRun, CallbackManagerForLLMRun, CallbackManagerForToolRun, CallbackManagerOptions, Callbacks, TraceGroup, traceAsGroup, } from "./manager.js";
|
|
7
|
+
export { CallbackManager, CallbackManagerForRetrieverRun, CallbackManagerForChainRun, CallbackManagerForLLMRun, CallbackManagerForToolRun, CallbackManagerOptions, Callbacks, TraceGroup, traceAsGroup, } from "./manager.js";
|
|
8
8
|
export { awaitAllCallbacks, consumeCallback } from "./promises.js";
|
package/dist/callbacks/index.js
CHANGED
|
@@ -4,5 +4,5 @@ export { ConsoleCallbackHandler } from "./handlers/console.js";
|
|
|
4
4
|
export { LangChainTracer } from "./handlers/tracer_langchain.js";
|
|
5
5
|
export { LangChainTracerV1 } from "./handlers/tracer_langchain_v1.js";
|
|
6
6
|
export { getTracingCallbackHandler, getTracingV2CallbackHandler, } from "./handlers/initialize.js";
|
|
7
|
-
export { CallbackManager, CallbackManagerForChainRun, CallbackManagerForLLMRun, CallbackManagerForToolRun, TraceGroup, traceAsGroup, } from "./manager.js";
|
|
7
|
+
export { CallbackManager, CallbackManagerForRetrieverRun, CallbackManagerForChainRun, CallbackManagerForLLMRun, CallbackManagerForToolRun, TraceGroup, traceAsGroup, } from "./manager.js";
|
|
8
8
|
export { awaitAllCallbacks, consumeCallback } from "./promises.js";
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
import { PromptTemplate } from "../../prompts/prompt.js";
|
|
2
2
|
export declare const DEFAULT_SQL_DATABASE_PROMPT: PromptTemplate<{
|
|
3
3
|
input: any;
|
|
4
|
+
top_k: any;
|
|
4
5
|
dialect: any;
|
|
5
6
|
table_info: any;
|
|
6
|
-
top_k: any;
|
|
7
7
|
}, any>;
|
|
8
8
|
export declare const SQL_POSTGRES_PROMPT: PromptTemplate<{
|
|
9
9
|
input: any;
|
|
10
|
+
top_k: any;
|
|
10
11
|
dialect: any;
|
|
11
12
|
table_info: any;
|
|
12
|
-
top_k: any;
|
|
13
13
|
}, any>;
|
|
14
14
|
export declare const SQL_SQLITE_PROMPT: PromptTemplate<{
|
|
15
15
|
input: any;
|
|
16
|
+
top_k: any;
|
|
16
17
|
dialect: any;
|
|
17
18
|
table_info: any;
|
|
18
|
-
top_k: any;
|
|
19
19
|
}, any>;
|
|
20
20
|
export declare const SQL_MYSQL_PROMPT: PromptTemplate<{
|
|
21
21
|
input: any;
|
|
22
|
+
top_k: any;
|
|
22
23
|
dialect: any;
|
|
23
24
|
table_info: any;
|
|
24
|
-
top_k: any;
|
|
25
25
|
}, any>;
|
|
26
26
|
export declare const SQL_MSSQL_PROMPT: PromptTemplate<{
|
|
27
27
|
input: any;
|
|
28
|
+
top_k: any;
|
|
28
29
|
dialect: any;
|
|
29
30
|
table_info: any;
|
|
30
|
-
top_k: any;
|
|
31
31
|
}, any>;
|
|
32
32
|
export declare const SQL_SAP_HANA_PROMPT: PromptTemplate<{
|
|
33
33
|
input: any;
|
|
34
|
+
top_k: any;
|
|
34
35
|
dialect: any;
|
|
35
36
|
table_info: any;
|
|
36
|
-
top_k: any;
|
|
37
37
|
}, any>;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecursiveUrlLoader = void 0;
|
|
4
|
+
const jsdom_1 = require("jsdom");
|
|
5
|
+
const async_caller_js_1 = require("../../util/async_caller.cjs");
|
|
6
|
+
const base_js_1 = require("../base.cjs");
|
|
7
|
+
class RecursiveUrlLoader extends base_js_1.BaseDocumentLoader {
|
|
8
|
+
constructor(url, options) {
|
|
9
|
+
super();
|
|
10
|
+
Object.defineProperty(this, "caller", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: void 0
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(this, "url", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: void 0
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "excludeDirs", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "extractor", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: void 0
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "maxDepth", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: void 0
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "timeout", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "preventOutside", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: void 0
|
|
51
|
+
});
|
|
52
|
+
this.caller = new async_caller_js_1.AsyncCaller({
|
|
53
|
+
maxConcurrency: 64,
|
|
54
|
+
maxRetries: 0,
|
|
55
|
+
...options.callerOptions,
|
|
56
|
+
});
|
|
57
|
+
this.url = url;
|
|
58
|
+
this.excludeDirs = options.excludeDirs ?? [];
|
|
59
|
+
this.extractor = options.extractor ?? ((s) => s);
|
|
60
|
+
this.maxDepth = options.maxDepth ?? 2;
|
|
61
|
+
this.timeout = options.timeout ?? 10000;
|
|
62
|
+
this.preventOutside = options.preventOutside ?? true;
|
|
63
|
+
}
|
|
64
|
+
async fetchWithTimeout(resource, options) {
|
|
65
|
+
const { timeout, ...rest } = options;
|
|
66
|
+
return this.caller.call(() => fetch(resource, { ...rest, signal: AbortSignal.timeout(timeout) }));
|
|
67
|
+
}
|
|
68
|
+
getChildLinks(html, baseUrl) {
|
|
69
|
+
const allLinks = Array.from(new jsdom_1.JSDOM(html).window.document.querySelectorAll("a")).map((a) => a.href);
|
|
70
|
+
const absolutePaths = [];
|
|
71
|
+
// eslint-disable-next-line no-script-url
|
|
72
|
+
const invalidPrefixes = ["javascript:", "mailto:", "#"];
|
|
73
|
+
const invalidSuffixes = [
|
|
74
|
+
".css",
|
|
75
|
+
".js",
|
|
76
|
+
".ico",
|
|
77
|
+
".png",
|
|
78
|
+
".jpg",
|
|
79
|
+
".jpeg",
|
|
80
|
+
".gif",
|
|
81
|
+
".svg",
|
|
82
|
+
];
|
|
83
|
+
for (const link of allLinks) {
|
|
84
|
+
if (invalidPrefixes.some((prefix) => link.startsWith(prefix)) ||
|
|
85
|
+
invalidSuffixes.some((suffix) => link.endsWith(suffix)))
|
|
86
|
+
continue;
|
|
87
|
+
if (link.startsWith("http")) {
|
|
88
|
+
const isAllowed = !this.preventOutside || link.startsWith(baseUrl);
|
|
89
|
+
if (isAllowed)
|
|
90
|
+
absolutePaths.push(link);
|
|
91
|
+
}
|
|
92
|
+
else if (link.startsWith("//")) {
|
|
93
|
+
const base = new URL(baseUrl);
|
|
94
|
+
absolutePaths.push(base.protocol + link);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const newLink = new URL(link, baseUrl).href;
|
|
98
|
+
absolutePaths.push(newLink);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return Array.from(new Set(absolutePaths));
|
|
102
|
+
}
|
|
103
|
+
extractMetadata(rawHtml, url) {
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
|
+
const metadata = { source: url };
|
|
106
|
+
const { document } = new jsdom_1.JSDOM(rawHtml).window;
|
|
107
|
+
const title = document.getElementsByTagName("title")[0];
|
|
108
|
+
if (title) {
|
|
109
|
+
metadata.title = title.textContent;
|
|
110
|
+
}
|
|
111
|
+
const description = document.querySelector("meta[name=description]");
|
|
112
|
+
if (description) {
|
|
113
|
+
metadata.description = description.getAttribute("content");
|
|
114
|
+
}
|
|
115
|
+
const html = document.getElementsByTagName("html")[0];
|
|
116
|
+
if (html) {
|
|
117
|
+
metadata.language = html.getAttribute("lang");
|
|
118
|
+
}
|
|
119
|
+
return metadata;
|
|
120
|
+
}
|
|
121
|
+
async getUrlAsDoc(url) {
|
|
122
|
+
let res;
|
|
123
|
+
try {
|
|
124
|
+
res = await this.fetchWithTimeout(url, { timeout: this.timeout });
|
|
125
|
+
res = await res.text();
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
pageContent: this.extractor(res),
|
|
132
|
+
metadata: this.extractMetadata(res, url),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
async getChildUrlsRecursive(inputUrl, visited = new Set(), depth = 0) {
|
|
136
|
+
if (depth > this.maxDepth)
|
|
137
|
+
return [];
|
|
138
|
+
let url = inputUrl;
|
|
139
|
+
if (!inputUrl.endsWith("/"))
|
|
140
|
+
url += "/";
|
|
141
|
+
const isExcluded = this.excludeDirs.some((exDir) => url.startsWith(exDir));
|
|
142
|
+
if (isExcluded)
|
|
143
|
+
return [];
|
|
144
|
+
let res;
|
|
145
|
+
try {
|
|
146
|
+
res = await this.fetchWithTimeout(url, { timeout: this.timeout });
|
|
147
|
+
res = await res.text();
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
const childUrls = this.getChildLinks(res, url);
|
|
153
|
+
const results = await Promise.all(childUrls.map((childUrl) => (async () => {
|
|
154
|
+
if (visited.has(childUrl))
|
|
155
|
+
return null;
|
|
156
|
+
visited.add(childUrl);
|
|
157
|
+
const childDoc = await this.getUrlAsDoc(childUrl);
|
|
158
|
+
if (!childDoc)
|
|
159
|
+
return null;
|
|
160
|
+
if (childUrl.endsWith("/")) {
|
|
161
|
+
const childUrlResponses = await this.getChildUrlsRecursive(childUrl, visited, depth + 1);
|
|
162
|
+
return [childDoc, ...childUrlResponses];
|
|
163
|
+
}
|
|
164
|
+
return [childDoc];
|
|
165
|
+
})()));
|
|
166
|
+
return results.flat().filter((docs) => docs !== null);
|
|
167
|
+
}
|
|
168
|
+
async load() {
|
|
169
|
+
const rootDoc = await this.getUrlAsDoc(this.url);
|
|
170
|
+
if (!rootDoc)
|
|
171
|
+
return [];
|
|
172
|
+
const docs = [rootDoc];
|
|
173
|
+
docs.push(...(await this.getChildUrlsRecursive(this.url, new Set([this.url]))));
|
|
174
|
+
return docs;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.RecursiveUrlLoader = RecursiveUrlLoader;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Document } from "../../document.js";
|
|
2
|
+
import { AsyncCaller } from "../../util/async_caller.js";
|
|
3
|
+
import { BaseDocumentLoader, DocumentLoader } from "../base.js";
|
|
4
|
+
export interface RecursiveUrlLoaderOptions {
|
|
5
|
+
excludeDirs?: string[];
|
|
6
|
+
extractor?: (text: string) => string;
|
|
7
|
+
maxDepth?: number;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
preventOutside?: boolean;
|
|
10
|
+
callerOptions?: ConstructorParameters<typeof AsyncCaller>[0];
|
|
11
|
+
}
|
|
12
|
+
export declare class RecursiveUrlLoader extends BaseDocumentLoader implements DocumentLoader {
|
|
13
|
+
private caller;
|
|
14
|
+
private url;
|
|
15
|
+
private excludeDirs;
|
|
16
|
+
private extractor;
|
|
17
|
+
private maxDepth;
|
|
18
|
+
private timeout;
|
|
19
|
+
private preventOutside;
|
|
20
|
+
constructor(url: string, options: RecursiveUrlLoaderOptions);
|
|
21
|
+
private fetchWithTimeout;
|
|
22
|
+
private getChildLinks;
|
|
23
|
+
private extractMetadata;
|
|
24
|
+
private getUrlAsDoc;
|
|
25
|
+
private getChildUrlsRecursive;
|
|
26
|
+
load(): Promise<Document[]>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { JSDOM } from "jsdom";
|
|
2
|
+
import { AsyncCaller } from "../../util/async_caller.js";
|
|
3
|
+
import { BaseDocumentLoader } from "../base.js";
|
|
4
|
+
export class RecursiveUrlLoader extends BaseDocumentLoader {
|
|
5
|
+
constructor(url, options) {
|
|
6
|
+
super();
|
|
7
|
+
Object.defineProperty(this, "caller", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: void 0
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "url", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "excludeDirs", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "extractor", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(this, "maxDepth", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: void 0
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "timeout", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: void 0
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(this, "preventOutside", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
writable: true,
|
|
47
|
+
value: void 0
|
|
48
|
+
});
|
|
49
|
+
this.caller = new AsyncCaller({
|
|
50
|
+
maxConcurrency: 64,
|
|
51
|
+
maxRetries: 0,
|
|
52
|
+
...options.callerOptions,
|
|
53
|
+
});
|
|
54
|
+
this.url = url;
|
|
55
|
+
this.excludeDirs = options.excludeDirs ?? [];
|
|
56
|
+
this.extractor = options.extractor ?? ((s) => s);
|
|
57
|
+
this.maxDepth = options.maxDepth ?? 2;
|
|
58
|
+
this.timeout = options.timeout ?? 10000;
|
|
59
|
+
this.preventOutside = options.preventOutside ?? true;
|
|
60
|
+
}
|
|
61
|
+
async fetchWithTimeout(resource, options) {
|
|
62
|
+
const { timeout, ...rest } = options;
|
|
63
|
+
return this.caller.call(() => fetch(resource, { ...rest, signal: AbortSignal.timeout(timeout) }));
|
|
64
|
+
}
|
|
65
|
+
getChildLinks(html, baseUrl) {
|
|
66
|
+
const allLinks = Array.from(new JSDOM(html).window.document.querySelectorAll("a")).map((a) => a.href);
|
|
67
|
+
const absolutePaths = [];
|
|
68
|
+
// eslint-disable-next-line no-script-url
|
|
69
|
+
const invalidPrefixes = ["javascript:", "mailto:", "#"];
|
|
70
|
+
const invalidSuffixes = [
|
|
71
|
+
".css",
|
|
72
|
+
".js",
|
|
73
|
+
".ico",
|
|
74
|
+
".png",
|
|
75
|
+
".jpg",
|
|
76
|
+
".jpeg",
|
|
77
|
+
".gif",
|
|
78
|
+
".svg",
|
|
79
|
+
];
|
|
80
|
+
for (const link of allLinks) {
|
|
81
|
+
if (invalidPrefixes.some((prefix) => link.startsWith(prefix)) ||
|
|
82
|
+
invalidSuffixes.some((suffix) => link.endsWith(suffix)))
|
|
83
|
+
continue;
|
|
84
|
+
if (link.startsWith("http")) {
|
|
85
|
+
const isAllowed = !this.preventOutside || link.startsWith(baseUrl);
|
|
86
|
+
if (isAllowed)
|
|
87
|
+
absolutePaths.push(link);
|
|
88
|
+
}
|
|
89
|
+
else if (link.startsWith("//")) {
|
|
90
|
+
const base = new URL(baseUrl);
|
|
91
|
+
absolutePaths.push(base.protocol + link);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const newLink = new URL(link, baseUrl).href;
|
|
95
|
+
absolutePaths.push(newLink);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return Array.from(new Set(absolutePaths));
|
|
99
|
+
}
|
|
100
|
+
extractMetadata(rawHtml, url) {
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
|
+
const metadata = { source: url };
|
|
103
|
+
const { document } = new JSDOM(rawHtml).window;
|
|
104
|
+
const title = document.getElementsByTagName("title")[0];
|
|
105
|
+
if (title) {
|
|
106
|
+
metadata.title = title.textContent;
|
|
107
|
+
}
|
|
108
|
+
const description = document.querySelector("meta[name=description]");
|
|
109
|
+
if (description) {
|
|
110
|
+
metadata.description = description.getAttribute("content");
|
|
111
|
+
}
|
|
112
|
+
const html = document.getElementsByTagName("html")[0];
|
|
113
|
+
if (html) {
|
|
114
|
+
metadata.language = html.getAttribute("lang");
|
|
115
|
+
}
|
|
116
|
+
return metadata;
|
|
117
|
+
}
|
|
118
|
+
async getUrlAsDoc(url) {
|
|
119
|
+
let res;
|
|
120
|
+
try {
|
|
121
|
+
res = await this.fetchWithTimeout(url, { timeout: this.timeout });
|
|
122
|
+
res = await res.text();
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
pageContent: this.extractor(res),
|
|
129
|
+
metadata: this.extractMetadata(res, url),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async getChildUrlsRecursive(inputUrl, visited = new Set(), depth = 0) {
|
|
133
|
+
if (depth > this.maxDepth)
|
|
134
|
+
return [];
|
|
135
|
+
let url = inputUrl;
|
|
136
|
+
if (!inputUrl.endsWith("/"))
|
|
137
|
+
url += "/";
|
|
138
|
+
const isExcluded = this.excludeDirs.some((exDir) => url.startsWith(exDir));
|
|
139
|
+
if (isExcluded)
|
|
140
|
+
return [];
|
|
141
|
+
let res;
|
|
142
|
+
try {
|
|
143
|
+
res = await this.fetchWithTimeout(url, { timeout: this.timeout });
|
|
144
|
+
res = await res.text();
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
const childUrls = this.getChildLinks(res, url);
|
|
150
|
+
const results = await Promise.all(childUrls.map((childUrl) => (async () => {
|
|
151
|
+
if (visited.has(childUrl))
|
|
152
|
+
return null;
|
|
153
|
+
visited.add(childUrl);
|
|
154
|
+
const childDoc = await this.getUrlAsDoc(childUrl);
|
|
155
|
+
if (!childDoc)
|
|
156
|
+
return null;
|
|
157
|
+
if (childUrl.endsWith("/")) {
|
|
158
|
+
const childUrlResponses = await this.getChildUrlsRecursive(childUrl, visited, depth + 1);
|
|
159
|
+
return [childDoc, ...childUrlResponses];
|
|
160
|
+
}
|
|
161
|
+
return [childDoc];
|
|
162
|
+
})()));
|
|
163
|
+
return results.flat().filter((docs) => docs !== null);
|
|
164
|
+
}
|
|
165
|
+
async load() {
|
|
166
|
+
const rootDoc = await this.getUrlAsDoc(this.url);
|
|
167
|
+
if (!rootDoc)
|
|
168
|
+
return [];
|
|
169
|
+
const docs = [rootDoc];
|
|
170
|
+
docs.push(...(await this.getChildUrlsRecursive(this.url, new Set([this.url]))));
|
|
171
|
+
return docs;
|
|
172
|
+
}
|
|
173
|
+
}
|
package/dist/hub.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pull = exports.push = void 0;
|
|
4
|
+
const langchainhub_1 = require("langchainhub");
|
|
5
|
+
const index_js_1 = require("./load/index.cjs");
|
|
6
|
+
async function push(repoFullName, runnable, options) {
|
|
7
|
+
const client = new langchainhub_1.Client(options);
|
|
8
|
+
return client.push(repoFullName, JSON.stringify(runnable), options);
|
|
9
|
+
}
|
|
10
|
+
exports.push = push;
|
|
11
|
+
async function pull(ownerRepoCommit, options) {
|
|
12
|
+
const client = new langchainhub_1.Client(options);
|
|
13
|
+
const result = await client.pull(ownerRepoCommit);
|
|
14
|
+
return (0, index_js_1.load)(result);
|
|
15
|
+
}
|
|
16
|
+
exports.pull = pull;
|
package/dist/hub.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ClientConfiguration, HubPushOptions } from "langchainhub";
|
|
2
|
+
import { Runnable } from "./schema/runnable.js";
|
|
3
|
+
export declare function push(repoFullName: string, runnable: Runnable, options?: HubPushOptions & ClientConfiguration): Promise<any>;
|
|
4
|
+
export declare function pull<T extends Runnable>(ownerRepoCommit: string, options?: ClientConfiguration): Promise<T>;
|
package/dist/hub.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Client } from "langchainhub";
|
|
2
|
+
import { load } from "./load/index.js";
|
|
3
|
+
export async function push(repoFullName, runnable, options) {
|
|
4
|
+
const client = new Client(options);
|
|
5
|
+
return client.push(repoFullName, JSON.stringify(runnable), options);
|
|
6
|
+
}
|
|
7
|
+
export async function pull(ownerRepoCommit, options) {
|
|
8
|
+
const client = new Client(options);
|
|
9
|
+
const result = await client.pull(ownerRepoCommit);
|
|
10
|
+
return load(result);
|
|
11
|
+
}
|
package/dist/llms/bedrock.cjs
CHANGED
|
@@ -4,9 +4,12 @@ exports.Bedrock = void 0;
|
|
|
4
4
|
const signature_v4_1 = require("@aws-sdk/signature-v4");
|
|
5
5
|
const credential_provider_node_1 = require("@aws-sdk/credential-provider-node");
|
|
6
6
|
const protocol_http_1 = require("@aws-sdk/protocol-http");
|
|
7
|
+
const eventstream_codec_1 = require("@smithy/eventstream-codec");
|
|
8
|
+
const util_utf8_1 = require("@smithy/util-utf8");
|
|
7
9
|
const sha256_js_1 = require("@aws-crypto/sha256-js");
|
|
8
10
|
const env_js_1 = require("../util/env.cjs");
|
|
9
11
|
const base_js_1 = require("./base.cjs");
|
|
12
|
+
const index_js_1 = require("../schema/index.cjs");
|
|
10
13
|
/**
|
|
11
14
|
* A helper class used within the `Bedrock` class. It is responsible for
|
|
12
15
|
* preparing the input and output for the Bedrock service. It formats the
|
|
@@ -17,20 +20,24 @@ class BedrockLLMInputOutputAdapter {
|
|
|
17
20
|
/** Adapter class to prepare the inputs from Langchain to a format
|
|
18
21
|
that LLM model expects. Also, provides a helper function to extract
|
|
19
22
|
the generated text from the model response. */
|
|
20
|
-
static prepareInput(provider, prompt) {
|
|
23
|
+
static prepareInput(provider, prompt, maxTokens = 50, temperature = 0) {
|
|
21
24
|
const inputBody = {};
|
|
22
|
-
if (provider === "anthropic"
|
|
25
|
+
if (provider === "anthropic") {
|
|
23
26
|
inputBody.prompt = prompt;
|
|
27
|
+
inputBody.max_tokens_to_sample = maxTokens;
|
|
28
|
+
inputBody.temperature = temperature;
|
|
24
29
|
}
|
|
25
|
-
else if (provider === "
|
|
26
|
-
inputBody.
|
|
27
|
-
inputBody.
|
|
30
|
+
else if (provider === "ai21") {
|
|
31
|
+
inputBody.prompt = prompt;
|
|
32
|
+
inputBody.maxTokens = maxTokens;
|
|
33
|
+
inputBody.temperature = temperature;
|
|
28
34
|
}
|
|
29
|
-
else {
|
|
35
|
+
else if (provider === "amazon") {
|
|
30
36
|
inputBody.inputText = prompt;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
inputBody.textGenerationConfig = {
|
|
38
|
+
maxTokenCount: maxTokens,
|
|
39
|
+
temperature,
|
|
40
|
+
};
|
|
34
41
|
}
|
|
35
42
|
return inputBody;
|
|
36
43
|
}
|
|
@@ -46,9 +53,9 @@ class BedrockLLMInputOutputAdapter {
|
|
|
46
53
|
return responseBody.completion;
|
|
47
54
|
}
|
|
48
55
|
else if (provider === "ai21") {
|
|
49
|
-
return responseBody.
|
|
56
|
+
return responseBody.data.text;
|
|
50
57
|
}
|
|
51
|
-
return responseBody.
|
|
58
|
+
return responseBody.outputText;
|
|
52
59
|
}
|
|
53
60
|
}
|
|
54
61
|
/**
|
|
@@ -105,6 +112,12 @@ class Bedrock extends base_js_1.LLM {
|
|
|
105
112
|
writable: true,
|
|
106
113
|
value: void 0
|
|
107
114
|
});
|
|
115
|
+
Object.defineProperty(this, "codec", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
configurable: true,
|
|
118
|
+
writable: true,
|
|
119
|
+
value: new eventstream_codec_1.EventStreamCodec(util_utf8_1.toUtf8, util_utf8_1.fromUtf8)
|
|
120
|
+
});
|
|
108
121
|
this.model = fields?.model ?? this.model;
|
|
109
122
|
const allowedModels = ["ai21", "anthropic", "amazon"];
|
|
110
123
|
if (!allowedModels.includes(this.model.split(".")[0])) {
|
|
@@ -130,11 +143,18 @@ class Bedrock extends base_js_1.LLM {
|
|
|
130
143
|
Example:
|
|
131
144
|
response = model.call("Tell me a joke.")
|
|
132
145
|
*/
|
|
133
|
-
async _call(prompt) {
|
|
146
|
+
async _call(prompt, options, runManager) {
|
|
147
|
+
const chunks = [];
|
|
148
|
+
for await (const chunk of this._streamResponseChunks(prompt, options, runManager)) {
|
|
149
|
+
chunks.push(chunk);
|
|
150
|
+
}
|
|
151
|
+
return chunks.map((chunk) => chunk.text).join("");
|
|
152
|
+
}
|
|
153
|
+
async *_streamResponseChunks(prompt, options, runManager) {
|
|
134
154
|
const provider = this.model.split(".")[0];
|
|
135
155
|
const service = "bedrock";
|
|
136
|
-
const inputBody = BedrockLLMInputOutputAdapter.prepareInput(provider, prompt);
|
|
137
|
-
const url = new URL(`https://${service}.${this.region}.amazonaws.com/model/${this.model}/invoke`);
|
|
156
|
+
const inputBody = BedrockLLMInputOutputAdapter.prepareInput(provider, prompt, this.maxTokens, this.temperature);
|
|
157
|
+
const url = new URL(`https://${service}.${this.region}.amazonaws.com/model/${this.model}/invoke-with-response-stream`);
|
|
138
158
|
const request = new protocol_http_1.HttpRequest({
|
|
139
159
|
hostname: url.hostname,
|
|
140
160
|
path: url.pathname,
|
|
@@ -157,17 +177,41 @@ class Bedrock extends base_js_1.LLM {
|
|
|
157
177
|
});
|
|
158
178
|
const signedRequest = await signer.sign(request);
|
|
159
179
|
// Send request to AWS using the low-level fetch API
|
|
160
|
-
const response = await this.fetchFn(url, {
|
|
180
|
+
const response = await this.caller.callWithOptions({ signal: options.signal }, async () => this.fetchFn(url, {
|
|
161
181
|
headers: signedRequest.headers,
|
|
162
182
|
body: signedRequest.body,
|
|
163
183
|
method: signedRequest.method,
|
|
164
|
-
});
|
|
184
|
+
}));
|
|
165
185
|
if (response.status < 200 || response.status >= 300) {
|
|
166
186
|
throw Error(`Failed to access underlying url '${url}': got ${response.status} ${response.statusText}: ${await response.text()}`);
|
|
167
187
|
}
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
|
|
188
|
+
const reader = response.body?.getReader();
|
|
189
|
+
for await (const chunk of this._readChunks(reader)) {
|
|
190
|
+
const event = this.codec.decode(chunk);
|
|
191
|
+
if (event.headers[":event-type"].value !== "chunk" ||
|
|
192
|
+
event.headers[":content-type"].value !== "application/json") {
|
|
193
|
+
throw Error(`Failed to get event chunk: got ${chunk}`);
|
|
194
|
+
}
|
|
195
|
+
const body = JSON.parse(Buffer.from(JSON.parse(new TextDecoder("utf-8").decode(event.body)).bytes, "base64").toString());
|
|
196
|
+
const text = BedrockLLMInputOutputAdapter.prepareOutput(provider, body);
|
|
197
|
+
yield new index_js_1.GenerationChunk({
|
|
198
|
+
text,
|
|
199
|
+
generationInfo: {},
|
|
200
|
+
});
|
|
201
|
+
await runManager?.handleLLMNewToken(text);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
205
|
+
_readChunks(reader) {
|
|
206
|
+
return {
|
|
207
|
+
async *[Symbol.asyncIterator]() {
|
|
208
|
+
let readResult = await reader.read();
|
|
209
|
+
while (!readResult.done) {
|
|
210
|
+
yield readResult.value;
|
|
211
|
+
readResult = await reader.read();
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
};
|
|
171
215
|
}
|
|
172
216
|
}
|
|
173
217
|
exports.Bedrock = Bedrock;
|
package/dist/llms/bedrock.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { EventStreamCodec } from "@smithy/eventstream-codec";
|
|
1
2
|
import type { AwsCredentialIdentity, Provider } from "@aws-sdk/types";
|
|
2
3
|
import { LLM, BaseLLMParams } from "./base.js";
|
|
4
|
+
import { CallbackManagerForLLMRun } from "../callbacks/manager.js";
|
|
5
|
+
import { GenerationChunk } from "../schema/index.js";
|
|
3
6
|
type CredentialType = AwsCredentialIdentity | Provider<AwsCredentialIdentity>;
|
|
4
7
|
/** Bedrock models.
|
|
5
8
|
To authenticate, the AWS client uses the following methods to automatically load credentials:
|
|
@@ -43,6 +46,7 @@ export declare class Bedrock extends LLM implements BedrockInput {
|
|
|
43
46
|
temperature?: number | undefined;
|
|
44
47
|
maxTokens?: number | undefined;
|
|
45
48
|
fetchFn: typeof fetch;
|
|
49
|
+
codec: EventStreamCodec;
|
|
46
50
|
get lc_secrets(): {
|
|
47
51
|
[key: string]: string;
|
|
48
52
|
} | undefined;
|
|
@@ -58,6 +62,10 @@ export declare class Bedrock extends LLM implements BedrockInput {
|
|
|
58
62
|
Example:
|
|
59
63
|
response = model.call("Tell me a joke.")
|
|
60
64
|
*/
|
|
61
|
-
_call(prompt: string): Promise<string>;
|
|
65
|
+
_call(prompt: string, options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<string>;
|
|
66
|
+
_streamResponseChunks(prompt: string, options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<GenerationChunk>;
|
|
67
|
+
_readChunks(reader: any): {
|
|
68
|
+
[Symbol.asyncIterator](): AsyncGenerator<any, void, unknown>;
|
|
69
|
+
};
|
|
62
70
|
}
|
|
63
71
|
export {};
|
package/dist/llms/bedrock.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { SignatureV4 } from "@aws-sdk/signature-v4";
|
|
2
2
|
import { defaultProvider } from "@aws-sdk/credential-provider-node";
|
|
3
3
|
import { HttpRequest } from "@aws-sdk/protocol-http";
|
|
4
|
+
import { EventStreamCodec } from "@smithy/eventstream-codec";
|
|
5
|
+
import { fromUtf8, toUtf8 } from "@smithy/util-utf8";
|
|
4
6
|
import { Sha256 } from "@aws-crypto/sha256-js";
|
|
5
7
|
import { getEnvironmentVariable } from "../util/env.js";
|
|
6
8
|
import { LLM } from "./base.js";
|
|
9
|
+
import { GenerationChunk } from "../schema/index.js";
|
|
7
10
|
/**
|
|
8
11
|
* A helper class used within the `Bedrock` class. It is responsible for
|
|
9
12
|
* preparing the input and output for the Bedrock service. It formats the
|
|
@@ -14,20 +17,24 @@ class BedrockLLMInputOutputAdapter {
|
|
|
14
17
|
/** Adapter class to prepare the inputs from Langchain to a format
|
|
15
18
|
that LLM model expects. Also, provides a helper function to extract
|
|
16
19
|
the generated text from the model response. */
|
|
17
|
-
static prepareInput(provider, prompt) {
|
|
20
|
+
static prepareInput(provider, prompt, maxTokens = 50, temperature = 0) {
|
|
18
21
|
const inputBody = {};
|
|
19
|
-
if (provider === "anthropic"
|
|
22
|
+
if (provider === "anthropic") {
|
|
20
23
|
inputBody.prompt = prompt;
|
|
24
|
+
inputBody.max_tokens_to_sample = maxTokens;
|
|
25
|
+
inputBody.temperature = temperature;
|
|
21
26
|
}
|
|
22
|
-
else if (provider === "
|
|
23
|
-
inputBody.
|
|
24
|
-
inputBody.
|
|
27
|
+
else if (provider === "ai21") {
|
|
28
|
+
inputBody.prompt = prompt;
|
|
29
|
+
inputBody.maxTokens = maxTokens;
|
|
30
|
+
inputBody.temperature = temperature;
|
|
25
31
|
}
|
|
26
|
-
else {
|
|
32
|
+
else if (provider === "amazon") {
|
|
27
33
|
inputBody.inputText = prompt;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
inputBody.textGenerationConfig = {
|
|
35
|
+
maxTokenCount: maxTokens,
|
|
36
|
+
temperature,
|
|
37
|
+
};
|
|
31
38
|
}
|
|
32
39
|
return inputBody;
|
|
33
40
|
}
|
|
@@ -43,9 +50,9 @@ class BedrockLLMInputOutputAdapter {
|
|
|
43
50
|
return responseBody.completion;
|
|
44
51
|
}
|
|
45
52
|
else if (provider === "ai21") {
|
|
46
|
-
return responseBody.
|
|
53
|
+
return responseBody.data.text;
|
|
47
54
|
}
|
|
48
|
-
return responseBody.
|
|
55
|
+
return responseBody.outputText;
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
58
|
/**
|
|
@@ -102,6 +109,12 @@ export class Bedrock extends LLM {
|
|
|
102
109
|
writable: true,
|
|
103
110
|
value: void 0
|
|
104
111
|
});
|
|
112
|
+
Object.defineProperty(this, "codec", {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
configurable: true,
|
|
115
|
+
writable: true,
|
|
116
|
+
value: new EventStreamCodec(toUtf8, fromUtf8)
|
|
117
|
+
});
|
|
105
118
|
this.model = fields?.model ?? this.model;
|
|
106
119
|
const allowedModels = ["ai21", "anthropic", "amazon"];
|
|
107
120
|
if (!allowedModels.includes(this.model.split(".")[0])) {
|
|
@@ -127,11 +140,18 @@ export class Bedrock extends LLM {
|
|
|
127
140
|
Example:
|
|
128
141
|
response = model.call("Tell me a joke.")
|
|
129
142
|
*/
|
|
130
|
-
async _call(prompt) {
|
|
143
|
+
async _call(prompt, options, runManager) {
|
|
144
|
+
const chunks = [];
|
|
145
|
+
for await (const chunk of this._streamResponseChunks(prompt, options, runManager)) {
|
|
146
|
+
chunks.push(chunk);
|
|
147
|
+
}
|
|
148
|
+
return chunks.map((chunk) => chunk.text).join("");
|
|
149
|
+
}
|
|
150
|
+
async *_streamResponseChunks(prompt, options, runManager) {
|
|
131
151
|
const provider = this.model.split(".")[0];
|
|
132
152
|
const service = "bedrock";
|
|
133
|
-
const inputBody = BedrockLLMInputOutputAdapter.prepareInput(provider, prompt);
|
|
134
|
-
const url = new URL(`https://${service}.${this.region}.amazonaws.com/model/${this.model}/invoke`);
|
|
153
|
+
const inputBody = BedrockLLMInputOutputAdapter.prepareInput(provider, prompt, this.maxTokens, this.temperature);
|
|
154
|
+
const url = new URL(`https://${service}.${this.region}.amazonaws.com/model/${this.model}/invoke-with-response-stream`);
|
|
135
155
|
const request = new HttpRequest({
|
|
136
156
|
hostname: url.hostname,
|
|
137
157
|
path: url.pathname,
|
|
@@ -154,16 +174,40 @@ export class Bedrock extends LLM {
|
|
|
154
174
|
});
|
|
155
175
|
const signedRequest = await signer.sign(request);
|
|
156
176
|
// Send request to AWS using the low-level fetch API
|
|
157
|
-
const response = await this.fetchFn(url, {
|
|
177
|
+
const response = await this.caller.callWithOptions({ signal: options.signal }, async () => this.fetchFn(url, {
|
|
158
178
|
headers: signedRequest.headers,
|
|
159
179
|
body: signedRequest.body,
|
|
160
180
|
method: signedRequest.method,
|
|
161
|
-
});
|
|
181
|
+
}));
|
|
162
182
|
if (response.status < 200 || response.status >= 300) {
|
|
163
183
|
throw Error(`Failed to access underlying url '${url}': got ${response.status} ${response.statusText}: ${await response.text()}`);
|
|
164
184
|
}
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
|
|
185
|
+
const reader = response.body?.getReader();
|
|
186
|
+
for await (const chunk of this._readChunks(reader)) {
|
|
187
|
+
const event = this.codec.decode(chunk);
|
|
188
|
+
if (event.headers[":event-type"].value !== "chunk" ||
|
|
189
|
+
event.headers[":content-type"].value !== "application/json") {
|
|
190
|
+
throw Error(`Failed to get event chunk: got ${chunk}`);
|
|
191
|
+
}
|
|
192
|
+
const body = JSON.parse(Buffer.from(JSON.parse(new TextDecoder("utf-8").decode(event.body)).bytes, "base64").toString());
|
|
193
|
+
const text = BedrockLLMInputOutputAdapter.prepareOutput(provider, body);
|
|
194
|
+
yield new GenerationChunk({
|
|
195
|
+
text,
|
|
196
|
+
generationInfo: {},
|
|
197
|
+
});
|
|
198
|
+
await runManager?.handleLLMNewToken(text);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
202
|
+
_readChunks(reader) {
|
|
203
|
+
return {
|
|
204
|
+
async *[Symbol.asyncIterator]() {
|
|
205
|
+
let readResult = await reader.read();
|
|
206
|
+
while (!readResult.done) {
|
|
207
|
+
yield readResult.value;
|
|
208
|
+
readResult = await reader.read();
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
};
|
|
168
212
|
}
|
|
169
213
|
}
|
|
@@ -69,6 +69,7 @@ exports.optionalImportEntrypoints = [
|
|
|
69
69
|
"langchain/document_loaders/web/github",
|
|
70
70
|
"langchain/document_loaders/web/notiondb",
|
|
71
71
|
"langchain/document_loaders/web/notionapi",
|
|
72
|
+
"langchain/document_loaders/web/recursive_url",
|
|
72
73
|
"langchain/document_loaders/web/s3",
|
|
73
74
|
"langchain/document_loaders/web/sonix_audio",
|
|
74
75
|
"langchain/document_loaders/web/confluence",
|
|
@@ -115,5 +116,6 @@ exports.optionalImportEntrypoints = [
|
|
|
115
116
|
"langchain/stores/message/planetscale",
|
|
116
117
|
"langchain/stores/message/xata",
|
|
117
118
|
"langchain/storage/ioredis",
|
|
119
|
+
"langchain/hub",
|
|
118
120
|
"langchain/experimental/multimodal_embeddings/googlevertexai",
|
|
119
121
|
];
|
|
@@ -66,6 +66,7 @@ export const optionalImportEntrypoints = [
|
|
|
66
66
|
"langchain/document_loaders/web/github",
|
|
67
67
|
"langchain/document_loaders/web/notiondb",
|
|
68
68
|
"langchain/document_loaders/web/notionapi",
|
|
69
|
+
"langchain/document_loaders/web/recursive_url",
|
|
69
70
|
"langchain/document_loaders/web/s3",
|
|
70
71
|
"langchain/document_loaders/web/sonix_audio",
|
|
71
72
|
"langchain/document_loaders/web/confluence",
|
|
@@ -112,5 +113,6 @@ export const optionalImportEntrypoints = [
|
|
|
112
113
|
"langchain/stores/message/planetscale",
|
|
113
114
|
"langchain/stores/message/xata",
|
|
114
115
|
"langchain/storage/ioredis",
|
|
116
|
+
"langchain/hub",
|
|
115
117
|
"langchain/experimental/multimodal_embeddings/googlevertexai",
|
|
116
118
|
];
|
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
package/dist/tools/sql.js
CHANGED
|
@@ -121,14 +121,20 @@ export class ListTablesSqlTool extends Tool {
|
|
|
121
121
|
enumerable: true,
|
|
122
122
|
configurable: true,
|
|
123
123
|
writable: true,
|
|
124
|
-
value: `Input is an empty string, output is a comma
|
|
124
|
+
value: `Input is an empty string, output is a comma-separated list of tables in the database.`
|
|
125
125
|
});
|
|
126
126
|
this.db = db;
|
|
127
127
|
}
|
|
128
|
-
/** @ignore */
|
|
129
128
|
async _call(_) {
|
|
130
129
|
try {
|
|
131
|
-
|
|
130
|
+
let selectedTables = this.db.allTables;
|
|
131
|
+
if (this.db.includesTables.length > 0) {
|
|
132
|
+
selectedTables = selectedTables.filter((currentTable) => this.db.includesTables.includes(currentTable.tableName));
|
|
133
|
+
}
|
|
134
|
+
if (this.db.ignoreTables.length > 0) {
|
|
135
|
+
selectedTables = selectedTables.filter((currentTable) => !this.db.ignoreTables.includes(currentTable.tableName));
|
|
136
|
+
}
|
|
137
|
+
const tables = selectedTables.map((table) => table.tableName);
|
|
132
138
|
return tables.join(", ");
|
|
133
139
|
}
|
|
134
140
|
catch (error) {
|
|
@@ -373,8 +373,9 @@ class MatchingEngine extends base_js_1.VectorStore {
|
|
|
373
373
|
* @param documentMetadata - The metadata from a document
|
|
374
374
|
* @returns a Restriction[] (or an array of a subclass, from the FilterType)
|
|
375
375
|
*/
|
|
376
|
+
metadataToRestrictions(
|
|
376
377
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
377
|
-
|
|
378
|
+
documentMetadata) {
|
|
378
379
|
const metadata = this.cleanMetadata(documentMetadata);
|
|
379
380
|
const restrictions = [];
|
|
380
381
|
for (const key of Object.keys(metadata)) {
|
|
@@ -343,8 +343,9 @@ export class MatchingEngine extends VectorStore {
|
|
|
343
343
|
* @param documentMetadata - The metadata from a document
|
|
344
344
|
* @returns a Restriction[] (or an array of a subclass, from the FilterType)
|
|
345
345
|
*/
|
|
346
|
+
metadataToRestrictions(
|
|
346
347
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
347
|
-
|
|
348
|
+
documentMetadata) {
|
|
348
349
|
const metadata = this.cleanMetadata(documentMetadata);
|
|
349
350
|
const restrictions = [];
|
|
350
351
|
for (const key of Object.keys(metadata)) {
|
|
@@ -98,7 +98,7 @@ class MyScaleStore extends base_js_1.VectorStore {
|
|
|
98
98
|
};
|
|
99
99
|
this.database = args.database || "default";
|
|
100
100
|
this.table = args.table || "vector_table";
|
|
101
|
-
this.metric = args.metric || "
|
|
101
|
+
this.metric = args.metric || "Cosine";
|
|
102
102
|
this.client = (0, client_1.createClient)({
|
|
103
103
|
host: `${args.protocol ?? "https://"}${args.host}:${args.port}`,
|
|
104
104
|
username: args.username,
|
|
@@ -263,7 +263,7 @@ class MyScaleStore extends base_js_1.VectorStore {
|
|
|
263
263
|
* @returns The SQL query string.
|
|
264
264
|
*/
|
|
265
265
|
buildSearchQuery(query, k, filter) {
|
|
266
|
-
const order = this.metric === "
|
|
266
|
+
const order = this.metric === "IP" ? "DESC" : "ASC";
|
|
267
267
|
const whereStr = filter ? `PREWHERE ${filter.whereStr}` : "";
|
|
268
268
|
return `
|
|
269
269
|
SELECT ${this.columnMap.text} AS text, ${this.columnMap.metadata} AS metadata, dist
|
|
@@ -31,7 +31,7 @@ export interface ColumnMap {
|
|
|
31
31
|
/**
|
|
32
32
|
* Type of metric used in the MyScale database.
|
|
33
33
|
*/
|
|
34
|
-
export type metric = "
|
|
34
|
+
export type metric = "L2" | "Cosine" | "IP";
|
|
35
35
|
/**
|
|
36
36
|
* Type for filtering search results in the MyScale database.
|
|
37
37
|
*/
|
|
@@ -72,7 +72,7 @@ export class MyScaleStore extends VectorStore {
|
|
|
72
72
|
};
|
|
73
73
|
this.database = args.database || "default";
|
|
74
74
|
this.table = args.table || "vector_table";
|
|
75
|
-
this.metric = args.metric || "
|
|
75
|
+
this.metric = args.metric || "Cosine";
|
|
76
76
|
this.client = createClient({
|
|
77
77
|
host: `${args.protocol ?? "https://"}${args.host}:${args.port}`,
|
|
78
78
|
username: args.username,
|
|
@@ -237,7 +237,7 @@ export class MyScaleStore extends VectorStore {
|
|
|
237
237
|
* @returns The SQL query string.
|
|
238
238
|
*/
|
|
239
239
|
buildSearchQuery(query, k, filter) {
|
|
240
|
-
const order = this.metric === "
|
|
240
|
+
const order = this.metric === "IP" ? "DESC" : "ASC";
|
|
241
241
|
const whereStr = filter ? `PREWHERE ${filter.whereStr}` : "";
|
|
242
242
|
return `
|
|
243
243
|
SELECT ${this.columnMap.text} AS text, ${this.columnMap.metadata} AS metadata, dist
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/document_loaders/web/recursive_url.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/document_loaders/web/recursive_url.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/document_loaders/web/recursive_url.js'
|
package/hub.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/hub.cjs');
|
package/hub.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/hub.js'
|
package/hub.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/hub.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.134",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -301,6 +301,9 @@
|
|
|
301
301
|
"document_loaders/web/notionapi.cjs",
|
|
302
302
|
"document_loaders/web/notionapi.js",
|
|
303
303
|
"document_loaders/web/notionapi.d.ts",
|
|
304
|
+
"document_loaders/web/recursive_url.cjs",
|
|
305
|
+
"document_loaders/web/recursive_url.js",
|
|
306
|
+
"document_loaders/web/recursive_url.d.ts",
|
|
304
307
|
"document_loaders/web/s3.cjs",
|
|
305
308
|
"document_loaders/web/s3.js",
|
|
306
309
|
"document_loaders/web/s3.d.ts",
|
|
@@ -535,6 +538,9 @@
|
|
|
535
538
|
"storage/ioredis.cjs",
|
|
536
539
|
"storage/ioredis.js",
|
|
537
540
|
"storage/ioredis.d.ts",
|
|
541
|
+
"hub.cjs",
|
|
542
|
+
"hub.js",
|
|
543
|
+
"hub.d.ts",
|
|
538
544
|
"util/math.cjs",
|
|
539
545
|
"util/math.js",
|
|
540
546
|
"util/math.d.ts",
|
|
@@ -614,6 +620,8 @@
|
|
|
614
620
|
"@planetscale/database": "^1.8.0",
|
|
615
621
|
"@qdrant/js-client-rest": "^1.2.0",
|
|
616
622
|
"@raycast/api": "^1.55.2",
|
|
623
|
+
"@smithy/eventstream-codec": "^2.0.5",
|
|
624
|
+
"@smithy/util-utf8": "^2.0.0",
|
|
617
625
|
"@supabase/postgrest-js": "^1.1.1",
|
|
618
626
|
"@supabase/supabase-js": "^2.10.0",
|
|
619
627
|
"@tensorflow-models/universal-sentence-encoder": "^1.3.3",
|
|
@@ -664,6 +672,7 @@
|
|
|
664
672
|
"ioredis": "^5.3.2",
|
|
665
673
|
"jest": "^29.5.0",
|
|
666
674
|
"jsdom": "^22.1.0",
|
|
675
|
+
"langchainhub": "~0.0.3",
|
|
667
676
|
"mammoth": "^1.5.1",
|
|
668
677
|
"ml-matrix": "^6.10.4",
|
|
669
678
|
"mongodb": "^5.2.0",
|
|
@@ -722,6 +731,8 @@
|
|
|
722
731
|
"@planetscale/database": "^1.8.0",
|
|
723
732
|
"@qdrant/js-client-rest": "^1.2.0",
|
|
724
733
|
"@raycast/api": "^1.55.2",
|
|
734
|
+
"@smithy/eventstream-codec": "^2.0.5",
|
|
735
|
+
"@smithy/util-utf8": "^2.0.0",
|
|
725
736
|
"@supabase/postgrest-js": "^1.1.1",
|
|
726
737
|
"@supabase/supabase-js": "^2.10.0",
|
|
727
738
|
"@tensorflow-models/universal-sentence-encoder": "*",
|
|
@@ -746,6 +757,7 @@
|
|
|
746
757
|
"ignore": "^5.2.0",
|
|
747
758
|
"ioredis": "^5.3.2",
|
|
748
759
|
"jsdom": "*",
|
|
760
|
+
"langchainhub": "~0.0.3",
|
|
749
761
|
"mammoth": "*",
|
|
750
762
|
"mongodb": "^5.2.0",
|
|
751
763
|
"mysql2": "^3.3.3",
|
|
@@ -848,6 +860,12 @@
|
|
|
848
860
|
"@raycast/api": {
|
|
849
861
|
"optional": true
|
|
850
862
|
},
|
|
863
|
+
"@smithy/eventstream-codec": {
|
|
864
|
+
"optional": true
|
|
865
|
+
},
|
|
866
|
+
"@smithy/util-utf8": {
|
|
867
|
+
"optional": true
|
|
868
|
+
},
|
|
851
869
|
"@supabase/postgrest-js": {
|
|
852
870
|
"optional": true
|
|
853
871
|
},
|
|
@@ -920,6 +938,9 @@
|
|
|
920
938
|
"jsdom": {
|
|
921
939
|
"optional": true
|
|
922
940
|
},
|
|
941
|
+
"langchainhub": {
|
|
942
|
+
"optional": true
|
|
943
|
+
},
|
|
923
944
|
"mammoth": {
|
|
924
945
|
"optional": true
|
|
925
946
|
},
|
|
@@ -1526,6 +1547,11 @@
|
|
|
1526
1547
|
"import": "./document_loaders/web/notionapi.js",
|
|
1527
1548
|
"require": "./document_loaders/web/notionapi.cjs"
|
|
1528
1549
|
},
|
|
1550
|
+
"./document_loaders/web/recursive_url": {
|
|
1551
|
+
"types": "./document_loaders/web/recursive_url.d.ts",
|
|
1552
|
+
"import": "./document_loaders/web/recursive_url.js",
|
|
1553
|
+
"require": "./document_loaders/web/recursive_url.cjs"
|
|
1554
|
+
},
|
|
1529
1555
|
"./document_loaders/web/s3": {
|
|
1530
1556
|
"types": "./document_loaders/web/s3.d.ts",
|
|
1531
1557
|
"import": "./document_loaders/web/s3.js",
|
|
@@ -1920,6 +1946,11 @@
|
|
|
1920
1946
|
"import": "./storage/ioredis.js",
|
|
1921
1947
|
"require": "./storage/ioredis.cjs"
|
|
1922
1948
|
},
|
|
1949
|
+
"./hub": {
|
|
1950
|
+
"types": "./hub.d.ts",
|
|
1951
|
+
"import": "./hub.js",
|
|
1952
|
+
"require": "./hub.cjs"
|
|
1953
|
+
},
|
|
1923
1954
|
"./util/math": {
|
|
1924
1955
|
"types": "./util/math.d.ts",
|
|
1925
1956
|
"import": "./util/math.js",
|