langchain 0.0.146 → 0.0.148

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 (168) hide show
  1. package/chat_models/googlevertexai/web.cjs +1 -0
  2. package/chat_models/googlevertexai/web.d.ts +1 -0
  3. package/chat_models/googlevertexai/web.js +1 -0
  4. package/chat_models/googlevertexai.cjs +1 -1
  5. package/chat_models/googlevertexai.d.ts +1 -1
  6. package/chat_models/googlevertexai.js +1 -1
  7. package/dist/base_language/index.cjs +2 -2
  8. package/dist/base_language/index.d.ts +2 -1
  9. package/dist/base_language/index.js +1 -1
  10. package/dist/chains/base.d.ts +1 -1
  11. package/dist/chains/constitutional_ai/constitutional_principle.cjs +272 -1
  12. package/dist/chains/constitutional_ai/constitutional_principle.js +272 -1
  13. package/dist/chains/openai_functions/openapi.cjs +32 -27
  14. package/dist/chains/openai_functions/openapi.d.ts +9 -0
  15. package/dist/chains/openai_functions/openapi.js +31 -27
  16. package/dist/chat_models/base.d.ts +1 -1
  17. package/dist/chat_models/{googlevertexai.cjs → googlevertexai/common.cjs} +14 -26
  18. package/dist/chat_models/{googlevertexai.d.ts → googlevertexai/common.d.ts} +13 -22
  19. package/dist/chat_models/{googlevertexai.js → googlevertexai/common.js} +12 -24
  20. package/dist/chat_models/googlevertexai/index.cjs +36 -0
  21. package/dist/chat_models/googlevertexai/index.d.ts +21 -0
  22. package/dist/chat_models/googlevertexai/index.js +31 -0
  23. package/dist/chat_models/googlevertexai/web.cjs +33 -0
  24. package/dist/chat_models/googlevertexai/web.d.ts +19 -0
  25. package/dist/chat_models/googlevertexai/web.js +28 -0
  26. package/dist/chat_models/openai.cjs +1 -1
  27. package/dist/chat_models/openai.js +1 -1
  28. package/dist/document_loaders/web/notionapi.cjs +93 -70
  29. package/dist/document_loaders/web/notionapi.d.ts +33 -1
  30. package/dist/document_loaders/web/notionapi.js +89 -71
  31. package/dist/embeddings/googlevertexai.cjs +5 -1
  32. package/dist/embeddings/googlevertexai.d.ts +2 -1
  33. package/dist/embeddings/googlevertexai.js +5 -1
  34. package/dist/evaluation/agents/index.cjs +17 -0
  35. package/dist/evaluation/agents/index.d.ts +1 -0
  36. package/dist/evaluation/agents/index.js +1 -0
  37. package/dist/evaluation/agents/prompt.cjs +132 -0
  38. package/dist/evaluation/agents/prompt.d.ts +6 -0
  39. package/dist/evaluation/agents/prompt.js +129 -0
  40. package/dist/evaluation/agents/trajectory.cjs +189 -0
  41. package/dist/evaluation/agents/trajectory.d.ts +54 -0
  42. package/dist/evaluation/agents/trajectory.js +184 -0
  43. package/dist/evaluation/base.cjs +274 -0
  44. package/dist/evaluation/base.d.ts +232 -0
  45. package/dist/evaluation/base.js +263 -0
  46. package/dist/evaluation/comparison/index.cjs +17 -0
  47. package/dist/evaluation/comparison/index.d.ts +1 -0
  48. package/dist/evaluation/comparison/index.js +1 -0
  49. package/dist/evaluation/comparison/pairwise.cjs +244 -0
  50. package/dist/evaluation/comparison/pairwise.d.ts +50 -0
  51. package/dist/evaluation/comparison/pairwise.js +238 -0
  52. package/dist/evaluation/comparison/prompt.cjs +74 -0
  53. package/dist/evaluation/comparison/prompt.d.ts +21 -0
  54. package/dist/evaluation/comparison/prompt.js +71 -0
  55. package/dist/evaluation/criteria/criteria.cjs +259 -0
  56. package/dist/evaluation/criteria/criteria.d.ts +73 -0
  57. package/dist/evaluation/criteria/criteria.js +253 -0
  58. package/dist/evaluation/criteria/index.cjs +17 -0
  59. package/dist/evaluation/criteria/index.d.ts +1 -0
  60. package/dist/evaluation/criteria/index.js +1 -0
  61. package/dist/evaluation/criteria/prompt.cjs +36 -0
  62. package/dist/evaluation/criteria/prompt.d.ts +12 -0
  63. package/dist/evaluation/criteria/prompt.js +33 -0
  64. package/dist/evaluation/embedding_distance/base.cjs +163 -0
  65. package/dist/evaluation/embedding_distance/base.d.ts +78 -0
  66. package/dist/evaluation/embedding_distance/base.js +156 -0
  67. package/dist/evaluation/embedding_distance/index.cjs +17 -0
  68. package/dist/evaluation/embedding_distance/index.d.ts +1 -0
  69. package/dist/evaluation/embedding_distance/index.js +1 -0
  70. package/dist/evaluation/index.cjs +6 -0
  71. package/dist/evaluation/index.d.ts +6 -0
  72. package/dist/evaluation/index.js +6 -0
  73. package/dist/evaluation/loader.cjs +60 -0
  74. package/dist/evaluation/loader.d.ts +27 -0
  75. package/dist/evaluation/loader.js +56 -0
  76. package/dist/evaluation/types.cjs +2 -0
  77. package/dist/evaluation/types.d.ts +35 -0
  78. package/dist/evaluation/types.js +1 -0
  79. package/dist/experimental/llms/bittensor.cjs +141 -0
  80. package/dist/experimental/llms/bittensor.d.ts +33 -0
  81. package/dist/experimental/llms/bittensor.js +137 -0
  82. package/dist/experimental/multimodal_embeddings/googlevertexai.cjs +5 -1
  83. package/dist/experimental/multimodal_embeddings/googlevertexai.d.ts +2 -1
  84. package/dist/experimental/multimodal_embeddings/googlevertexai.js +5 -1
  85. package/dist/hub.d.ts +1 -1
  86. package/dist/llms/base.d.ts +1 -1
  87. package/dist/llms/{googlevertexai.js → googlevertexai/common.cjs} +21 -17
  88. package/dist/llms/{googlevertexai.d.ts → googlevertexai/common.d.ts} +13 -23
  89. package/dist/llms/{googlevertexai.cjs → googlevertexai/common.js} +17 -21
  90. package/dist/llms/googlevertexai/index.cjs +34 -0
  91. package/dist/llms/googlevertexai/index.d.ts +26 -0
  92. package/dist/llms/googlevertexai/index.js +30 -0
  93. package/dist/llms/googlevertexai/web.cjs +31 -0
  94. package/dist/llms/googlevertexai/web.d.ts +24 -0
  95. package/dist/llms/googlevertexai/web.js +27 -0
  96. package/dist/llms/openai-chat.cjs +1 -1
  97. package/dist/llms/openai-chat.js +1 -1
  98. package/dist/llms/openai.cjs +1 -1
  99. package/dist/llms/openai.js +1 -1
  100. package/dist/load/import_constants.cjs +3 -0
  101. package/dist/load/import_constants.js +3 -0
  102. package/dist/load/import_map.cjs +3 -2
  103. package/dist/load/import_map.d.ts +2 -1
  104. package/dist/load/import_map.js +2 -1
  105. package/dist/load/index.cjs +2 -1
  106. package/dist/load/index.js +2 -1
  107. package/dist/load/serializable.cjs +23 -4
  108. package/dist/load/serializable.js +23 -4
  109. package/dist/prompts/base.cjs +2 -2
  110. package/dist/prompts/base.d.ts +1 -1
  111. package/dist/prompts/base.js +1 -1
  112. package/dist/prompts/chat.cjs +2 -2
  113. package/dist/prompts/chat.d.ts +1 -1
  114. package/dist/prompts/chat.js +1 -1
  115. package/dist/retrievers/multi_query.cjs +140 -0
  116. package/dist/retrievers/multi_query.d.ts +33 -0
  117. package/dist/retrievers/multi_query.js +136 -0
  118. package/dist/schema/document.cjs +2 -2
  119. package/dist/schema/document.d.ts +1 -1
  120. package/dist/schema/document.js +1 -1
  121. package/dist/schema/output_parser.cjs +2 -2
  122. package/dist/schema/output_parser.d.ts +2 -1
  123. package/dist/schema/output_parser.js +1 -1
  124. package/dist/schema/retriever.cjs +2 -2
  125. package/dist/schema/retriever.d.ts +2 -1
  126. package/dist/schema/retriever.js +1 -1
  127. package/dist/schema/runnable/config.cjs +8 -0
  128. package/dist/schema/runnable/config.d.ts +3 -0
  129. package/dist/schema/runnable/config.js +4 -0
  130. package/dist/schema/{runnable.cjs → runnable/index.cjs} +290 -101
  131. package/dist/schema/{runnable.d.ts → runnable/index.d.ts} +127 -41
  132. package/dist/schema/{runnable.js → runnable/index.js} +284 -99
  133. package/dist/tools/base.d.ts +1 -1
  134. package/dist/types/googlevertexai-types.d.ts +11 -4
  135. package/dist/util/async_caller.cjs +35 -25
  136. package/dist/util/async_caller.d.ts +8 -0
  137. package/dist/util/async_caller.js +35 -25
  138. package/dist/util/googlevertexai-connection.cjs +14 -15
  139. package/dist/util/googlevertexai-connection.d.ts +7 -7
  140. package/dist/util/googlevertexai-connection.js +14 -15
  141. package/dist/util/googlevertexai-webauth.cjs +56 -0
  142. package/dist/util/googlevertexai-webauth.d.ts +25 -0
  143. package/dist/util/googlevertexai-webauth.js +52 -0
  144. package/dist/vectorstores/googlevertexai.cjs +9 -8
  145. package/dist/vectorstores/googlevertexai.d.ts +8 -7
  146. package/dist/vectorstores/googlevertexai.js +9 -8
  147. package/dist/vectorstores/pinecone.cjs +30 -22
  148. package/dist/vectorstores/pinecone.d.ts +3 -1
  149. package/dist/vectorstores/pinecone.js +30 -22
  150. package/dist/vectorstores/vectara.cjs +20 -23
  151. package/dist/vectorstores/vectara.d.ts +9 -2
  152. package/dist/vectorstores/vectara.js +20 -23
  153. package/experimental/llms/bittensor.cjs +1 -0
  154. package/experimental/llms/bittensor.d.ts +1 -0
  155. package/experimental/llms/bittensor.js +1 -0
  156. package/llms/googlevertexai/web.cjs +1 -0
  157. package/llms/googlevertexai/web.d.ts +1 -0
  158. package/llms/googlevertexai/web.js +1 -0
  159. package/llms/googlevertexai.cjs +1 -1
  160. package/llms/googlevertexai.d.ts +1 -1
  161. package/llms/googlevertexai.js +1 -1
  162. package/package.json +40 -3
  163. package/retrievers/multi_query.cjs +1 -0
  164. package/retrievers/multi_query.d.ts +1 -0
  165. package/retrievers/multi_query.js +1 -0
  166. package/schema/runnable.cjs +1 -1
  167. package/schema/runnable.d.ts +1 -1
  168. package/schema/runnable.js +1 -1
