langchain 0.0.172 → 0.0.173
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/agents/openai/output_parser.cjs +1 -0
- package/agents/openai/output_parser.d.ts +1 -0
- package/agents/openai/output_parser.js +1 -0
- package/agents/xml/output_parser.cjs +1 -0
- package/agents/xml/output_parser.d.ts +1 -0
- package/agents/xml/output_parser.js +1 -0
- package/dist/agents/index.cjs +3 -1
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.js +1 -0
- package/dist/agents/openai/index.cjs +8 -31
- package/dist/agents/openai/index.d.ts +2 -0
- package/dist/agents/openai/index.js +8 -31
- package/dist/agents/openai/output_parser.cjs +65 -0
- package/dist/agents/openai/output_parser.d.ts +22 -0
- package/dist/agents/openai/output_parser.js +61 -0
- package/dist/agents/toolkits/conversational_retrieval/tool.cjs +2 -1
- package/dist/agents/toolkits/conversational_retrieval/tool.js +2 -1
- package/dist/agents/xml/index.cjs +9 -25
- package/dist/agents/xml/index.d.ts +2 -7
- package/dist/agents/xml/index.js +8 -23
- package/dist/agents/xml/output_parser.cjs +44 -0
- package/dist/agents/xml/output_parser.d.ts +14 -0
- package/dist/agents/xml/output_parser.js +40 -0
- package/dist/document_loaders/fs/pdf.cjs +2 -1
- package/dist/document_loaders/fs/pdf.js +2 -1
- package/dist/document_loaders/web/pdf.cjs +2 -1
- package/dist/document_loaders/web/pdf.js +2 -1
- package/dist/load/import_map.cjs +5 -2
- package/dist/load/import_map.d.ts +3 -0
- package/dist/load/import_map.js +3 -0
- package/dist/memory/vector_store.cjs +2 -1
- package/dist/memory/vector_store.js +2 -1
- package/dist/storage/file_system.cjs +31 -11
- package/dist/storage/file_system.js +9 -9
- 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/render.cjs +19 -1
- package/dist/tools/render.d.ts +12 -0
- package/dist/tools/render.js +17 -0
- package/dist/tools/serpapi.d.ts +2 -2
- package/dist/tools/webbrowser.cjs +2 -1
- package/dist/tools/webbrowser.js +2 -1
- package/dist/util/document.cjs +12 -0
- package/dist/util/document.d.ts +9 -0
- package/dist/util/document.js +8 -0
- package/dist/vectorstores/cassandra.cjs +130 -35
- package/dist/vectorstores/cassandra.d.ts +21 -10
- package/dist/vectorstores/cassandra.js +130 -35
- package/dist/vectorstores/pgvector.cjs +13 -7
- package/dist/vectorstores/pgvector.d.ts +7 -0
- package/dist/vectorstores/pgvector.js +13 -7
- package/package.json +27 -3
- package/util/document.cjs +1 -0
- package/util/document.d.ts +1 -0
- package/util/document.js +1 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Document } from "../../document.js";
|
|
2
2
|
import { BaseDocumentLoader } from "../base.js";
|
|
3
|
+
import { formatDocumentsAsString } from "../../util/document.js";
|
|
3
4
|
/**
|
|
4
5
|
* A document loader for loading data from PDFs.
|
|
5
6
|
*/
|
|
@@ -74,7 +75,7 @@ export class WebPDFLoader extends BaseDocumentLoader {
|
|
|
74
75
|
}
|
|
75
76
|
return [
|
|
76
77
|
new Document({
|
|
77
|
-
pageContent: documents
|
|
78
|
+
pageContent: formatDocumentsAsString(documents),
|
|
78
79
|
metadata: {
|
|
79
80
|
pdf: {
|
|
80
81
|
version,
|
package/dist/load/import_map.cjs
CHANGED
|
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.
|
|
28
|
-
exports.runnables__remote = exports.evaluation = exports.experimental__chains__violation_of_expectations = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__time = exports.util__math = exports.storage__in_memory = exports.storage__encoder_backed = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__embeddings_filter = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__tavily_search_api = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = exports.retrievers__chaindesk = 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__document = exports.schema = exports.chat_models__fake = exports.chat_models__yandex = void 0;
|
|
27
|
+
exports.chat_models__baiduwenxin = exports.chat_models__fireworks = exports.chat_models__cloudflare_workersai = 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__web__searchapi = 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__fake = exports.llms__yandex = exports.llms__fireworks = exports.llms__ollama = exports.llms__cloudflare_workersai = exports.llms__aleph_alpha = exports.llms__ai21 = exports.llms__openai = exports.llms__base = exports.embeddings__minimax = exports.embeddings__openai = exports.embeddings__ollama = exports.embeddings__fake = exports.embeddings__cache_backed = exports.embeddings__base = exports.chains__openai_functions = exports.chains = exports.tools__render = exports.tools = exports.base_language = exports.agents__openai__output_parser = exports.agents__xml__output_parser = exports.agents__react__output_parser = exports.agents__format_scratchpad__log_to_message = exports.agents__format_scratchpad__xml = exports.agents__format_scratchpad__log = exports.agents__format_scratchpad = exports.agents__toolkits = exports.agents = exports.load__serializable = void 0;
|
|
28
|
+
exports.runnables__remote = exports.evaluation = exports.experimental__chains__violation_of_expectations = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__time = exports.util__math = exports.util__document = exports.storage__in_memory = exports.storage__encoder_backed = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__embeddings_filter = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__tavily_search_api = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = exports.retrievers__chaindesk = 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__document = exports.schema = exports.chat_models__fake = exports.chat_models__yandex = exports.chat_models__minimax = exports.chat_models__ollama = 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"));
|
|
@@ -34,6 +34,8 @@ exports.agents__format_scratchpad__log = __importStar(require("../agents/format_
|
|
|
34
34
|
exports.agents__format_scratchpad__xml = __importStar(require("../agents/format_scratchpad/xml.cjs"));
|
|
35
35
|
exports.agents__format_scratchpad__log_to_message = __importStar(require("../agents/format_scratchpad/log_to_message.cjs"));
|
|
36
36
|
exports.agents__react__output_parser = __importStar(require("../agents/react/output_parser.cjs"));
|
|
37
|
+
exports.agents__xml__output_parser = __importStar(require("../agents/xml/output_parser.cjs"));
|
|
38
|
+
exports.agents__openai__output_parser = __importStar(require("../agents/openai/output_parser.cjs"));
|
|
37
39
|
exports.base_language = __importStar(require("../base_language/index.cjs"));
|
|
38
40
|
exports.tools = __importStar(require("../tools/index.cjs"));
|
|
39
41
|
exports.tools__render = __importStar(require("../tools/render.cjs"));
|
|
@@ -108,6 +110,7 @@ exports.stores__file__in_memory = __importStar(require("../stores/file/in_memory
|
|
|
108
110
|
exports.stores__message__in_memory = __importStar(require("../stores/message/in_memory.cjs"));
|
|
109
111
|
exports.storage__encoder_backed = __importStar(require("../storage/encoder_backed.cjs"));
|
|
110
112
|
exports.storage__in_memory = __importStar(require("../storage/in_memory.cjs"));
|
|
113
|
+
exports.util__document = __importStar(require("../util/document.cjs"));
|
|
111
114
|
exports.util__math = __importStar(require("../util/math.cjs"));
|
|
112
115
|
exports.util__time = __importStar(require("../util/time.cjs"));
|
|
113
116
|
exports.experimental__autogpt = __importStar(require("../experimental/autogpt/index.cjs"));
|
|
@@ -6,6 +6,8 @@ export * as agents__format_scratchpad__log from "../agents/format_scratchpad/log
|
|
|
6
6
|
export * as agents__format_scratchpad__xml from "../agents/format_scratchpad/xml.js";
|
|
7
7
|
export * as agents__format_scratchpad__log_to_message from "../agents/format_scratchpad/log_to_message.js";
|
|
8
8
|
export * as agents__react__output_parser from "../agents/react/output_parser.js";
|
|
9
|
+
export * as agents__xml__output_parser from "../agents/xml/output_parser.js";
|
|
10
|
+
export * as agents__openai__output_parser from "../agents/openai/output_parser.js";
|
|
9
11
|
export * as base_language from "../base_language/index.js";
|
|
10
12
|
export * as tools from "../tools/index.js";
|
|
11
13
|
export * as tools__render from "../tools/render.js";
|
|
@@ -80,6 +82,7 @@ export * as stores__file__in_memory from "../stores/file/in_memory.js";
|
|
|
80
82
|
export * as stores__message__in_memory from "../stores/message/in_memory.js";
|
|
81
83
|
export * as storage__encoder_backed from "../storage/encoder_backed.js";
|
|
82
84
|
export * as storage__in_memory from "../storage/in_memory.js";
|
|
85
|
+
export * as util__document from "../util/document.js";
|
|
83
86
|
export * as util__math from "../util/math.js";
|
|
84
87
|
export * as util__time from "../util/time.js";
|
|
85
88
|
export * as experimental__autogpt from "../experimental/autogpt/index.js";
|
package/dist/load/import_map.js
CHANGED
|
@@ -7,6 +7,8 @@ export * as agents__format_scratchpad__log from "../agents/format_scratchpad/log
|
|
|
7
7
|
export * as agents__format_scratchpad__xml from "../agents/format_scratchpad/xml.js";
|
|
8
8
|
export * as agents__format_scratchpad__log_to_message from "../agents/format_scratchpad/log_to_message.js";
|
|
9
9
|
export * as agents__react__output_parser from "../agents/react/output_parser.js";
|
|
10
|
+
export * as agents__xml__output_parser from "../agents/xml/output_parser.js";
|
|
11
|
+
export * as agents__openai__output_parser from "../agents/openai/output_parser.js";
|
|
10
12
|
export * as base_language from "../base_language/index.js";
|
|
11
13
|
export * as tools from "../tools/index.js";
|
|
12
14
|
export * as tools__render from "../tools/render.js";
|
|
@@ -81,6 +83,7 @@ export * as stores__file__in_memory from "../stores/file/in_memory.js";
|
|
|
81
83
|
export * as stores__message__in_memory from "../stores/message/in_memory.js";
|
|
82
84
|
export * as storage__encoder_backed from "../storage/encoder_backed.js";
|
|
83
85
|
export * as storage__in_memory from "../storage/in_memory.js";
|
|
86
|
+
export * as util__document from "../util/document.js";
|
|
84
87
|
export * as util__math from "../util/math.js";
|
|
85
88
|
export * as util__time from "../util/time.js";
|
|
86
89
|
export * as experimental__autogpt from "../experimental/autogpt/index.js";
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VectorStoreRetrieverMemory = void 0;
|
|
4
4
|
const document_js_1 = require("../document.cjs");
|
|
5
|
+
const document_js_2 = require("../util/document.cjs");
|
|
5
6
|
const base_js_1 = require("./base.cjs");
|
|
6
7
|
/**
|
|
7
8
|
* Class for managing long-term memory in Large Language Model (LLM)
|
|
@@ -58,7 +59,7 @@ class VectorStoreRetrieverMemory extends base_js_1.BaseMemory {
|
|
|
58
59
|
return {
|
|
59
60
|
[this.memoryKey]: this.returnDocs
|
|
60
61
|
? results
|
|
61
|
-
:
|
|
62
|
+
: (0, document_js_2.formatDocumentsAsString)(results, "\n"),
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Document } from "../document.js";
|
|
2
|
+
import { formatDocumentsAsString } from "../util/document.js";
|
|
2
3
|
import { BaseMemory, getInputValue, } from "./base.js";
|
|
3
4
|
/**
|
|
4
5
|
* Class for managing long-term memory in Large Language Model (LLM)
|
|
@@ -55,7 +56,7 @@ export class VectorStoreRetrieverMemory extends BaseMemory {
|
|
|
55
56
|
return {
|
|
56
57
|
[this.memoryKey]: this.returnDocs
|
|
57
58
|
? results
|
|
58
|
-
: results
|
|
59
|
+
: formatDocumentsAsString(results, "\n"),
|
|
59
60
|
};
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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 __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
4
24
|
};
|
|
5
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
26
|
exports.LocalFileStore = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
27
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
28
|
+
const path = __importStar(require("node:path"));
|
|
9
29
|
const storage_js_1 = require("../schema/storage.cjs");
|
|
10
30
|
/**
|
|
11
31
|
* File system implementation of the BaseStore using a dictionary. Used for
|
|
@@ -35,7 +55,7 @@ class LocalFileStore extends storage_js_1.BaseStore {
|
|
|
35
55
|
*/
|
|
36
56
|
async getParsedFile(key) {
|
|
37
57
|
try {
|
|
38
|
-
const fileContent = await
|
|
58
|
+
const fileContent = await fs.readFile(this.getFullPath(key));
|
|
39
59
|
if (!fileContent) {
|
|
40
60
|
return undefined;
|
|
41
61
|
}
|
|
@@ -57,7 +77,7 @@ class LocalFileStore extends storage_js_1.BaseStore {
|
|
|
57
77
|
*/
|
|
58
78
|
async setFileContent(content, key) {
|
|
59
79
|
try {
|
|
60
|
-
await
|
|
80
|
+
await fs.writeFile(this.getFullPath(key), content);
|
|
61
81
|
}
|
|
62
82
|
catch (error) {
|
|
63
83
|
throw new Error(`Error writing file at path: ${this.getFullPath(key)}.\nError: ${JSON.stringify(error)}`);
|
|
@@ -70,7 +90,7 @@ class LocalFileStore extends storage_js_1.BaseStore {
|
|
|
70
90
|
getFullPath(key) {
|
|
71
91
|
try {
|
|
72
92
|
const keyAsTxtFile = `${key}.txt`;
|
|
73
|
-
const fullPath =
|
|
93
|
+
const fullPath = path.join(this.rootPath, keyAsTxtFile);
|
|
74
94
|
return fullPath;
|
|
75
95
|
}
|
|
76
96
|
catch (e) {
|
|
@@ -104,7 +124,7 @@ class LocalFileStore extends storage_js_1.BaseStore {
|
|
|
104
124
|
* @returns Promise that resolves when all keys have been deleted.
|
|
105
125
|
*/
|
|
106
126
|
async mdelete(keys) {
|
|
107
|
-
await Promise.all(keys.map((key) =>
|
|
127
|
+
await Promise.all(keys.map((key) => fs.unlink(this.getFullPath(key))));
|
|
108
128
|
}
|
|
109
129
|
/**
|
|
110
130
|
* Asynchronous generator that yields keys from the store. If a prefix is
|
|
@@ -113,7 +133,7 @@ class LocalFileStore extends storage_js_1.BaseStore {
|
|
|
113
133
|
* @returns AsyncGenerator that yields keys from the store.
|
|
114
134
|
*/
|
|
115
135
|
async *yieldKeys(prefix) {
|
|
116
|
-
const allFiles = await
|
|
136
|
+
const allFiles = await fs.readdir(this.rootPath);
|
|
117
137
|
const allKeys = allFiles.map((file) => file.replace(".txt", ""));
|
|
118
138
|
for (const key of allKeys) {
|
|
119
139
|
if (prefix === undefined || key.startsWith(prefix)) {
|
|
@@ -130,12 +150,12 @@ class LocalFileStore extends storage_js_1.BaseStore {
|
|
|
130
150
|
static async fromPath(rootPath) {
|
|
131
151
|
try {
|
|
132
152
|
// Verifies the directory exists at the provided path, and that it is readable and writable.
|
|
133
|
-
await
|
|
153
|
+
await fs.access(rootPath, fs.constants.R_OK | fs.constants.W_OK);
|
|
134
154
|
}
|
|
135
155
|
catch (_) {
|
|
136
156
|
try {
|
|
137
157
|
// Directory does not exist, create it.
|
|
138
|
-
await
|
|
158
|
+
await fs.mkdir(rootPath, { recursive: true });
|
|
139
159
|
}
|
|
140
160
|
catch (error) {
|
|
141
161
|
throw new Error(`An error occurred creating directory at: ${rootPath}.\nError: ${JSON.stringify(error)}`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
3
|
import { BaseStore } from "../schema/storage.js";
|
|
4
4
|
/**
|
|
5
5
|
* File system implementation of the BaseStore using a dictionary. Used for
|
|
@@ -29,7 +29,7 @@ export class LocalFileStore extends BaseStore {
|
|
|
29
29
|
*/
|
|
30
30
|
async getParsedFile(key) {
|
|
31
31
|
try {
|
|
32
|
-
const fileContent = await
|
|
32
|
+
const fileContent = await fs.readFile(this.getFullPath(key));
|
|
33
33
|
if (!fileContent) {
|
|
34
34
|
return undefined;
|
|
35
35
|
}
|
|
@@ -51,7 +51,7 @@ export class LocalFileStore extends BaseStore {
|
|
|
51
51
|
*/
|
|
52
52
|
async setFileContent(content, key) {
|
|
53
53
|
try {
|
|
54
|
-
await
|
|
54
|
+
await fs.writeFile(this.getFullPath(key), content);
|
|
55
55
|
}
|
|
56
56
|
catch (error) {
|
|
57
57
|
throw new Error(`Error writing file at path: ${this.getFullPath(key)}.\nError: ${JSON.stringify(error)}`);
|
|
@@ -64,7 +64,7 @@ export class LocalFileStore extends BaseStore {
|
|
|
64
64
|
getFullPath(key) {
|
|
65
65
|
try {
|
|
66
66
|
const keyAsTxtFile = `${key}.txt`;
|
|
67
|
-
const fullPath =
|
|
67
|
+
const fullPath = path.join(this.rootPath, keyAsTxtFile);
|
|
68
68
|
return fullPath;
|
|
69
69
|
}
|
|
70
70
|
catch (e) {
|
|
@@ -98,7 +98,7 @@ export class LocalFileStore extends BaseStore {
|
|
|
98
98
|
* @returns Promise that resolves when all keys have been deleted.
|
|
99
99
|
*/
|
|
100
100
|
async mdelete(keys) {
|
|
101
|
-
await Promise.all(keys.map((key) =>
|
|
101
|
+
await Promise.all(keys.map((key) => fs.unlink(this.getFullPath(key))));
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* Asynchronous generator that yields keys from the store. If a prefix is
|
|
@@ -107,7 +107,7 @@ export class LocalFileStore extends BaseStore {
|
|
|
107
107
|
* @returns AsyncGenerator that yields keys from the store.
|
|
108
108
|
*/
|
|
109
109
|
async *yieldKeys(prefix) {
|
|
110
|
-
const allFiles = await
|
|
110
|
+
const allFiles = await fs.readdir(this.rootPath);
|
|
111
111
|
const allKeys = allFiles.map((file) => file.replace(".txt", ""));
|
|
112
112
|
for (const key of allKeys) {
|
|
113
113
|
if (prefix === undefined || key.startsWith(prefix)) {
|
|
@@ -124,12 +124,12 @@ export class LocalFileStore extends BaseStore {
|
|
|
124
124
|
static async fromPath(rootPath) {
|
|
125
125
|
try {
|
|
126
126
|
// Verifies the directory exists at the provided path, and that it is readable and writable.
|
|
127
|
-
await
|
|
127
|
+
await fs.access(rootPath, fs.constants.R_OK | fs.constants.W_OK);
|
|
128
128
|
}
|
|
129
129
|
catch (_) {
|
|
130
130
|
try {
|
|
131
131
|
// Directory does not exist, create it.
|
|
132
|
-
await
|
|
132
|
+
await fs.mkdir(rootPath, { recursive: true });
|
|
133
133
|
}
|
|
134
134
|
catch (error) {
|
|
135
135
|
throw new Error(`An error occurred creating directory at: ${rootPath}.\nError: ${JSON.stringify(error)}`);
|
package/dist/tools/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SearchApi = exports.SearxngSearch = exports.DataForSeoAPISearch = exports.WolframAlphaTool = exports.WikipediaQueryRun = exports.BraveSearch = exports.WriteFileTool = exports.ReadFileTool = exports.AIPluginTool = exports.GoogleCustomSearch = exports.Serper = exports.ZapierNLAWrapper = exports.ZapierNLARunAction = exports.VectorStoreQATool = exports.RequestsPostTool = exports.RequestsGetTool = exports.JsonGetValueTool = exports.JsonListKeysTool = exports.JsonSpec = exports.ChainTool = exports.IFTTTWebhook = exports.DynamicStructuredTool = exports.DynamicTool = exports.StructuredTool = exports.Tool = exports.BingSerpAPI = exports.DadJokeAPI = exports.SerpAPI = void 0;
|
|
3
|
+
exports.formatToOpenAIFunction = exports.SearchApi = exports.SearxngSearch = exports.DataForSeoAPISearch = exports.WolframAlphaTool = exports.WikipediaQueryRun = exports.BraveSearch = exports.WriteFileTool = exports.ReadFileTool = exports.AIPluginTool = exports.GoogleCustomSearch = exports.Serper = exports.ZapierNLAWrapper = exports.ZapierNLARunAction = exports.VectorStoreQATool = exports.RequestsPostTool = exports.RequestsGetTool = exports.JsonGetValueTool = exports.JsonListKeysTool = exports.JsonSpec = exports.ChainTool = exports.IFTTTWebhook = exports.DynamicStructuredTool = exports.DynamicTool = exports.StructuredTool = exports.Tool = exports.BingSerpAPI = exports.DadJokeAPI = exports.SerpAPI = void 0;
|
|
4
4
|
var serpapi_js_1 = require("./serpapi.cjs");
|
|
5
5
|
Object.defineProperty(exports, "SerpAPI", { enumerable: true, get: function () { return serpapi_js_1.SerpAPI; } });
|
|
6
6
|
var dadjokeapi_js_1 = require("./dadjokeapi.cjs");
|
|
@@ -50,3 +50,5 @@ var searxng_search_js_1 = require("./searxng_search.cjs");
|
|
|
50
50
|
Object.defineProperty(exports, "SearxngSearch", { enumerable: true, get: function () { return searxng_search_js_1.SearxngSearch; } });
|
|
51
51
|
var searchapi_js_1 = require("./searchapi.cjs");
|
|
52
52
|
Object.defineProperty(exports, "SearchApi", { enumerable: true, get: function () { return searchapi_js_1.SearchApi; } });
|
|
53
|
+
var convert_to_openai_js_1 = require("./convert_to_openai.cjs");
|
|
54
|
+
Object.defineProperty(exports, "formatToOpenAIFunction", { enumerable: true, get: function () { return convert_to_openai_js_1.formatToOpenAIFunction; } });
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -19,3 +19,4 @@ export { WolframAlphaTool } from "./wolframalpha.js";
|
|
|
19
19
|
export { DataForSeoAPISearch, type DataForSeoApiConfig, } from "./dataforseo_api_search.js";
|
|
20
20
|
export { SearxngSearch } from "./searxng_search.js";
|
|
21
21
|
export { SearchApi, type SearchApiParameters } from "./searchapi.js";
|
|
22
|
+
export { formatToOpenAIFunction } from "./convert_to_openai.js";
|
package/dist/tools/index.js
CHANGED
|
@@ -19,3 +19,4 @@ export { WolframAlphaTool } from "./wolframalpha.js";
|
|
|
19
19
|
export { DataForSeoAPISearch, } from "./dataforseo_api_search.js";
|
|
20
20
|
export { SearxngSearch } from "./searxng_search.js";
|
|
21
21
|
export { SearchApi } from "./searchapi.js";
|
|
22
|
+
export { formatToOpenAIFunction } from "./convert_to_openai.js";
|
package/dist/tools/render.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.renderTextDescription = void 0;
|
|
3
|
+
exports.renderTextDescriptionAndArgs = exports.renderTextDescription = void 0;
|
|
4
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
4
5
|
/**
|
|
5
6
|
* Render the tool name and description in plain text.
|
|
6
7
|
*
|
|
@@ -16,3 +17,20 @@ function renderTextDescription(tools) {
|
|
|
16
17
|
return tools.map((tool) => `${tool.name}: ${tool.description}`).join("\n");
|
|
17
18
|
}
|
|
18
19
|
exports.renderTextDescription = renderTextDescription;
|
|
20
|
+
/**
|
|
21
|
+
* Render the tool name, description, and args in plain text.
|
|
22
|
+
* Output will be in the format of:'
|
|
23
|
+
* ```
|
|
24
|
+
* search: This tool is used for search, args: {"query": {"type": "string"}}
|
|
25
|
+
* calculator: This tool is used for math,
|
|
26
|
+
* args: {"expression": {"type": "string"}}
|
|
27
|
+
* ```
|
|
28
|
+
* @param tools
|
|
29
|
+
* @returns a string of all tools, their descriptions and a stringified version of their schemas
|
|
30
|
+
*/
|
|
31
|
+
function renderTextDescriptionAndArgs(tools) {
|
|
32
|
+
return tools
|
|
33
|
+
.map((tool) => `${tool.name}: ${tool.description}, args: ${JSON.stringify((0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema).properties)}`)
|
|
34
|
+
.join("\n");
|
|
35
|
+
}
|
|
36
|
+
exports.renderTextDescriptionAndArgs = renderTextDescriptionAndArgs;
|
package/dist/tools/render.d.ts
CHANGED
|
@@ -11,3 +11,15 @@ import { StructuredTool } from "./base.js";
|
|
|
11
11
|
* @returns a string of all tools and their descriptions
|
|
12
12
|
*/
|
|
13
13
|
export declare function renderTextDescription(tools: StructuredTool[]): string;
|
|
14
|
+
/**
|
|
15
|
+
* Render the tool name, description, and args in plain text.
|
|
16
|
+
* Output will be in the format of:'
|
|
17
|
+
* ```
|
|
18
|
+
* search: This tool is used for search, args: {"query": {"type": "string"}}
|
|
19
|
+
* calculator: This tool is used for math,
|
|
20
|
+
* args: {"expression": {"type": "string"}}
|
|
21
|
+
* ```
|
|
22
|
+
* @param tools
|
|
23
|
+
* @returns a string of all tools, their descriptions and a stringified version of their schemas
|
|
24
|
+
*/
|
|
25
|
+
export declare function renderTextDescriptionAndArgs(tools: StructuredTool[]): string;
|
package/dist/tools/render.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
1
2
|
/**
|
|
2
3
|
* Render the tool name and description in plain text.
|
|
3
4
|
*
|
|
@@ -12,3 +13,19 @@
|
|
|
12
13
|
export function renderTextDescription(tools) {
|
|
13
14
|
return tools.map((tool) => `${tool.name}: ${tool.description}`).join("\n");
|
|
14
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Render the tool name, description, and args in plain text.
|
|
18
|
+
* Output will be in the format of:'
|
|
19
|
+
* ```
|
|
20
|
+
* search: This tool is used for search, args: {"query": {"type": "string"}}
|
|
21
|
+
* calculator: This tool is used for math,
|
|
22
|
+
* args: {"expression": {"type": "string"}}
|
|
23
|
+
* ```
|
|
24
|
+
* @param tools
|
|
25
|
+
* @returns a string of all tools, their descriptions and a stringified version of their schemas
|
|
26
|
+
*/
|
|
27
|
+
export function renderTextDescriptionAndArgs(tools) {
|
|
28
|
+
return tools
|
|
29
|
+
.map((tool) => `${tool.name}: ${tool.description}, args: ${JSON.stringify(zodToJsonSchema(tool.schema).properties)}`)
|
|
30
|
+
.join("\n");
|
|
31
|
+
}
|
package/dist/tools/serpapi.d.ts
CHANGED
|
@@ -66,8 +66,8 @@ export interface SerpAPIParameters extends BaseParameters {
|
|
|
66
66
|
* Additional Google Place ID
|
|
67
67
|
* Parameter that you might have to use to force the knowledge graph map view to
|
|
68
68
|
* show up. You can find the lsig ID by using our [Local Pack
|
|
69
|
-
* API](https://serpapi.com/local-pack) or [Places Results
|
|
70
|
-
* API](https://serpapi.com/
|
|
69
|
+
* API](https://serpapi.com/local-pack) or [Local Places Results
|
|
70
|
+
* API](https://serpapi.com/local-results).
|
|
71
71
|
* lsig ID is also available via a redirect Google uses within [Google My
|
|
72
72
|
* Business](https://www.google.com/business/).
|
|
73
73
|
*/
|
|
@@ -35,6 +35,7 @@ const memory_js_1 = require("../vectorstores/memory.cjs");
|
|
|
35
35
|
const document_js_1 = require("../document.cjs");
|
|
36
36
|
const base_js_1 = require("./base.cjs");
|
|
37
37
|
const axios_fetch_adapter_js_1 = __importDefault(require("../util/axios-fetch-adapter.cjs"));
|
|
38
|
+
const document_js_2 = require("../util/document.cjs");
|
|
38
39
|
const parseInputs = (inputs) => {
|
|
39
40
|
const [baseUrl, task] = inputs.split(",").map((input) => {
|
|
40
41
|
let t = input.trim();
|
|
@@ -234,7 +235,7 @@ class WebBrowser extends base_js_1.Tool {
|
|
|
234
235
|
}));
|
|
235
236
|
const vectorStore = await memory_js_1.MemoryVectorStore.fromDocuments(docs, this.embeddings);
|
|
236
237
|
const results = await vectorStore.similaritySearch(task, 4, undefined, runManager?.getChild("vectorstore"));
|
|
237
|
-
context =
|
|
238
|
+
context = (0, document_js_2.formatDocumentsAsString)(results, "\n");
|
|
238
239
|
}
|
|
239
240
|
const input = `Text:${context}\n\nI need ${doSummary ? "a summary" : task} from the above text, also provide up to 5 markdown links from within that would be of interest (always including URL and text). Links should be provided, if present, in markdown syntax as a list under the heading "Relevant Links:".`;
|
|
240
241
|
return this.model.predict(input, undefined, runManager?.getChild());
|
package/dist/tools/webbrowser.js
CHANGED
|
@@ -6,6 +6,7 @@ import { MemoryVectorStore } from "../vectorstores/memory.js";
|
|
|
6
6
|
import { Document } from "../document.js";
|
|
7
7
|
import { Tool } from "./base.js";
|
|
8
8
|
import fetchAdapter from "../util/axios-fetch-adapter.js";
|
|
9
|
+
import { formatDocumentsAsString } from "../util/document.js";
|
|
9
10
|
export const parseInputs = (inputs) => {
|
|
10
11
|
const [baseUrl, task] = inputs.split(",").map((input) => {
|
|
11
12
|
let t = input.trim();
|
|
@@ -203,7 +204,7 @@ export class WebBrowser extends Tool {
|
|
|
203
204
|
}));
|
|
204
205
|
const vectorStore = await MemoryVectorStore.fromDocuments(docs, this.embeddings);
|
|
205
206
|
const results = await vectorStore.similaritySearch(task, 4, undefined, runManager?.getChild("vectorstore"));
|
|
206
|
-
context = results
|
|
207
|
+
context = formatDocumentsAsString(results, "\n");
|
|
207
208
|
}
|
|
208
209
|
const input = `Text:${context}\n\nI need ${doSummary ? "a summary" : task} from the above text, also provide up to 5 markdown links from within that would be of interest (always including URL and text). Links should be provided, if present, in markdown syntax as a list under the heading "Relevant Links:".`;
|
|
209
210
|
return this.model.predict(input, undefined, runManager?.getChild());
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatDocumentsAsString = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Given a list of documents, this util formats their contents
|
|
6
|
+
* into a string, separated by newlines.
|
|
7
|
+
*
|
|
8
|
+
* @param documents
|
|
9
|
+
* @returns A string of the documents page content, separated by newlines.
|
|
10
|
+
*/
|
|
11
|
+
const formatDocumentsAsString = (documents, separator = "\n\n") => documents.map((doc) => doc.pageContent).join(separator);
|
|
12
|
+
exports.formatDocumentsAsString = formatDocumentsAsString;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Document } from "../document.js";
|
|
2
|
+
/**
|
|
3
|
+
* Given a list of documents, this util formats their contents
|
|
4
|
+
* into a string, separated by newlines.
|
|
5
|
+
*
|
|
6
|
+
* @param documents
|
|
7
|
+
* @returns A string of the documents page content, separated by newlines.
|
|
8
|
+
*/
|
|
9
|
+
export declare const formatDocumentsAsString: (documents: Document[], separator?: string) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given a list of documents, this util formats their contents
|
|
3
|
+
* into a string, separated by newlines.
|
|
4
|
+
*
|
|
5
|
+
* @param documents
|
|
6
|
+
* @returns A string of the documents page content, separated by newlines.
|
|
7
|
+
*/
|
|
8
|
+
export const formatDocumentsAsString = (documents, separator = "\n\n") => documents.map((doc) => doc.pageContent).join(separator);
|