langchain 0.0.64 → 0.0.65

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 (93) hide show
  1. package/dist/agents/agent.cjs +3 -4
  2. package/dist/agents/agent.js +3 -4
  3. package/dist/agents/chat_convo/prompt.cjs +1 -1
  4. package/dist/agents/chat_convo/prompt.d.ts +1 -1
  5. package/dist/agents/chat_convo/prompt.js +1 -1
  6. package/dist/agents/types.cjs +2 -2
  7. package/dist/agents/types.d.ts +2 -1
  8. package/dist/agents/types.js +1 -1
  9. package/dist/callbacks/manager.cjs +5 -1
  10. package/dist/callbacks/manager.js +5 -1
  11. package/dist/chains/analyze_documents_chain.cjs +1 -1
  12. package/dist/chains/analyze_documents_chain.js +1 -1
  13. package/dist/chains/base.cjs +25 -10
  14. package/dist/chains/base.d.ts +7 -3
  15. package/dist/chains/base.js +25 -10
  16. package/dist/chains/chat_vector_db_chain.cjs +1 -1
  17. package/dist/chains/chat_vector_db_chain.d.ts +7 -14
  18. package/dist/chains/chat_vector_db_chain.js +1 -1
  19. package/dist/chains/combine_docs_chain.cjs +3 -3
  20. package/dist/chains/combine_docs_chain.d.ts +2 -2
  21. package/dist/chains/combine_docs_chain.js +3 -3
  22. package/dist/chains/conversational_retrieval_chain.cjs +1 -1
  23. package/dist/chains/conversational_retrieval_chain.js +1 -1
  24. package/dist/chains/llm_chain.cjs +4 -4
  25. package/dist/chains/llm_chain.d.ts +3 -2
  26. package/dist/chains/llm_chain.js +4 -4
  27. package/dist/chains/retrieval_qa.cjs +1 -1
  28. package/dist/chains/retrieval_qa.js +1 -1
  29. package/dist/chains/sequential_chain.cjs +1 -1
  30. package/dist/chains/sequential_chain.js +1 -1
  31. package/dist/chains/sql_db/sql_db_chain.cjs +1 -1
  32. package/dist/chains/sql_db/sql_db_chain.js +1 -1
  33. package/dist/chains/vector_db_qa.cjs +1 -1
  34. package/dist/chains/vector_db_qa.js +1 -1
  35. package/dist/document_loaders/fs/unstructured.cjs +48 -1
  36. package/dist/document_loaders/fs/unstructured.d.ts +9 -1
  37. package/dist/document_loaders/fs/unstructured.js +46 -0
  38. package/dist/embeddings/tensorflow.cjs +67 -0
  39. package/dist/embeddings/tensorflow.d.ts +12 -0
  40. package/dist/embeddings/tensorflow.js +40 -0
  41. package/dist/experimental/autogpt/output_parser.cjs +2 -2
  42. package/dist/experimental/autogpt/output_parser.d.ts +1 -1
  43. package/dist/experimental/autogpt/output_parser.js +1 -1
  44. package/dist/memory/buffer_window_memory.cjs +2 -0
  45. package/dist/memory/buffer_window_memory.js +2 -0
  46. package/dist/output_parsers/combining.cjs +4 -4
  47. package/dist/output_parsers/combining.d.ts +3 -2
  48. package/dist/output_parsers/combining.js +3 -3
  49. package/dist/output_parsers/fix.cjs +6 -6
  50. package/dist/output_parsers/fix.d.ts +3 -2
  51. package/dist/output_parsers/fix.js +4 -4
  52. package/dist/output_parsers/list.cjs +3 -3
  53. package/dist/output_parsers/list.d.ts +1 -1
  54. package/dist/output_parsers/list.js +1 -1
  55. package/dist/output_parsers/regex.cjs +3 -3
  56. package/dist/output_parsers/regex.d.ts +1 -1
  57. package/dist/output_parsers/regex.js +1 -1
  58. package/dist/output_parsers/structured.cjs +10 -4
  59. package/dist/output_parsers/structured.d.ts +1 -1
  60. package/dist/output_parsers/structured.js +9 -3
  61. package/dist/prompts/base.d.ts +2 -1
  62. package/dist/prompts/chat.cjs +16 -2
  63. package/dist/prompts/chat.d.ts +2 -2
  64. package/dist/prompts/chat.js +16 -2
  65. package/dist/schema/index.cjs +1 -21
  66. package/dist/schema/index.d.ts +0 -30
  67. package/dist/schema/index.js +0 -18
  68. package/dist/schema/output_parser.cjs +23 -0
  69. package/dist/schema/output_parser.d.ts +32 -0
  70. package/dist/schema/output_parser.js +18 -0
  71. package/dist/tools/base.cjs +4 -4
  72. package/dist/tools/base.d.ts +4 -7
  73. package/dist/tools/base.js +4 -4
  74. package/dist/tools/fs.cjs +4 -4
  75. package/dist/tools/fs.d.ts +2 -2
  76. package/dist/tools/fs.js +4 -4
  77. package/dist/tools/serpapi.cjs +17 -10
  78. package/dist/tools/serpapi.d.ts +4 -1
  79. package/dist/tools/serpapi.js +17 -10
  80. package/dist/tools/webbrowser.cjs +4 -4
  81. package/dist/tools/webbrowser.d.ts +6 -6
  82. package/dist/tools/webbrowser.js +4 -4
  83. package/dist/util/flatten.cjs +21 -0
  84. package/dist/util/flatten.d.ts +1 -0
  85. package/dist/util/flatten.js +17 -0
  86. package/dist/vectorstores/pinecone.cjs +4 -0
  87. package/dist/vectorstores/pinecone.js +4 -0
  88. package/dist/vectorstores/weaviate.cjs +15 -9
  89. package/dist/vectorstores/weaviate.js +15 -9
  90. package/embeddings/tensorflow.cjs +1 -0
  91. package/embeddings/tensorflow.d.ts +1 -0
  92. package/embeddings/tensorflow.js +1 -0
  93. package/package.json +26 -3
