langchain 0.0.153 → 0.0.155
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/base_language/index.cjs +36 -0
- package/dist/base_language/index.d.ts +9 -1
- package/dist/base_language/index.js +36 -0
- package/dist/cache/base.cjs +24 -1
- package/dist/cache/base.d.ts +9 -0
- package/dist/cache/base.js +21 -0
- package/dist/cache/cloudflare_kv.cjs +2 -5
- package/dist/cache/cloudflare_kv.js +3 -6
- package/dist/cache/ioredis.cjs +16 -6
- package/dist/cache/ioredis.d.ts +5 -2
- package/dist/cache/ioredis.js +17 -7
- package/dist/cache/momento.cjs +6 -2
- package/dist/cache/momento.js +7 -3
- package/dist/cache/redis.cjs +3 -5
- package/dist/cache/redis.js +4 -6
- package/dist/cache/upstash_redis.cjs +2 -5
- package/dist/cache/upstash_redis.js +3 -6
- package/dist/callbacks/base.d.ts +42 -28
- package/dist/callbacks/handlers/log_stream.cjs +283 -0
- package/dist/callbacks/handlers/log_stream.d.ts +99 -0
- package/dist/callbacks/handlers/log_stream.js +277 -0
- package/dist/callbacks/handlers/tracer.cjs +34 -18
- package/dist/callbacks/handlers/tracer.d.ts +18 -16
- package/dist/callbacks/handlers/tracer.js +34 -18
- package/dist/chat_models/base.cjs +64 -20
- package/dist/chat_models/base.d.ts +7 -0
- package/dist/chat_models/base.js +64 -20
- package/dist/document_loaders/web/notionapi.cjs +8 -4
- package/dist/document_loaders/web/notionapi.js +8 -4
- package/dist/document_loaders/web/searchapi.cjs +134 -0
- package/dist/document_loaders/web/searchapi.d.ts +65 -0
- package/dist/document_loaders/web/searchapi.js +130 -0
- package/dist/llms/base.cjs +10 -26
- package/dist/llms/base.d.ts +4 -4
- package/dist/llms/base.js +4 -20
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/load/import_map.cjs +3 -2
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/schema/index.cjs +50 -1
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.js +48 -0
- package/dist/schema/runnable/base.cjs +64 -5
- package/dist/schema/runnable/base.d.ts +13 -0
- package/dist/schema/runnable/base.js +64 -5
- package/dist/stores/message/utils.cjs +2 -50
- package/dist/stores/message/utils.d.ts +0 -14
- package/dist/stores/message/utils.js +2 -49
- package/dist/tools/index.cjs +3 -1
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +1 -0
- package/dist/tools/searchapi.cjs +139 -0
- package/dist/tools/searchapi.d.ts +64 -0
- package/dist/tools/searchapi.js +135 -0
- package/dist/util/fast-json-patch/index.cjs +48 -0
- package/dist/util/fast-json-patch/index.d.ts +21 -0
- package/dist/util/fast-json-patch/index.js +15 -0
- package/dist/util/fast-json-patch/src/core.cjs +469 -0
- package/dist/util/fast-json-patch/src/core.d.ts +111 -0
- package/dist/util/fast-json-patch/src/core.js +459 -0
- package/dist/util/fast-json-patch/src/helpers.cjs +194 -0
- package/dist/util/fast-json-patch/src/helpers.d.ts +36 -0
- package/dist/util/fast-json-patch/src/helpers.js +181 -0
- package/dist/util/googlevertexai-webauth.cjs +6 -2
- package/dist/util/googlevertexai-webauth.d.ts +1 -0
- package/dist/util/googlevertexai-webauth.js +6 -2
- package/dist/util/stream.cjs +2 -40
- package/dist/util/stream.d.ts +1 -2
- package/dist/util/stream.js +1 -38
- package/dist/vectorstores/pgvector.cjs +1 -1
- package/dist/vectorstores/pgvector.js +1 -1
- package/dist/vectorstores/vercel_postgres.cjs +300 -0
- package/dist/vectorstores/vercel_postgres.d.ts +145 -0
- package/dist/vectorstores/vercel_postgres.js +296 -0
- package/document_loaders/web/searchapi.cjs +1 -0
- package/document_loaders/web/searchapi.d.ts +1 -0
- package/document_loaders/web/searchapi.js +1 -0
- package/package.json +22 -1
- package/vectorstores/vercel_postgres.cjs +1 -0
- package/vectorstores/vercel_postgres.d.ts +1 -0
- package/vectorstores/vercel_postgres.js +1 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { getEnvironmentVariable } from "../util/env.js";
|
|
2
|
+
import { Tool } from "./base.js";
|
|
3
|
+
function isJSONObject(value) {
|
|
4
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* SearchApi Class Definition.
|
|
8
|
+
*
|
|
9
|
+
* Provides a wrapper around the SearchApi.
|
|
10
|
+
*
|
|
11
|
+
* Ensure you've set the SEARCHAPI_API_KEY environment variable for authentication.
|
|
12
|
+
* You can obtain a free API key from https://www.searchapi.io/.
|
|
13
|
+
*/
|
|
14
|
+
export class SearchApi extends Tool {
|
|
15
|
+
static lc_name() {
|
|
16
|
+
return "SearchApi";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Converts the SearchApi instance to JSON. This method is not implemented
|
|
20
|
+
* and will throw an error if called.
|
|
21
|
+
* @returns Throws an error.
|
|
22
|
+
*/
|
|
23
|
+
toJSON() {
|
|
24
|
+
return this.toJSONNotImplemented();
|
|
25
|
+
}
|
|
26
|
+
constructor(apiKey = getEnvironmentVariable("SEARCHAPI_API_KEY"), params = {}) {
|
|
27
|
+
super(...arguments);
|
|
28
|
+
Object.defineProperty(this, "apiKey", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: void 0
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "params", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: void 0
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "name", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: "search"
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "description", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: "a search engine. useful for when you need to answer questions about current events. input should be a search query."
|
|
51
|
+
});
|
|
52
|
+
if (!apiKey) {
|
|
53
|
+
throw new Error("SearchApi requires an API key. Please set it as SEARCHAPI_API_KEY in your .env file, or pass it as a parameter to the SearchApi constructor.");
|
|
54
|
+
}
|
|
55
|
+
this.apiKey = apiKey;
|
|
56
|
+
this.params = params;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Builds a URL for the SearchApi request.
|
|
60
|
+
* @param parameters The parameters for the request.
|
|
61
|
+
* @returns A string representing the built URL.
|
|
62
|
+
*/
|
|
63
|
+
buildUrl(searchQuery) {
|
|
64
|
+
const preparedParams = Object.entries({
|
|
65
|
+
engine: "google",
|
|
66
|
+
api_key: this.apiKey,
|
|
67
|
+
...this.params,
|
|
68
|
+
q: searchQuery,
|
|
69
|
+
})
|
|
70
|
+
.filter(([key, value]) => value !== undefined && value !== null && key !== "apiKey")
|
|
71
|
+
.map(([key, value]) => [key, `${value}`]);
|
|
72
|
+
const searchParams = new URLSearchParams(preparedParams);
|
|
73
|
+
return `https://www.searchapi.io/api/v1/search?${searchParams}`;
|
|
74
|
+
}
|
|
75
|
+
/** @ignore */
|
|
76
|
+
/**
|
|
77
|
+
* Calls the SearchAPI.
|
|
78
|
+
*
|
|
79
|
+
* Accepts an input query and fetches the result from SearchApi.
|
|
80
|
+
*
|
|
81
|
+
* @param {string} input - Search query.
|
|
82
|
+
* @returns {string} - Formatted search results or an error message.
|
|
83
|
+
*
|
|
84
|
+
* NOTE: This method is the core search handler and processes various types
|
|
85
|
+
* of search results including Google organic results, videos, jobs, and images.
|
|
86
|
+
*/
|
|
87
|
+
async _call(input) {
|
|
88
|
+
const resp = await fetch(this.buildUrl(input));
|
|
89
|
+
const json = await resp.json();
|
|
90
|
+
if (json.error) {
|
|
91
|
+
throw new Error(`Failed to load search results from SearchApi due to: ${json.error}`);
|
|
92
|
+
}
|
|
93
|
+
// Google Search results
|
|
94
|
+
if (json.answer_box?.answer) {
|
|
95
|
+
return json.answer_box.answer;
|
|
96
|
+
}
|
|
97
|
+
if (json.answer_box?.snippet) {
|
|
98
|
+
return json.answer_box.snippet;
|
|
99
|
+
}
|
|
100
|
+
if (json.knowledge_graph?.description) {
|
|
101
|
+
return json.knowledge_graph.description;
|
|
102
|
+
}
|
|
103
|
+
// Organic results (Google, Google News)
|
|
104
|
+
if (json.organic_results) {
|
|
105
|
+
const snippets = json.organic_results
|
|
106
|
+
.filter((r) => r.snippet)
|
|
107
|
+
.map((r) => r.snippet);
|
|
108
|
+
return snippets.join("\n");
|
|
109
|
+
}
|
|
110
|
+
// Google Jobs results
|
|
111
|
+
if (json.jobs) {
|
|
112
|
+
const jobDescriptions = json.jobs
|
|
113
|
+
.slice(0, 1)
|
|
114
|
+
.filter((r) => r.description)
|
|
115
|
+
.map((r) => r.description);
|
|
116
|
+
return jobDescriptions.join("\n");
|
|
117
|
+
}
|
|
118
|
+
// Google Videos results
|
|
119
|
+
if (json.videos) {
|
|
120
|
+
const videoInfo = json.videos
|
|
121
|
+
.filter((r) => r.title && r.link)
|
|
122
|
+
.map((r) => `Title: "${r.title}" Link: ${r.link}`);
|
|
123
|
+
return videoInfo.join("\n");
|
|
124
|
+
}
|
|
125
|
+
// Google Images results
|
|
126
|
+
if (json.images) {
|
|
127
|
+
const image_results = json.images.slice(0, 15);
|
|
128
|
+
const imageInfo = image_results
|
|
129
|
+
.filter((r) => r.title && r.original && isJSONObject(r.original) && r.original.link)
|
|
130
|
+
.map((r) => `Title: "${r.title}" Link: ${r.original.link}`);
|
|
131
|
+
return imageInfo.join("\n");
|
|
132
|
+
}
|
|
133
|
+
return "No good search result found";
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
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]; } };
|
|
7
|
+
}
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.unescapePathComponent = exports.escapePathComponent = exports.deepClone = exports.JsonPatchError = void 0;
|
|
30
|
+
__exportStar(require("./src/core.cjs"), exports);
|
|
31
|
+
var helpers_js_1 = require("./src/helpers.cjs");
|
|
32
|
+
Object.defineProperty(exports, "JsonPatchError", { enumerable: true, get: function () { return helpers_js_1.PatchError; } });
|
|
33
|
+
Object.defineProperty(exports, "deepClone", { enumerable: true, get: function () { return helpers_js_1._deepClone; } });
|
|
34
|
+
Object.defineProperty(exports, "escapePathComponent", { enumerable: true, get: function () { return helpers_js_1.escapePathComponent; } });
|
|
35
|
+
Object.defineProperty(exports, "unescapePathComponent", { enumerable: true, get: function () { return helpers_js_1.unescapePathComponent; } });
|
|
36
|
+
/**
|
|
37
|
+
* Default export for backwards compat
|
|
38
|
+
*/
|
|
39
|
+
const core = __importStar(require("./src/core.cjs"));
|
|
40
|
+
const helpers_js_2 = require("./src/helpers.cjs");
|
|
41
|
+
exports.default = {
|
|
42
|
+
...core,
|
|
43
|
+
// ...duplex,
|
|
44
|
+
JsonPatchError: helpers_js_2.PatchError,
|
|
45
|
+
deepClone: helpers_js_2._deepClone,
|
|
46
|
+
escapePathComponent: helpers_js_2.escapePathComponent,
|
|
47
|
+
unescapePathComponent: helpers_js_2.unescapePathComponent,
|
|
48
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export * from "./src/core.js";
|
|
2
|
+
export { PatchError as JsonPatchError, _deepClone as deepClone, escapePathComponent, unescapePathComponent, } from "./src/helpers.js";
|
|
3
|
+
/**
|
|
4
|
+
* Default export for backwards compat
|
|
5
|
+
*/
|
|
6
|
+
import * as core from "./src/core.js";
|
|
7
|
+
import { PatchError as JsonPatchError, _deepClone as deepClone, escapePathComponent, unescapePathComponent } from "./src/helpers.js";
|
|
8
|
+
declare const _default: {
|
|
9
|
+
JsonPatchError: typeof JsonPatchError;
|
|
10
|
+
deepClone: typeof deepClone;
|
|
11
|
+
escapePathComponent: typeof escapePathComponent;
|
|
12
|
+
unescapePathComponent: typeof unescapePathComponent;
|
|
13
|
+
getValueByPointer(document: any, pointer: string): any;
|
|
14
|
+
applyOperation<T>(document: T, operation: core.Operation, validateOperation?: boolean | core.Validator<T>, mutateDocument?: boolean, banPrototypeModifications?: boolean, index?: number): core.OperationResult<T>;
|
|
15
|
+
applyPatch<T_1>(document: T_1, patch: readonly core.Operation[], validateOperation?: boolean | core.Validator<T_1> | undefined, mutateDocument?: boolean, banPrototypeModifications?: boolean): core.PatchResult<T_1>;
|
|
16
|
+
applyReducer<T_2>(document: T_2, operation: core.Operation, index: number): T_2;
|
|
17
|
+
validator(operation: core.Operation, index: number, document?: any, existingPathFragment?: string | undefined): void;
|
|
18
|
+
validate<T_3>(sequence: readonly core.Operation[], document?: T_3 | undefined, externalValidator?: core.Validator<T_3> | undefined): JsonPatchError;
|
|
19
|
+
_areEquals(a: any, b: any): boolean;
|
|
20
|
+
};
|
|
21
|
+
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./src/core.js";
|
|
2
|
+
export { PatchError as JsonPatchError, _deepClone as deepClone, escapePathComponent, unescapePathComponent, } from "./src/helpers.js";
|
|
3
|
+
/**
|
|
4
|
+
* Default export for backwards compat
|
|
5
|
+
*/
|
|
6
|
+
import * as core from "./src/core.js";
|
|
7
|
+
import { PatchError as JsonPatchError, _deepClone as deepClone, escapePathComponent, unescapePathComponent, } from "./src/helpers.js";
|
|
8
|
+
export default {
|
|
9
|
+
...core,
|
|
10
|
+
// ...duplex,
|
|
11
|
+
JsonPatchError,
|
|
12
|
+
deepClone,
|
|
13
|
+
escapePathComponent,
|
|
14
|
+
unescapePathComponent,
|
|
15
|
+
};
|