@@ -0,0 +1,33 @@
1
+ import { LLMChain } from "../chains/llm_chain.js";
2
+ import { Document } from "../document.js";
3
+ import { BaseRetriever, BaseRetrieverInput } from "../schema/retriever.js";
4
+ import { CallbackManagerForRetrieverRun } from "../callbacks/index.js";
5
+ import { BaseLanguageModel } from "../base_language/index.js";
6
+ import { BasePromptTemplate } from "../prompts/base.js";
7
+ interface LineList {
8
+ lines: string[];
9
+ }
10
+ export interface MultiQueryRetrieverInput extends BaseRetrieverInput {
11
+ retriever: BaseRetriever;
12
+ llmChain: LLMChain<LineList>;
13
+ queryCount?: number;
14
+ parserKey?: string;
15
+ }
16
+ export declare class MultiQueryRetriever extends BaseRetriever {
17
+ static lc_name(): string;
18
+ lc_namespace: string[];
19
+ private retriever;
20
+ private llmChain;
21
+ private queryCount;
22
+ private parserKey;
23
+ constructor(fields: MultiQueryRetrieverInput);
24
+ static fromLLM(fields: Omit<MultiQueryRetrieverInput, "llmChain"> & {
25
+ llm: BaseLanguageModel;
26
+ prompt?: BasePromptTemplate;
27
+ }): MultiQueryRetriever;
28
+ private _generateQueries;
29
+ private _retrieveDocuments;
30
+ private _uniqueUnion;
31
+ _getRelevantDocuments(question: string, runManager?: CallbackManagerForRetrieverRun): Promise<Document[]>;
32
+ }
33
+ export {};
@@ -0,0 +1,136 @@
1
+ import { LLMChain } from "../chains/llm_chain.js";
2
+ import { PromptTemplate } from "../prompts/prompt.js";
3
+ import { BaseOutputParser } from "../schema/output_parser.js";
4
+ import { BaseRetriever } from "../schema/retriever.js";
5
+ class LineListOutputParser extends BaseOutputParser {
6
+ constructor() {
7
+ super(...arguments);
8
+ Object.defineProperty(this, "lc_namespace", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: ["langchain", "retrievers", "multiquery"]
13
+ });
14
+ }
15
+ static lc_name() {
16
+ return "LineListOutputParser";
17
+ }
18
+ async parse(text) {
19
+ const startKeyIndex = text.indexOf("<questions>");
20
+ const endKeyIndex = text.indexOf("</questions>");
21
+ const questionsStartIndex = startKeyIndex === -1 ? 0 : startKeyIndex + "<questions>".length;
22
+ const questionsEndIndex = endKeyIndex === -1 ? text.length : endKeyIndex;
23
+ const lines = text
24
+ .slice(questionsStartIndex, questionsEndIndex)
25
+ .trim()
26
+ .split("\n")
27
+ .filter((line) => line.trim() !== "");
28
+ return { lines };
29
+ }
30
+ getFormatInstructions() {
31
+ throw new Error("Not implemented.");
32
+ }
33
+ }
34
+ // Create template
35
+ const DEFAULT_QUERY_PROMPT = /* #__PURE__ */ new PromptTemplate({
36
+ inputVariables: ["question", "queryCount"],
37
+ template: `You are an AI language model assistant. Your task is
38
+ to generate {queryCount} different versions of the given user
39
+ question to retrieve relevant documents from a vector database.
40
+ By generating multiple perspectives on the user question,
41
+ your goal is to help the user overcome some of the limitations
42
+ of distance-based similarity search.
43
+
44
+ Provide these alternative questions separated by newlines between XML tags. For example:
45
+
46
+ <questions>
47
+ Question 1
48
+ Question 2
49
+ Question 3
50
+ </questions>
51
+
52
+ Original question: {question}`,
53
+ });
54
+ // Export class
55
+ export class MultiQueryRetriever extends BaseRetriever {
56
+ static lc_name() {
57
+ return "MultiQueryRetriever";
58
+ }
59
+ constructor(fields) {
60
+ super(fields);
61
+ Object.defineProperty(this, "lc_namespace", {
62
+ enumerable: true,
63
+ configurable: true,
64
+ writable: true,
65
+ value: ["langchain", "retrievers", "multiquery"]
66
+ });
67
+ Object.defineProperty(this, "retriever", {
68
+ enumerable: true,
69
+ configurable: true,
70
+ writable: true,
71
+ value: void 0
72
+ });
73
+ Object.defineProperty(this, "llmChain", {
74
+ enumerable: true,
75
+ configurable: true,
76
+ writable: true,
77
+ value: void 0
78
+ });
79
+ Object.defineProperty(this, "queryCount", {
80
+ enumerable: true,
81
+ configurable: true,
82
+ writable: true,
83
+ value: 3
84
+ });
85
+ Object.defineProperty(this, "parserKey", {
86
+ enumerable: true,
87
+ configurable: true,
88
+ writable: true,
89
+ value: "lines"
90
+ });
91
+ this.retriever = fields.retriever;
92
+ this.llmChain = fields.llmChain;
93
+ this.queryCount = fields.queryCount ?? this.queryCount;
94
+ this.parserKey = fields.parserKey ?? this.parserKey;
95
+ }
96
+ static fromLLM(fields) {
97
+ const { retriever, llm, prompt = DEFAULT_QUERY_PROMPT, queryCount, parserKey, ...rest } = fields;
98
+ const outputParser = new LineListOutputParser();
99
+ const llmChain = new LLMChain({ llm, prompt, outputParser });
100
+ return new this({ retriever, llmChain, queryCount, parserKey, ...rest });
101
+ }
102
+ // Generate the different queries for each retrieval, using our llmChain
103
+ async _generateQueries(question, runManager) {
104
+ const response = await this.llmChain.call({ question, queryCount: this.queryCount }, runManager?.getChild());
105
+ const lines = response.text[this.parserKey] || [];
106
+ if (this.verbose) {
107
+ console.log(`Generated queries: ${lines}`);
108
+ }
109
+ return lines;
110
+ }
111
+ // Retrieve documents using the original retriever
112
+ async _retrieveDocuments(queries, runManager) {
113
+ const documents = [];
114
+ for (const query of queries) {
115
+ const docs = await this.retriever.getRelevantDocuments(query, runManager?.getChild());
116
+ documents.push(...docs);
117
+ }
118
+ return documents;
119
+ }
120
+ // Deduplicate the documents that were returned in multiple retrievals
121
+ _uniqueUnion(documents) {
122
+ const uniqueDocumentsDict = {};
123
+ for (const doc of documents) {
124
+ const key = `${doc.pageContent}:${JSON.stringify(Object.entries(doc.metadata).sort())}`;
125
+ uniqueDocumentsDict[key] = doc;
126
+ }
127
+ const uniqueDocuments = Object.values(uniqueDocumentsDict);
128
+ return uniqueDocuments;
129
+ }
130
+ async _getRelevantDocuments(question, runManager) {
131
+ const queries = await this._generateQueries(question, runManager);
132
+ const documents = await this._retrieveDocuments(queries, runManager);
133
+ const uniqueDocuments = this._uniqueUnion(documents);
134
+ return uniqueDocuments;
135
+ }
136
+ }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MappingDocumentTransformer = exports.BaseDocumentTransformer = void 0;
4
- const runnable_js_1 = require("./runnable.cjs");
4
+ const index_js_1 = require("./runnable/index.cjs");
5
5
  /**
6
6
  * Abstract base class for document transformation systems.
7
7
  *
@@ -12,7 +12,7 @@ const runnable_js_1 = require("./runnable.cjs");
12
12
  * One example of this is a text splitter that splits a large document into
13
13
  * many smaller documents.
14
14
  */
