langchain 0.0.171 → 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.
Files changed (110) hide show
  1. package/agents/format_scratchpad/log.cjs +1 -0
  2. package/agents/format_scratchpad/log.d.ts +1 -0
  3. package/agents/format_scratchpad/log.js +1 -0
  4. package/agents/format_scratchpad/log_to_message.cjs +1 -0
  5. package/agents/format_scratchpad/log_to_message.d.ts +1 -0
  6. package/agents/format_scratchpad/log_to_message.js +1 -0
  7. package/agents/format_scratchpad/xml.cjs +1 -0
  8. package/agents/format_scratchpad/xml.d.ts +1 -0
  9. package/agents/format_scratchpad/xml.js +1 -0
  10. package/agents/format_scratchpad.cjs +1 -1
  11. package/agents/format_scratchpad.d.ts +1 -1
  12. package/agents/format_scratchpad.js +1 -1
  13. package/agents/openai/output_parser.cjs +1 -0
  14. package/agents/openai/output_parser.d.ts +1 -0
  15. package/agents/openai/output_parser.js +1 -0
  16. package/agents/react/output_parser.cjs +1 -0
  17. package/agents/react/output_parser.d.ts +1 -0
  18. package/agents/react/output_parser.js +1 -0
  19. package/agents/xml/output_parser.cjs +1 -0
  20. package/agents/xml/output_parser.d.ts +1 -0
  21. package/agents/xml/output_parser.js +1 -0
  22. package/dist/agents/format_scratchpad/log.cjs +16 -0
  23. package/dist/agents/format_scratchpad/log.d.ts +9 -0
  24. package/dist/agents/format_scratchpad/log.js +12 -0
  25. package/dist/agents/format_scratchpad/log_to_message.cjs +22 -0
  26. package/dist/agents/format_scratchpad/log_to_message.d.ts +2 -0
  27. package/dist/agents/format_scratchpad/log_to_message.js +18 -0
  28. package/dist/agents/{format_scratchpad.cjs → format_scratchpad/openai_functions.cjs} +3 -3
  29. package/dist/agents/{format_scratchpad.d.ts → format_scratchpad/openai_functions.d.ts} +1 -1
  30. package/dist/agents/{format_scratchpad.js → format_scratchpad/openai_functions.js} +3 -3
  31. package/dist/agents/format_scratchpad/xml.cjs +12 -0
  32. package/dist/agents/format_scratchpad/xml.d.ts +2 -0
  33. package/dist/agents/format_scratchpad/xml.js +8 -0
  34. package/dist/agents/index.cjs +3 -1
  35. package/dist/agents/index.d.ts +1 -0
  36. package/dist/agents/index.js +1 -0
  37. package/dist/agents/openai/index.cjs +8 -31
  38. package/dist/agents/openai/index.d.ts +2 -0
  39. package/dist/agents/openai/index.js +8 -31
  40. package/dist/agents/openai/output_parser.cjs +65 -0
  41. package/dist/agents/openai/output_parser.d.ts +22 -0
  42. package/dist/agents/openai/output_parser.js +61 -0
  43. package/dist/agents/react/output_parser.cjs +96 -0
  44. package/dist/agents/react/output_parser.d.ts +47 -0
  45. package/dist/agents/react/output_parser.js +92 -0
  46. package/dist/agents/react/prompt.cjs +13 -0
  47. package/dist/agents/react/prompt.d.ts +1 -0
  48. package/dist/agents/react/prompt.js +10 -0
  49. package/dist/agents/toolkits/conversational_retrieval/tool.cjs +2 -1
  50. package/dist/agents/toolkits/conversational_retrieval/tool.js +2 -1
  51. package/dist/agents/xml/index.cjs +9 -25
  52. package/dist/agents/xml/index.d.ts +2 -7
  53. package/dist/agents/xml/index.js +8 -23
  54. package/dist/agents/xml/output_parser.cjs +44 -0
  55. package/dist/agents/xml/output_parser.d.ts +14 -0
  56. package/dist/agents/xml/output_parser.js +40 -0
  57. package/dist/document_loaders/fs/pdf.cjs +2 -1
  58. package/dist/document_loaders/fs/pdf.js +2 -1
  59. package/dist/document_loaders/web/pdf.cjs +2 -1
  60. package/dist/document_loaders/web/pdf.js +2 -1
  61. package/dist/embeddings/openai.cjs +11 -0
  62. package/dist/embeddings/openai.d.ts +2 -0
  63. package/dist/embeddings/openai.js +11 -0
  64. package/dist/load/import_constants.cjs +1 -0
  65. package/dist/load/import_constants.js +1 -0
  66. package/dist/load/import_map.cjs +11 -3
  67. package/dist/load/import_map.d.ts +9 -1
  68. package/dist/load/import_map.js +9 -1
  69. package/dist/memory/vector_store.cjs +2 -1
  70. package/dist/memory/vector_store.js +2 -1
  71. package/dist/storage/file_system.cjs +167 -0
  72. package/dist/storage/file_system.d.ts +60 -0
  73. package/dist/storage/file_system.js +140 -0
  74. package/dist/tools/index.cjs +3 -1
  75. package/dist/tools/index.d.ts +1 -0
  76. package/dist/tools/index.js +1 -0
  77. package/dist/tools/render.cjs +36 -0
  78. package/dist/tools/render.d.ts +25 -0
  79. package/dist/tools/render.js +31 -0
  80. package/dist/tools/serpapi.d.ts +2 -2
  81. package/dist/tools/webbrowser.cjs +2 -1
  82. package/dist/tools/webbrowser.js +2 -1
  83. package/dist/util/document.cjs +12 -0
  84. package/dist/util/document.d.ts +9 -0
  85. package/dist/util/document.js +8 -0
  86. package/dist/vectorstores/analyticdb.cjs +7 -3
  87. package/dist/vectorstores/analyticdb.d.ts +1 -1
  88. package/dist/vectorstores/analyticdb.js +7 -3
  89. package/dist/vectorstores/cassandra.cjs +130 -35
  90. package/dist/vectorstores/cassandra.d.ts +21 -10
  91. package/dist/vectorstores/cassandra.js +130 -35
  92. package/dist/vectorstores/pgvector.cjs +13 -7
  93. package/dist/vectorstores/pgvector.d.ts +7 -0
  94. package/dist/vectorstores/pgvector.js +13 -7
  95. package/dist/vectorstores/qdrant.cjs +19 -11
  96. package/dist/vectorstores/qdrant.d.ts +1 -1
  97. package/dist/vectorstores/qdrant.js +19 -11
  98. package/dist/vectorstores/redis.cjs +4 -1
  99. package/dist/vectorstores/redis.d.ts +1 -1
  100. package/dist/vectorstores/redis.js +4 -1
  101. package/package.json +75 -3
  102. package/storage/file_system.cjs +1 -0
  103. package/storage/file_system.d.ts +1 -0
  104. package/storage/file_system.js +1 -0
  105. package/tools/render.cjs +1 -0
  106. package/tools/render.d.ts +1 -0
  107. package/tools/render.js +1 -0
  108. package/util/document.cjs +1 -0
  109. package/util/document.d.ts +1 -0
  110. package/util/document.js +1 -0