@@ -218,15 +218,29 @@ class ChatPromptTemplate extends BaseChatPromptTemplate {
218
218
  return new ChatPromptTemplate(promptDict);
219
219
  }
220
220
  static fromPromptMessages(promptMessages) {
221
+ const flattenedMessages = promptMessages.reduce((acc, promptMessage) => acc.concat(
222
+ // eslint-disable-next-line no-instanceof/no-instanceof
223
+ promptMessage instanceof ChatPromptTemplate
224
+ ? promptMessage.promptMessages
225
+ : [promptMessage]), []);
226
+ const flattenedPartialVariables = promptMessages.reduce((acc, promptMessage) =>
227
+ // eslint-disable-next-line no-instanceof/no-instanceof
228
+ promptMessage instanceof ChatPromptTemplate
229
+ ? Object.assign(acc, promptMessage.partialVariables)
230
+ : acc, Object.create(null));
221
231
  const inputVariables = new Set();
222
- for (const promptMessage of promptMessages) {
232
+ for (const promptMessage of flattenedMessages) {
223
233
  for (const inputVariable of promptMessage.inputVariables) {
234
+ if (inputVariable in flattenedPartialVariables) {
235
+ continue;
236
+ }
224
237
  inputVariables.add(inputVariable);
225
238
  }
226
239
  }
227
240
  return new ChatPromptTemplate({
228
241
  inputVariables: [...inputVariables],
229
- promptMessages,
242
+ promptMessages: flattenedMessages,
243
+ partialVariables: flattenedPartialVariables,
230
244
  });
231
245
  }
232
246
  }
@@ -71,6 +71,6 @@ export declare class ChatPromptTemplate extends BaseChatPromptTemplate implement
71
71
  _getPromptType(): "chat";
72
72
  formatMessages(values: InputValues): Promise<BaseChatMessage[]>;
73
73
  serialize(): SerializedChatPromptTemplate;
74
- partial(values: PartialValues): Promise<BasePromptTemplate>;
75
- static fromPromptMessages(promptMessages: BaseMessagePromptTemplate[]): ChatPromptTemplate;
74
+ partial(values: PartialValues): Promise<ChatPromptTemplate>;
75
+ static fromPromptMessages(promptMessages: (BaseMessagePromptTemplate | ChatPromptTemplate)[]): ChatPromptTemplate;
76
76
  }
@@ -206,15 +206,29 @@ export class ChatPromptTemplate extends BaseChatPromptTemplate {
206
206
  return new ChatPromptTemplate(promptDict);
207
207
  }