15
- class BaseDocumentTransformer extends runnable_js_1.Runnable {
15
+ class BaseDocumentTransformer extends index_js_1.Runnable {
16
16
  constructor() {
17
17
  super(...arguments);
18
18
  Object.defineProperty(this, "lc_namespace", {
@@ -1,6 +1,6 @@
1
1
  import { BaseCallbackConfig } from "../callbacks/manager.js";
2
2
  import { Document } from "../document.js";
3
- import { Runnable } from "./runnable.js";
3
+ import { Runnable } from "./runnable/index.js";
4
4
  /**
5
5
  * Abstract base class for document transformation systems.
6
6
  *
@@ -1,4 +1,4 @@
1
- import { Runnable } from "./runnable.js";
1
+ import { Runnable } from "./runnable/index.js";
2
2
  /**
3
3
  * Abstract base class for document transformation systems.
4
4
  *
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OutputParserException = exports.BytesOutputParser = exports.StringOutputParser = exports.BaseTransformOutputParser = exports.BaseOutputParser = exports.BaseLLMOutputParser = void 0;
4
- const runnable_js_1 = require("./runnable.cjs");
4
+ const index_js_1 = require("./runnable/index.cjs");
5
5
  /**
6
6
  * Abstract base class for parsing the output of a Large Language Model
7
7
  * (LLM) call. It provides methods for parsing the result of an LLM call
8
8
  * and invoking the parser with a given input.
9
9
  */
10
- class BaseLLMOutputParser extends runnable_js_1.Runnable {
10
+ class BaseLLMOutputParser extends index_js_1.Runnable {
11
11
  /**
12
12
  * Parses the result of an LLM call with a given prompt. By default, it
13
13
  * simply calls `parseResult`.
@@ -1,6 +1,7 @@
1
1
  import { BaseCallbackConfig, Callbacks } from "../callbacks/manager.js";
2
2
  import { BasePromptValue, Generation, ChatGeneration, BaseMessage } from "./index.js";
3
- import { Runnable, RunnableConfig } from "./runnable.js";
3
+ import { Runnable } from "./runnable/index.js";
4
+ import { RunnableConfig } from "./runnable/config.js";
4
5
  /**
5
6
  * Options for formatting instructions.
6
7
  */
@@ -1,4 +1,4 @@
1
- import { Runnable } from "./runnable.js";
1
+ import { Runnable } from "./runnable/index.js";
2
2
  /**
3
3
  * Abstract base class for parsing the output of a Large Language Model
4
4
  * (LLM) call. It provides methods for parsing the result of an LLM call
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseRetriever = void 0;
4
4
  const manager_js_1 = require("../callbacks/manager.cjs");
5
- const runnable_js_1 = require("./runnable.cjs");
5
+ const index_js_1 = require("./runnable/index.cjs");
6
6
  /**
7
7
  * Abstract base class for a Document retrieval system. A retrieval system
8
8
  * is defined as something that can take string queries and return the
9
9
  * most 'relevant' Documents from some source.
10
10
  */
11
- class BaseRetriever extends runnable_js_1.Runnable {
11
+ class BaseRetriever extends index_js_1.Runnable {
12
12
  constructor(fields) {
13
13
  super(fields);
14
14
  Object.defineProperty(this, "callbacks", {
@@ -1,6 +1,7 @@
1
1
  import { BaseCallbackConfig, CallbackManagerForRetrieverRun, Callbacks } from "../callbacks/manager.js";
2
2
  import { Document } from "../document.js";
3
- import { Runnable, RunnableConfig } from "./runnable.js";
3
+ import { Runnable } from "./runnable/index.js";
4
+ import { RunnableConfig } from "./runnable/config.js";
4
5
  /**
5
6
  * Base Retriever class. All indexes should extend this class.
6
7
  */
@@ -1,5 +1,5 @@
1
1
  import { CallbackManager, parseCallbackConfigArg, } from "../callbacks/manager.js";
2
- import { Runnable } from "./runnable.js";
2
+ import { Runnable } from "./runnable/index.js";
3
3
  /**
4
4
  * Abstract base class for a Document retrieval system. A retrieval system
5
5
  * is defined as something that can take string queries and return the
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCallbackMangerForConfig = void 0;
4
+ const manager_js_1 = require("../../callbacks/manager.cjs");
5
+ async function getCallbackMangerForConfig(config) {
6
+ return manager_js_1.CallbackManager.configure(config?.callbacks, undefined, config?.tags, undefined, config?.metadata);
7
+ }
8
+ exports.getCallbackMangerForConfig = getCallbackMangerForConfig;
@@ -0,0 +1,3 @@
1
+ import { BaseCallbackConfig, CallbackManager } from "../../callbacks/manager.js";
2
+ export type RunnableConfig = BaseCallbackConfig;
3
+ export declare function getCallbackMangerForConfig(config?: RunnableConfig): Promise<CallbackManager | undefined>;
@@ -0,0 +1,4 @@
1
+ import { CallbackManager, } from "../../callbacks/manager.js";
2
+ export async function getCallbackMangerForConfig(config) {
3
+ return CallbackManager.configure(config?.callbacks, undefined, config?.tags, undefined, config?.metadata);
4
+ }