@@ -24,14 +24,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  return result;
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- 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 = 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 = exports.base_language = 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.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 = 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"));
32
- exports.agents__format_scratchpad = __importStar(require("../agents/format_scratchpad.cjs"));
32
+ exports.agents__format_scratchpad = __importStar(require("../agents/format_scratchpad/openai_functions.cjs"));
33
+ exports.agents__format_scratchpad__log = __importStar(require("../agents/format_scratchpad/log.cjs"));
34
+ exports.agents__format_scratchpad__xml = __importStar(require("../agents/format_scratchpad/xml.cjs"));
35
+ exports.agents__format_scratchpad__log_to_message = __importStar(require("../agents/format_scratchpad/log_to_message.cjs"));
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"));
33
39
  exports.base_language = __importStar(require("../base_language/index.cjs"));
34
40
  exports.tools = __importStar(require("../tools/index.cjs"));
41
+ exports.tools__render = __importStar(require("../tools/render.cjs"));
35
42
  exports.chains = __importStar(require("../chains/index.cjs"));
36
43
  exports.chains__openai_functions = __importStar(require("../chains/openai_functions/index.cjs"));
37
44
  exports.embeddings__base = __importStar(require("../embeddings/base.cjs"));
@@ -103,6 +110,7 @@ exports.stores__file__in_memory = __importStar(require("../stores/file/in_memory
103
110
  exports.stores__message__in_memory = __importStar(require("../stores/message/in_memory.cjs"));
104
111
  exports.storage__encoder_backed = __importStar(require("../storage/encoder_backed.cjs"));
105
112
  exports.storage__in_memory = __importStar(require("../storage/in_memory.cjs"));
113
+ exports.util__document = __importStar(require("../util/document.cjs"));
106
114
  exports.util__math = __importStar(require("../util/math.cjs"));
107
115
  exports.util__time = __importStar(require("../util/time.cjs"));
108
116
  exports.experimental__autogpt = __importStar(require("../experimental/autogpt/index.cjs"));
@@ -1,9 +1,16 @@
1
1
  export * as load__serializable from "../load/serializable.js";
2
2
  export * as agents from "../agents/index.js";
3
3
  export * as agents__toolkits from "../agents/toolkits/index.js";
4
- export * as agents__format_scratchpad from "../agents/format_scratchpad.js";
4
+ export * as agents__format_scratchpad from "../agents/format_scratchpad/openai_functions.js";
5
+ export * as agents__format_scratchpad__log from "../agents/format_scratchpad/log.js";
6
+ export * as agents__format_scratchpad__xml from "../agents/format_scratchpad/xml.js";
7
+ export * as agents__format_scratchpad__log_to_message from "../agents/format_scratchpad/log_to_message.js";
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";
5
11
  export * as base_language from "../base_language/index.js";
6
12
  export * as tools from "../tools/index.js";
13
+ export * as tools__render from "../tools/render.js";
7
14
  export * as chains from "../chains/index.js";
8
15
  export * as chains__openai_functions from "../chains/openai_functions/index.js";
9
16
  export * as embeddings__base from "../embeddings/base.js";
@@ -75,6 +82,7 @@ export * as stores__file__in_memory from "../stores/file/in_memory.js";
75
82
  export * as stores__message__in_memory from "../stores/message/in_memory.js";
76
83
  export * as storage__encoder_backed from "../storage/encoder_backed.js";
77
84
  export * as storage__in_memory from "../storage/in_memory.js";
85
+ export * as util__document from "../util/document.js";
78
86
  export * as util__math from "../util/math.js";
79
87
  export * as util__time from "../util/time.js";
80
88
  export * as experimental__autogpt from "../experimental/autogpt/index.js";
@@ -2,9 +2,16 @@
2
2
  export * as load__serializable from "../load/serializable.js";
3
3
  export * as agents from "../agents/index.js";
4
4
  export * as agents__toolkits from "../agents/toolkits/index.js";
5
- export * as agents__format_scratchpad from "../agents/format_scratchpad.js";
5
+ export * as agents__format_scratchpad from "../agents/format_scratchpad/openai_functions.js";
6
+ export * as agents__format_scratchpad__log from "../agents/format_scratchpad/log.js";
7
+ export * as agents__format_scratchpad__xml from "../agents/format_scratchpad/xml.js";
8
+ export * as agents__format_scratchpad__log_to_message from "../agents/format_scratchpad/log_to_message.js";
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";
6
12
  export * as base_language from "../base_language/index.js";
7
13
  export * as tools from "../tools/index.js";
14
+ export * as tools__render from "../tools/render.js";
8
15
  export * as chains from "../chains/index.js";
9
16
  export * as chains__openai_functions from "../chains/openai_functions/index.js";
10
17
  export * as embeddings__base from "../embeddings/base.js";
@@ -76,6 +83,7 @@ export * as stores__file__in_memory from "../stores/file/in_memory.js";
76
83
  export * as stores__message__in_memory from "../stores/message/in_memory.js";
77
84
  export * as storage__encoder_backed from "../storage/encoder_backed.js";
78
85
  export * as storage__in_memory from "../storage/in_memory.js";
86
+ export * as util__document from "../util/document.js";
79
87
  export * as util__math from "../util/math.js";
80
88
  export * as util__time from "../util/time.js";
81
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
- : results.map((r) => r.pageContent).join("\n"),
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.map((r) => r.pageContent).join("\n"),
59
+ : formatDocumentsAsString(results, "\n"),
59
60
  };
60
61
  }