208
208
  static fromPromptMessages(promptMessages) {
209
+ const flattenedMessages = promptMessages.reduce((acc, promptMessage) => acc.concat(
210
+ // eslint-disable-next-line no-instanceof/no-instanceof
211
+ promptMessage instanceof ChatPromptTemplate
212
+ ? promptMessage.promptMessages
213
+ : [promptMessage]), []);
214
+ const flattenedPartialVariables = promptMessages.reduce((acc, promptMessage) =>
215
+ // eslint-disable-next-line no-instanceof/no-instanceof
216
+ promptMessage instanceof ChatPromptTemplate
217
+ ? Object.assign(acc, promptMessage.partialVariables)
218
+ : acc, Object.create(null));
209
219
  const inputVariables = new Set();
210
- for (const promptMessage of promptMessages) {
220
+ for (const promptMessage of flattenedMessages) {
211
221
  for (const inputVariable of promptMessage.inputVariables) {
222
+ if (inputVariable in flattenedPartialVariables) {
223
+ continue;
224
+ }
212
225
  inputVariables.add(inputVariable);
213
226
  }
214
227
  }
215
228
  return new ChatPromptTemplate({
216
229
  inputVariables: [...inputVariables],
217
- promptMessages,
230
+ promptMessages: flattenedMessages,
231
+ partialVariables: flattenedPartialVariables,
218
232
  });
219
233
  }
220
234
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseFileStore = exports.BaseCache = exports.BaseChatMessageHistory = exports.OutputParserException = exports.BaseOutputParser = exports.BaseRetriever = exports.BasePromptValue = exports.ChatMessage = exports.SystemChatMessage = exports.AIChatMessage = exports.HumanChatMessage = exports.BaseChatMessage = exports.RUN_KEY = void 0;
3
+ exports.BaseFileStore = exports.BaseCache = exports.BaseChatMessageHistory = exports.BaseRetriever = exports.BasePromptValue = exports.ChatMessage = exports.SystemChatMessage = exports.AIChatMessage = exports.HumanChatMessage = exports.BaseChatMessage = exports.RUN_KEY = void 0;
4
4
  exports.RUN_KEY = "__run";
5
5
  class BaseChatMessage {
6
6
  constructor(text) {
@@ -68,26 +68,6 @@ exports.BasePromptValue = BasePromptValue;
68
68
  class BaseRetriever {
69
69
  }
70
70
  exports.BaseRetriever = BaseRetriever;
71
- /** Class to parse the output of an LLM call.
72
- */
73
- class BaseOutputParser {
74
- async parseWithPrompt(text, _prompt) {
75
- return this.parse(text);
76
- }
77
- /**
78
- * Return the string type key uniquely identifying this class of parser
79
- */
80
- _type() {
81
- throw new Error("_type not implemented");
82
- }
83
- }
84
- exports.BaseOutputParser = BaseOutputParser;
85
- class OutputParserException extends Error {
86
- constructor(message) {
87
- super(message);
88
- }
89
- }
90
- exports.OutputParserException = OutputParserException;
91
71
  class BaseChatMessageHistory {
92
72
  }
93
73
  exports.BaseChatMessageHistory = BaseChatMessageHistory;
@@ -92,36 +92,6 @@ export type ChainValues = Record<string, any>;
92
92
  export declare abstract class BaseRetriever {
93
93
  abstract getRelevantDocuments(query: string): Promise<Document[]>;
94
94
  }
95
- /** Class to parse the output of an LLM call.
96
- */
97
- export declare abstract class BaseOutputParser<T = unknown> {
98
- /**
99
- * Parse the output of an LLM call.
100
- *
101
- * @param text - LLM output to parse.
102
- * @returns Parsed output.
103
- */
104
- abstract parse(text: string): Promise<T>;
105
- parseWithPrompt(text: string, _prompt: BasePromptValue): Promise<T>;
106
- /**
107
- * Return a string describing the format of the output.
108
- * @returns Format instructions.
109
- * @example
110
- * ```json
111
- * {
112
- * "foo": "bar"
113
- * }
114
- * ```
115
- */
116
- abstract getFormatInstructions(): string;
117
- /**
118
- * Return the string type key uniquely identifying this class of parser
119
- */
120
- _type(): string;
121
- }
122
- export declare class OutputParserException extends Error {
123
- constructor(message: string);
124
- }
125
95
  export declare abstract class BaseChatMessageHistory {
126
96
  abstract getMessages(): Promise<BaseChatMessage[]>;
127
97
  abstract addUserMessage(message: string): Promise<void>;
@@ -58,24 +58,6 @@ export class BasePromptValue {
58
58
  */
59
59
  export class BaseRetriever {
60
60
  }
61
- /** Class to parse the output of an LLM call.
62
- */
63
- export class BaseOutputParser {
64
- async parseWithPrompt(text, _prompt) {
65
- return this.parse(text);
66
- }
67
- /**
68
- * Return the string type key uniquely identifying this class of parser
69
- */
70
- _type() {
71
- throw new Error("_type not implemented");
72
- }
73
- }
74
- export class OutputParserException extends Error {
75
- constructor(message) {
76
- super(message);
77
- }
78
- }
79
61
  export class BaseChatMessageHistory {
80
62
  }
81
63
  export class BaseCache {
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OutputParserException = exports.BaseOutputParser = void 0;
4
+ /** Class to parse the output of an LLM call.
5
+ */
6
+ class BaseOutputParser {
7
+ async parseWithPrompt(text, _prompt, callbacks) {
8
+ return this.parse(text, callbacks);
9
+ }
10
+ /**
11
+ * Return the string type key uniquely identifying this class of parser
12
+ */
13
+ _type() {
14
+ throw new Error("_type not implemented");
15
+ }
16
+ }
17
+ exports.BaseOutputParser = BaseOutputParser;
18
+ class OutputParserException extends Error {
19
+ constructor(message) {
20
+ super(message);
21
+ }
22
+ }
23
+ exports.OutputParserException = OutputParserException;
@@ -0,0 +1,32 @@
1
+ import { Callbacks } from "../callbacks/manager.js";
2
+ import { BasePromptValue } from "./index.js";
3
+ /** Class to parse the output of an LLM call.
4
+ */
5
+ export declare abstract class BaseOutputParser<T = unknown> {
6
+ /**
7
+ * Parse the output of an LLM call.
8
+ *
9
+ * @param text - LLM output to parse.
10
+ * @returns Parsed output.
11
+ */
12
+ abstract parse(text: string, callbacks?: Callbacks): Promise<T>;
13
+ parseWithPrompt(text: string, _prompt: BasePromptValue, callbacks?: Callbacks): Promise<T>;
14
+ /**
15
+ * Return a string describing the format of the output.
16
+ * @returns Format instructions.
17
+ * @example
18
+ * ```json
19
+ * {
20
+ * "foo": "bar"
21
+ * }
22
+ * ```
23
+ */
24
+ abstract getFormatInstructions(): string;
25
+ /**
26
+ * Return the string type key uniquely identifying this class of parser
27
+ */
28
+ _type(): string;
29
+ }
30
+ export declare class OutputParserException extends Error {
31
+ constructor(message: string);
32
+ }
@@ -0,0 +1,18 @@
1
+ /** Class to parse the output of an LLM call.
2
+ */
3
+ export class BaseOutputParser {
4
+ async parseWithPrompt(text, _prompt, callbacks) {
5
+ return this.parse(text, callbacks);
6
+ }
7
+ /**
8
+ * Return the string type key uniquely identifying this class of parser
9
+ */
10
+ _type() {
11
+ throw new Error("_type not implemented");
12
+ }
13
+ }
14
+ export class OutputParserException extends Error {
15
+ constructor(message) {
16
+ super(message);
17
+ }
18
+ }
@@ -5,8 +5,8 @@ const zod_1 = require("zod");
5
5
  const manager_js_1 = require("../callbacks/manager.cjs");
6
6
  const index_js_1 = require("../base_language/index.cjs");
7
7
  class StructuredTool extends index_js_1.BaseLangChain {
8
- constructor(verbose, callbacks) {
9
- super({ verbose, callbacks });
8
+ constructor(fields) {
9
+ super(fields ?? {});
10
10
  Object.defineProperty(this, "returnDirect", {
11
11
  enumerable: true,
12
12
  configurable: true,
@@ -32,8 +32,8 @@ class StructuredTool extends index_js_1.BaseLangChain {
32
32
  }
33
33
  exports.StructuredTool = StructuredTool;
34
34
  class Tool extends StructuredTool {
35
- constructor() {
36
- super(...arguments);
35
+ constructor(verbose, callbacks) {
36
+ super({ verbose, callbacks });
37
37
  Object.defineProperty(this, "schema", {
38
38
  enumerable: true,
39
39
  configurable: true,
@@ -1,16 +1,12 @@
1
1
  import { z } from "zod";
2
- import { CallbackManager, CallbackManagerForToolRun, Callbacks } from "../callbacks/manager.js";
2
+ import { CallbackManagerForToolRun, Callbacks } from "../callbacks/manager.js";
3
3
  import { BaseLangChain, BaseLangChainParams } from "../base_language/index.js";
4
4
  export interface ToolParams extends BaseLangChainParams {
5
- /**
6
- * @deprecated Use `callbacks` instead
7
- */
8
- callbackManager?: CallbackManager;
9
5
  }
10
6
  export declare abstract class StructuredTool<T extends z.ZodObject<any, any, any, any> = z.ZodObject<any, any, any, any>> extends BaseLangChain {
11
7
  abstract schema: T | z.ZodEffects<T>;
12
- constructor(verbose?: boolean, callbacks?: Callbacks);
13
- protected abstract _call(arg: z.output<T>, callbackManager?: CallbackManagerForToolRun): Promise<string>;
8
+ constructor(fields?: ToolParams);
9
+ protected abstract _call(arg: z.output<T>, runManager?: CallbackManagerForToolRun): Promise<string>;
14
10
  call(arg: (z.output<T> extends string ? string : never) | z.input<T>, callbacks?: Callbacks): Promise<string>;
15
11
  abstract name: string;
16
12
  abstract description: string;
@@ -26,5 +22,6 @@ export declare abstract class Tool extends StructuredTool {
26
22
  }>, string | undefined, {
27
23
  input?: string | undefined;
28
24
  }>;
25
+ constructor(verbose?: boolean, callbacks?: Callbacks);
29
26
  call(arg: string | undefined | z.input<this["schema"]>, callbacks?: Callbacks): Promise<string>;
30
27
  }
@@ -2,8 +2,8 @@ import { z } from "zod";
2
2
  import { CallbackManager, } from "../callbacks/manager.js";
3
3
  import { BaseLangChain } from "../base_language/index.js";
4
4
  export class StructuredTool extends BaseLangChain {
5
- constructor(verbose, callbacks) {
6
- super({ verbose, callbacks });
5
+ constructor(fields) {
6
+ super(fields ?? {});
7
7
  Object.defineProperty(this, "returnDirect", {
8
8
  enumerable: true,
9
9
  configurable: true,
@@ -28,8 +28,8 @@ export class StructuredTool extends BaseLangChain {
28
28
  }
29
29
  }
30
30
  export class Tool extends StructuredTool {
31
- constructor() {
32
- super(...arguments);
31
+ constructor(verbose, callbacks) {
32
+ super({ verbose, callbacks });
33
33
  Object.defineProperty(this, "schema", {
34
34
  enumerable: true,
35
35
  configurable: true,
package/dist/tools/fs.cjs CHANGED
@@ -4,8 +4,8 @@ exports.WriteFileTool = exports.ReadFileTool = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const base_js_1 = require("./base.cjs");
6
6
  class ReadFileTool extends base_js_1.StructuredTool {
7
- constructor({ verbose, callbacks, store }) {
8
- super(verbose, callbacks);
7
+ constructor({ store, ...rest }) {
8
+ super(rest);
9
9
  Object.defineProperty(this, "schema", {
10
10
  enumerable: true,
11
11
  configurable: true,
@@ -40,8 +40,8 @@ class ReadFileTool extends base_js_1.StructuredTool {
40
40
  }
41
41
  exports.ReadFileTool = ReadFileTool;
42
42
  class WriteFileTool extends base_js_1.StructuredTool {
43
- constructor({ verbose, callbacks, store }) {
44
- super(verbose, callbacks);
43
+ constructor({ store, ...rest }) {
44
+ super(rest);
45
45
  Object.defineProperty(this, "schema", {
46
46
  enumerable: true,
47
47
  configurable: true,
@@ -15,7 +15,7 @@ export declare class ReadFileTool extends StructuredTool {
15
15
  name: string;
16
16
  description: string;
17
17
  store: BaseFileStore;
18
- constructor({ verbose, callbacks, store }: ReadFileParams);
18
+ constructor({ store, ...rest }: ReadFileParams);
19
19
  _call({ file_path }: z.infer<typeof this.schema>): Promise<string>;
20
20
  }
21
21
  interface WriteFileParams extends ToolParams {
@@ -35,7 +35,7 @@ export declare class WriteFileTool extends StructuredTool {
35
35
  name: string;
36
36
  description: string;
37
37
  store: BaseFileStore;
38
- constructor({ verbose, callbacks, store }: WriteFileParams);
38
+ constructor({ store, ...rest }: WriteFileParams);
39
39
  _call({ file_path, text }: z.infer<typeof this.schema>): Promise<string>;
40
40
  }
41
41
  export {};
package/dist/tools/fs.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { z } from "zod";
2
2
  import { StructuredTool } from "./base.js";
3
3
  export class ReadFileTool extends StructuredTool {
4
- constructor({ verbose, callbacks, store }) {
5
- super(verbose, callbacks);
4
+ constructor({ store, ...rest }) {
5
+ super(rest);
6
6
  Object.defineProperty(this, "schema", {
7
7
  enumerable: true,
8
8
  configurable: true,
@@ -36,8 +36,8 @@ export class ReadFileTool extends StructuredTool {
36
36
  }
37
37
  }
38
38
  export class WriteFileTool extends StructuredTool {
39
- constructor({ verbose, callbacks, store }) {
40
- super(verbose, callbacks);
39
+ constructor({ store, ...rest }) {
40
+ super(rest);
41
41
  Object.defineProperty(this, "schema", {
42
42
  enumerable: true,
43
43
  configurable: true,
@@ -2,13 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SerpAPI = void 0;
4
4
  const base_js_1 = require("./base.cjs");
5
- function buildUrl(path, parameters) {
6
- const nonUndefinedParams = Object.entries(parameters)
7
- .filter(([_, value]) => value !== undefined)
8
- .map(([key, value]) => [key, `${value}`]);
9
- const searchParams = new URLSearchParams(nonUndefinedParams);
10
- return `https://serpapi.com/${path}?${searchParams}`;
11
- }
12
5
  /**
13
6
  * Wrapper around SerpAPI.
14
7
  *
@@ -18,7 +11,7 @@ class SerpAPI extends base_js_1.Tool {
18
11
  constructor(apiKey = typeof process !== "undefined"
19
12
  ? // eslint-disable-next-line no-process-env
20
13
  process.env?.SERPAPI_API_KEY
21
- : undefined, params = {}) {
14
+ : undefined, params = {}, baseUrl = "https://serpapi.com") {
22
15
  super();
23
16
  Object.defineProperty(this, "key", {
24
17
  enumerable: true,
@@ -32,6 +25,12 @@ class SerpAPI extends base_js_1.Tool {
32
25
  writable: true,
33
26
  value: void 0
34
27
  });
28
+ Object.defineProperty(this, "baseUrl", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: void 0
33
+ });
35
34
  Object.defineProperty(this, "name", {
36
35
  enumerable: true,
37
36
  configurable: true,
@@ -49,15 +48,23 @@ class SerpAPI extends base_js_1.Tool {
49
48
  }
50
49
  this.key = apiKey;
51
50
  this.params = params;
51
+ this.baseUrl = baseUrl;
52
+ }
53
+ buildUrl(path, parameters, baseUrl) {
54
+ const nonUndefinedParams = Object.entries(parameters)
55
+ .filter(([_, value]) => value !== undefined)
56
+ .map(([key, value]) => [key, `${value}`]);
57
+ const searchParams = new URLSearchParams(nonUndefinedParams);
58
+ return `${baseUrl}/${path}?${searchParams}`;
52
59
  }
53
60
  /** @ignore */
54
61
  async _call(input) {
55
62
  const { timeout, ...params } = this.params;
56
- const resp = await fetch(buildUrl("search", {
63
+ const resp = await fetch(this.buildUrl("search", {
57
64
  ...params,
58
65
  api_key: this.key,
59
66
  q: input,
60
- }), {
67
+ }, this.baseUrl), {
61
68
  signal: timeout ? AbortSignal.timeout(timeout) : undefined,
62
69
  });
63
70
  const res = await resp.json();
@@ -273,6 +273,7 @@ export interface SerpAPIParameters extends BaseParameters {
273
273
  */
274
274
  ijn?: string;
275
275
  }
276
+ type UrlParameters = Record<string, string | number | boolean | undefined | null>;
276
277
  /**
277
278
  * Wrapper around SerpAPI.
278
279
  *
@@ -281,8 +282,10 @@ export interface SerpAPIParameters extends BaseParameters {
281
282
  export declare class SerpAPI extends Tool {
282
283
  protected key: string;
283
284
  protected params: Partial<SerpAPIParameters>;
284
- constructor(apiKey?: string | undefined, params?: Partial<SerpAPIParameters>);
285
+ protected baseUrl: string;
286
+ constructor(apiKey?: string | undefined, params?: Partial<SerpAPIParameters>, baseUrl?: string);
285
287
  name: string;
288
+ protected buildUrl<P extends UrlParameters>(path: string, parameters: P, baseUrl: string): string;
286
289
  /** @ignore */
287
290
  _call(input: string): Promise<any>;
288
291
  description: string;
@@ -1,11 +1,4 @@
1
1
  import { Tool } from "./base.js";
2
- function buildUrl(path, parameters) {
3
- const nonUndefinedParams = Object.entries(parameters)
4
- .filter(([_, value]) => value !== undefined)
5
- .map(([key, value]) => [key, `${value}`]);
6
- const searchParams = new URLSearchParams(nonUndefinedParams);
7
- return `https://serpapi.com/${path}?${searchParams}`;
8
- }
9
2
  /**
10
3
  * Wrapper around SerpAPI.
11
4
  *
@@ -15,7 +8,7 @@ export class SerpAPI extends Tool {
15
8
  constructor(apiKey = typeof process !== "undefined"
16
9
  ? // eslint-disable-next-line no-process-env
17
10
  process.env?.SERPAPI_API_KEY
18
- : undefined, params = {}) {
11
+ : undefined, params = {}, baseUrl = "https://serpapi.com") {
19
12
  super();
20
13
  Object.defineProperty(this, "key", {
21
14
  enumerable: true,
@@ -29,6 +22,12 @@ export class SerpAPI extends Tool {
29
22
  writable: true,
30
23
  value: void 0
31
24
  });
25
+ Object.defineProperty(this, "baseUrl", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: void 0
30
+ });
32
31
  Object.defineProperty(this, "name", {
33
32
  enumerable: true,
34
33
  configurable: true,
@@ -46,15 +45,23 @@ export class SerpAPI extends Tool {
46
45
  }
47
46
  this.key = apiKey;
48
47
  this.params = params;
48
+ this.baseUrl = baseUrl;
49
+ }
50
+ buildUrl(path, parameters, baseUrl) {
51
+ const nonUndefinedParams = Object.entries(parameters)
52
+ .filter(([_, value]) => value !== undefined)
53
+ .map(([key, value]) => [key, `${value}`]);
54
+ const searchParams = new URLSearchParams(nonUndefinedParams);
55
+ return `${baseUrl}/${path}?${searchParams}`;
49
56
  }
50
57
  /** @ignore */
51
58
  async _call(input) {
52
59
  const { timeout, ...params } = this.params;
53
- const resp = await fetch(buildUrl("search", {
60
+ const resp = await fetch(this.buildUrl("search", {
54
61
  ...params,
55
62
  api_key: this.key,
56
63
  q: input,
57
- }), {
64
+ }, this.baseUrl), {
58
65
  signal: timeout ? AbortSignal.timeout(timeout) : undefined,
59
66
  });
60
67
  const res = await resp.json();
@@ -123,8 +123,8 @@ const DEFAULT_HEADERS = {
123
123
  "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0",
124
124
  };
125
125
  class WebBrowser extends base_js_2.Tool {
126
- constructor({ model, headers, embeddings, verbose, callbackManager, axiosConfig, }) {
127
- super(verbose, callbackManager);
126
+ constructor({ model, headers, embeddings, verbose, callbacks, callbackManager, axiosConfig, }) {
127
+ super(verbose, callbacks ?? callbackManager);
128
128
  Object.defineProperty(this, "model", {
129
129
  enumerable: true,
130
130
  configurable: true,
@@ -171,7 +171,7 @@ class WebBrowser extends base_js_2.Tool {
171
171
  };
172
172
  }
173
173
  /** @ignore */
174
- async _call(inputs) {
174
+ async _call(inputs, runManager) {
175
175
  const [baseUrl, task] = inputs.split(",").map((input) => {
176
176
  let t = input.trim();
177
177
  t = t.startsWith('"') ? t.slice(1) : t;
@@ -213,7 +213,7 @@ class WebBrowser extends base_js_2.Tool {
213
213
  context = results.map((res) => res.pageContent).join("\n");
214
214
  }
215
215
  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:".`;
216
- const res = await this.model.generatePrompt([new base_js_1.StringPromptValue(input)]);
216
+ const res = await this.model.generatePrompt([new base_js_1.StringPromptValue(input)], undefined, runManager?.getChild());
217
217
  return res.generations[0][0].text;
218
218
  }
219
219
  }
@@ -1,16 +1,16 @@
1
1
  import { AxiosRequestConfig } from "axios";
2
2
  import { BaseLanguageModel } from "../base_language/index.js";
3
- import { Tool } from "./base.js";
4
- import { CallbackManager } from "../callbacks/manager.js";
3
+ import { Tool, ToolParams } from "./base.js";
4
+ import { CallbackManager, CallbackManagerForToolRun } from "../callbacks/manager.js";
5
5
  import { Embeddings } from "../embeddings/base.js";
6
6
  export declare const getText: (html: string, baseUrl: string, summary: boolean) => string;
7
7
  type Headers = Record<string, any>;
8
- export interface WebBrowserArgs {
8
+ export interface WebBrowserArgs extends ToolParams {
9
9
  model: BaseLanguageModel;
10
10
  embeddings: Embeddings;
11
11
  headers?: Headers;
12
12
  axiosConfig?: Omit<AxiosRequestConfig, "url">;
13
- verbose?: boolean;
13
+ /** @deprecated */
14
14
  callbackManager?: CallbackManager;
15
15
  }
16
16
  export declare class WebBrowser extends Tool {
@@ -18,9 +18,9 @@ export declare class WebBrowser extends Tool {
18
18
  private embeddings;
19
19
  private headers;
20
20
  private axiosConfig;
21
- constructor({ model, headers, embeddings, verbose, callbackManager, axiosConfig, }: WebBrowserArgs);
21
+ constructor({ model, headers, embeddings, verbose, callbacks, callbackManager, axiosConfig, }: WebBrowserArgs);
22
22
  /** @ignore */
23
- _call(inputs: string): Promise<string>;
23
+ _call(inputs: string, runManager?: CallbackManagerForToolRun): Promise<string>;
24
24
  name: string;
25
25
  description: string;
26
26
  }
@@ -93,8 +93,8 @@ const DEFAULT_HEADERS = {
93
93
  "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0",
94
94
  };
95
95
  export class WebBrowser extends Tool {
96
- constructor({ model, headers, embeddings, verbose, callbackManager, axiosConfig, }) {
97
- super(verbose, callbackManager);
96
+ constructor({ model, headers, embeddings, verbose, callbacks, callbackManager, axiosConfig, }) {
97
+ super(verbose, callbacks ?? callbackManager);
98
98
  Object.defineProperty(this, "model", {
99
99
  enumerable: true,
100
100
  configurable: true,
@@ -141,7 +141,7 @@ export class WebBrowser extends Tool {
141
141
  };
142
142
  }
143
143
  /** @ignore */
144
- async _call(inputs) {
144
+ async _call(inputs, runManager) {
145
145
  const [baseUrl, task] = inputs.split(",").map((input) => {
146
146
  let t = input.trim();
147
147
  t = t.startsWith('"') ? t.slice(1) : t;
@@ -183,7 +183,7 @@ export class WebBrowser extends Tool {
183
183
  context = results.map((res) => res.pageContent).join("\n");
184
184
  }
185
185
  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:".`;
186
- const res = await this.model.generatePrompt([new StringPromptValue(input)]);
186
+ const res = await this.model.generatePrompt([new StringPromptValue(input)], undefined, runManager?.getChild());
187
187
  return res.generations[0][0].text;
188
188
  }
189
189
  }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flattenObject = void 0;
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ const flattenObject = (obj, deep = true) => {
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ const flattenedObject = {};
8
+ for (const key in obj) {
9
+ if (typeof obj[key] === "object" && !Array.isArray(obj[key])) {
10
+ let recursiveResult = obj[key];
11
+ if (deep)
12
+ recursiveResult = (0, exports.flattenObject)(recursiveResult);
13
+ for (const deepKey in recursiveResult) {
14
+ if (Object.hasOwn(obj, key))
15
+ flattenedObject[`${key}.${deepKey}`] = recursiveResult[deepKey];
16
+ }
17
+ }
18
+ }
19
+ return flattenedObject;
20
+ };
21
+ exports.flattenObject = flattenObject;
@@ -0,0 +1 @@
1
+ export declare const flattenObject: (obj: Record<string, any>, deep?: boolean) => Record<string, any>;