61
62
  /**
@@ -0,0 +1,167 @@
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 __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;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.LocalFileStore = void 0;
27
+ const fs = __importStar(require("node:fs/promises"));
28
+ const path = __importStar(require("node:path"));
29
+ const storage_js_1 = require("../schema/storage.cjs");
30
+ /**
31
+ * File system implementation of the BaseStore using a dictionary. Used for
32
+ * storing key-value pairs in the file system.
33
+ */
34
+ class LocalFileStore extends storage_js_1.BaseStore {
35
+ constructor(fields) {
36
+ super(fields);
37
+ Object.defineProperty(this, "lc_namespace", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: ["langchain", "storage"]
42
+ });
43
+ Object.defineProperty(this, "rootPath", {
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true,
47
+ value: void 0
48
+ });
49
+ this.rootPath = fields.rootPath;
50
+ }
51
+ /**
52
+ * Read and parse the file at the given path.
53
+ * @param key The key to read the file for.
54
+ * @returns Promise that resolves to the parsed file content.
55
+ */
56
+ async getParsedFile(key) {
57
+ try {
58
+ const fileContent = await fs.readFile(this.getFullPath(key));
59
+ if (!fileContent) {
60
+ return undefined;
61
+ }
62
+ return fileContent;
63
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
+ }
65
+ catch (e) {
66
+ // File does not exist yet.
67
+ // eslint-disable-next-line no-instanceof/no-instanceof
68
+ if ("code" in e && e.code === "ENOENT") {
69
+ return undefined;
70
+ }
71
+ throw new Error(`Error reading and parsing file at path: ${this.rootPath}.\nError: ${JSON.stringify(e)}`);
72
+ }
73
+ }
74
+ /**
75
+ * Writes the given key-value pairs to the file at the given path.
76
+ * @param fileContent An object with the key-value pairs to be written to the file.
77
+ */
78
+ async setFileContent(content, key) {
79
+ try {
80
+ await fs.writeFile(this.getFullPath(key), content);
81
+ }
82
+ catch (error) {
83
+ throw new Error(`Error writing file at path: ${this.getFullPath(key)}.\nError: ${JSON.stringify(error)}`);
84
+ }
85
+ }
86
+ /**
87
+ * Returns the full path of the file where the value of the given key is stored.
88
+ * @param key the key to get the full path for
89
+ */
90
+ getFullPath(key) {
91
+ try {
92
+ const keyAsTxtFile = `${key}.txt`;
93
+ const fullPath = path.join(this.rootPath, keyAsTxtFile);
94
+ return fullPath;
95
+ }
96
+ catch (e) {
97
+ throw new Error(`Error getting full path for key: ${key}.\nError: ${JSON.stringify(e)}`);
98
+ }
99
+ }
100
+ /**
101
+ * Retrieves the values associated with the given keys from the store.
102
+ * @param keys Keys to retrieve values for.
103
+ * @returns Array of values associated with the given keys.
104
+ */
105
+ async mget(keys) {
106
+ const values = [];
107
+ for (const key of keys) {
108
+ const fileContent = await this.getParsedFile(key);
109
+ values.push(fileContent);
110
+ }
111
+ return values;
112
+ }
113
+ /**
114
+ * Sets the values for the given keys in the store.
115
+ * @param keyValuePairs Array of key-value pairs to set in the store.
116
+ * @returns Promise that resolves when all key-value pairs have been set.
117
+ */
118
+ async mset(keyValuePairs) {
119
+ await Promise.all(keyValuePairs.map(([key, value]) => this.setFileContent(value, key)));
120
+ }
121
+ /**
122
+ * Deletes the given keys and their associated values from the store.
123
+ * @param keys Keys to delete from the store.
124
+ * @returns Promise that resolves when all keys have been deleted.
125
+ */
126
+ async mdelete(keys) {
127
+ await Promise.all(keys.map((key) => fs.unlink(this.getFullPath(key))));
128
+ }
129
+ /**
130
+ * Asynchronous generator that yields keys from the store. If a prefix is
131
+ * provided, it only yields keys that start with the prefix.
132
+ * @param prefix Optional prefix to filter keys.
133
+ * @returns AsyncGenerator that yields keys from the store.
134
+ */
135
+ async *yieldKeys(prefix) {
136
+ const allFiles = await fs.readdir(this.rootPath);
137
+ const allKeys = allFiles.map((file) => file.replace(".txt", ""));
138
+ for (const key of allKeys) {
139
+ if (prefix === undefined || key.startsWith(prefix)) {
140
+ yield key;
141
+ }
142
+ }
143
+ }
144
+ /**
145
+ * Static method for initializing the class.
146
+ * Preforms a check to see if the directory exists, and if not, creates it.
147
+ * @param path Path to the directory.
148
+ * @returns Promise that resolves to an instance of the class.
149
+ */
150
+ static async fromPath(rootPath) {
151
+ try {
152
+ // Verifies the directory exists at the provided path, and that it is readable and writable.
153
+ await fs.access(rootPath, fs.constants.R_OK | fs.constants.W_OK);
154
+ }
155
+ catch (_) {
156
+ try {
157
+ // Directory does not exist, create it.
158
+ await fs.mkdir(rootPath, { recursive: true });
159
+ }
160
+ catch (error) {
161
+ throw new Error(`An error occurred creating directory at: ${rootPath}.\nError: ${JSON.stringify(error)}`);
162
+ }
163
+ }
164
+ return new this({ rootPath });
165
+ }
166
+ }
167
+ exports.LocalFileStore = LocalFileStore;
@@ -0,0 +1,60 @@
1
+ import { BaseStore } from "../schema/storage.js";
2
+ /**
3
+ * File system implementation of the BaseStore using a dictionary. Used for
4
+ * storing key-value pairs in the file system.
5
+ */
6
+ export declare class LocalFileStore extends BaseStore<string, Uint8Array> {
7
+ lc_namespace: string[];
8
+ rootPath: string;
9
+ constructor(fields: {
10
+ rootPath: string;
11
+ });
12
+ /**
13
+ * Read and parse the file at the given path.
14
+ * @param key The key to read the file for.
15
+ * @returns Promise that resolves to the parsed file content.
16
+ */
17
+ private getParsedFile;
18
+ /**
19
+ * Writes the given key-value pairs to the file at the given path.
20
+ * @param fileContent An object with the key-value pairs to be written to the file.
21
+ */
22
+ private setFileContent;
23
+ /**
24
+ * Returns the full path of the file where the value of the given key is stored.
25
+ * @param key the key to get the full path for
26
+ */
27
+ private getFullPath;
28
+ /**
29
+ * Retrieves the values associated with the given keys from the store.
30
+ * @param keys Keys to retrieve values for.
31
+ * @returns Array of values associated with the given keys.
32
+ */
33
+ mget(keys: string[]): Promise<(Uint8Array | undefined)[]>;
34
+ /**
35
+ * Sets the values for the given keys in the store.
36
+ * @param keyValuePairs Array of key-value pairs to set in the store.
37
+ * @returns Promise that resolves when all key-value pairs have been set.
38
+ */
39
+ mset(keyValuePairs: [string, Uint8Array][]): Promise<void>;
40
+ /**
41
+ * Deletes the given keys and their associated values from the store.
42
+ * @param keys Keys to delete from the store.
43
+ * @returns Promise that resolves when all keys have been deleted.
44
+ */
45
+ mdelete(keys: string[]): Promise<void>;
46
+ /**
47
+ * Asynchronous generator that yields keys from the store. If a prefix is
48
+ * provided, it only yields keys that start with the prefix.
49
+ * @param prefix Optional prefix to filter keys.
50
+ * @returns AsyncGenerator that yields keys from the store.
51
+ */
52
+ yieldKeys(prefix?: string): AsyncGenerator<string>;
53
+ /**
54
+ * Static method for initializing the class.
55
+ * Preforms a check to see if the directory exists, and if not, creates it.
56
+ * @param path Path to the directory.
57
+ * @returns Promise that resolves to an instance of the class.
58
+ */
59
+ static fromPath(rootPath: string): Promise<LocalFileStore>;
60
+ }
@@ -0,0 +1,140 @@
1
+ import * as fs from "node:fs/promises";
2
+ import * as path from "node:path";
3
+ import { BaseStore } from "../schema/storage.js";
4
+ /**
5
+ * File system implementation of the BaseStore using a dictionary. Used for
6
+ * storing key-value pairs in the file system.
7
+ */
8
+ export class LocalFileStore extends BaseStore {
9
+ constructor(fields) {
10
+ super(fields);
11
+ Object.defineProperty(this, "lc_namespace", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: ["langchain", "storage"]
16
+ });
17
+ Object.defineProperty(this, "rootPath", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: void 0
22
+ });
23
+ this.rootPath = fields.rootPath;
24
+ }
25
+ /**
26
+ * Read and parse the file at the given path.
27
+ * @param key The key to read the file for.
28
+ * @returns Promise that resolves to the parsed file content.
29
+ */
30
+ async getParsedFile(key) {
31
+ try {
32
+ const fileContent = await fs.readFile(this.getFullPath(key));
33
+ if (!fileContent) {
34
+ return undefined;
35
+ }
36
+ return fileContent;
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ }
39
+ catch (e) {
40
+ // File does not exist yet.
41
+ // eslint-disable-next-line no-instanceof/no-instanceof
42
+ if ("code" in e && e.code === "ENOENT") {
43
+ return undefined;
44
+ }
45
+ throw new Error(`Error reading and parsing file at path: ${this.rootPath}.\nError: ${JSON.stringify(e)}`);
46
+ }
47
+ }
48
+ /**
49
+ * Writes the given key-value pairs to the file at the given path.
50
+ * @param fileContent An object with the key-value pairs to be written to the file.
51
+ */
52
+ async setFileContent(content, key) {
53
+ try {
54
+ await fs.writeFile(this.getFullPath(key), content);
55
+ }
56
+ catch (error) {
57
+ throw new Error(`Error writing file at path: ${this.getFullPath(key)}.\nError: ${JSON.stringify(error)}`);
58
+ }
59
+ }
60
+ /**
61
+ * Returns the full path of the file where the value of the given key is stored.
62
+ * @param key the key to get the full path for
63
+ */
64
+ getFullPath(key) {
65
+ try {
66
+ const keyAsTxtFile = `${key}.txt`;
67
+ const fullPath = path.join(this.rootPath, keyAsTxtFile);
68
+ return fullPath;
69
+ }
70
+ catch (e) {
71
+ throw new Error(`Error getting full path for key: ${key}.\nError: ${JSON.stringify(e)}`);
72
+ }
73
+ }
74
+ /**
75
+ * Retrieves the values associated with the given keys from the store.
76
+ * @param keys Keys to retrieve values for.
77
+ * @returns Array of values associated with the given keys.
78
+ */
79
+ async mget(keys) {
80
+ const values = [];
81
+ for (const key of keys) {
82
+ const fileContent = await this.getParsedFile(key);
83
+ values.push(fileContent);
84
+ }
85
+ return values;
86
+ }
87
+ /**
88
+ * Sets the values for the given keys in the store.
89
+ * @param keyValuePairs Array of key-value pairs to set in the store.
90
+ * @returns Promise that resolves when all key-value pairs have been set.
91
+ */
92
+ async mset(keyValuePairs) {
93
+ await Promise.all(keyValuePairs.map(([key, value]) => this.setFileContent(value, key)));
94
+ }
95
+ /**
96
+ * Deletes the given keys and their associated values from the store.
97
+ * @param keys Keys to delete from the store.
98
+ * @returns Promise that resolves when all keys have been deleted.
99
+ */
100
+ async mdelete(keys) {
101
+ await Promise.all(keys.map((key) => fs.unlink(this.getFullPath(key))));
102
+ }
103
+ /**
104
+ * Asynchronous generator that yields keys from the store. If a prefix is
105
+ * provided, it only yields keys that start with the prefix.
106
+ * @param prefix Optional prefix to filter keys.
107
+ * @returns AsyncGenerator that yields keys from the store.
108
+ */
109
+ async *yieldKeys(prefix) {
110
+ const allFiles = await fs.readdir(this.rootPath);
111
+ const allKeys = allFiles.map((file) => file.replace(".txt", ""));
112
+ for (const key of allKeys) {
113
+ if (prefix === undefined || key.startsWith(prefix)) {
114
+ yield key;
115
+ }
116
+ }
117
+ }
118
+ /**
119
+ * Static method for initializing the class.
120
+ * Preforms a check to see if the directory exists, and if not, creates it.
121
+ * @param path Path to the directory.
122
+ * @returns Promise that resolves to an instance of the class.
123
+ */
124
+ static async fromPath(rootPath) {
125
+ try {
126
+ // Verifies the directory exists at the provided path, and that it is readable and writable.
127
+ await fs.access(rootPath, fs.constants.R_OK | fs.constants.W_OK);
128
+ }
129
+ catch (_) {
130
+ try {
131
+ // Directory does not exist, create it.
132
+ await fs.mkdir(rootPath, { recursive: true });
133
+ }
134
+ catch (error) {
135
+ throw new Error(`An error occurred creating directory at: ${rootPath}.\nError: ${JSON.stringify(error)}`);
136
+ }
137
+ }
138
+ return new this({ rootPath });
139
+ }
140
+ }
@@ -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; } });
@@ -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";
@@ -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";
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderTextDescriptionAndArgs = exports.renderTextDescription = void 0;
4
+ const zod_to_json_schema_1 = require("zod-to-json-schema");
5
+ /**
6
+ * Render the tool name and description in plain text.
7
+ *
8
+ * Output will be in the format of:
9
+ * ```
10
+ * search: This tool is used for search
11
+ * calculator: This tool is used for math
12
+ * ```
13
+ * @param tools
14
+ * @returns a string of all tools and their descriptions
15
+ */
16
+ function renderTextDescription(tools) {
17
+ return tools.map((tool) => `${tool.name}: ${tool.description}`).join("\n");
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;
@@ -0,0 +1,25 @@
1
+ import { StructuredTool } from "./base.js";
2
+ /**
3
+ * Render the tool name and description in plain text.
4
+ *
5
+ * Output will be in the format of:
6
+ * ```
7
+ * search: This tool is used for search
8
+ * calculator: This tool is used for math
9
+ * ```
10
+ * @param tools
11
+ * @returns a string of all tools and their descriptions
12
+ */
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;
@@ -0,0 +1,31 @@
1
+ import { zodToJsonSchema } from "zod-to-json-schema";
2
+ /**
3
+ * Render the tool name and description in plain text.
4
+ *
5
+ * Output will be in the format of:
6
+ * ```
7
+ * search: This tool is used for search
8
+ * calculator: This tool is used for math
9
+ * ```
10
+ * @param tools
11
+ * @returns a string of all tools and their descriptions
12
+ */
13
+ export function renderTextDescription(tools) {
14
+ return tools.map((tool) => `${tool.name}: ${tool.description}`).join("\n");
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
+ }
@@ -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/places-results).
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 = results.map((res) => res.pageContent).join("\n");
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());