langchain 0.0.63 → 0.0.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/initialize.cjs +1 -1
- package/dist/agents/initialize.d.ts +1 -1
- package/dist/agents/initialize.js +1 -1
- package/dist/base_language/index.d.ts +4 -1
- package/dist/chains/analyze_documents_chain.cjs +2 -2
- package/dist/chains/analyze_documents_chain.d.ts +2 -1
- package/dist/chains/analyze_documents_chain.js +2 -2
- package/dist/chains/base.cjs +5 -1
- package/dist/chains/base.js +5 -1
- package/dist/chains/chat_vector_db_chain.cjs +3 -3
- package/dist/chains/chat_vector_db_chain.d.ts +2 -1
- package/dist/chains/chat_vector_db_chain.js +3 -3
- package/dist/chains/combine_docs_chain.cjs +8 -8
- package/dist/chains/combine_docs_chain.d.ts +4 -3
- package/dist/chains/combine_docs_chain.js +8 -8
- package/dist/chains/conversational_retrieval_chain.cjs +3 -3
- package/dist/chains/conversational_retrieval_chain.d.ts +2 -1
- package/dist/chains/conversational_retrieval_chain.js +3 -3
- package/dist/chains/index.cjs +4 -3
- package/dist/chains/index.d.ts +2 -2
- package/dist/chains/index.js +1 -1
- package/dist/chains/retrieval_qa.cjs +2 -2
- package/dist/chains/retrieval_qa.d.ts +2 -1
- package/dist/chains/retrieval_qa.js +2 -2
- package/dist/chains/sequential_chain.cjs +262 -0
- package/dist/chains/{simple_sequential_chain.d.ts → sequential_chain.d.ts} +31 -2
- package/dist/chains/sequential_chain.js +257 -0
- package/dist/chains/serde.d.ts +7 -1
- package/dist/chains/sql_db/sql_db_chain.cjs +6 -4
- package/dist/chains/sql_db/sql_db_chain.d.ts +2 -1
- package/dist/chains/sql_db/sql_db_chain.js +6 -4
- package/dist/chains/vector_db_qa.cjs +2 -2
- package/dist/chains/vector_db_qa.d.ts +2 -1
- package/dist/chains/vector_db_qa.js +2 -2
- package/dist/chat_models/base.d.ts +10 -8
- package/dist/chat_models/openai.cjs +9 -5
- package/dist/chat_models/openai.d.ts +14 -5
- package/dist/chat_models/openai.js +10 -6
- package/dist/experimental/babyagi/agent.cjs +194 -0
- package/dist/experimental/babyagi/agent.d.ts +47 -0
- package/dist/experimental/babyagi/agent.js +190 -0
- package/dist/experimental/babyagi/index.cjs +11 -0
- package/dist/experimental/babyagi/index.d.ts +4 -0
- package/dist/experimental/babyagi/index.js +4 -0
- package/dist/experimental/babyagi/task_creation.cjs +29 -0
- package/dist/experimental/babyagi/task_creation.d.ts +5 -0
- package/dist/experimental/babyagi/task_creation.js +25 -0
- package/dist/experimental/babyagi/task_execution.cjs +20 -0
- package/dist/experimental/babyagi/task_execution.d.ts +5 -0
- package/dist/experimental/babyagi/task_execution.js +16 -0
- package/dist/experimental/babyagi/task_prioritization.cjs +23 -0
- package/dist/experimental/babyagi/task_prioritization.d.ts +5 -0
- package/dist/experimental/babyagi/task_prioritization.js +19 -0
- package/dist/llms/base.cjs +0 -9
- package/dist/llms/base.d.ts +11 -12
- package/dist/llms/base.js +0 -9
- package/dist/llms/openai-chat.cjs +9 -5
- package/dist/llms/openai-chat.d.ts +16 -7
- package/dist/llms/openai-chat.js +9 -5
- package/dist/llms/openai.cjs +9 -5
- package/dist/llms/openai.d.ts +15 -12
- package/dist/llms/openai.js +10 -6
- package/dist/memory/base.d.ts +1 -0
- package/dist/memory/buffer_memory.cjs +3 -0
- package/dist/memory/buffer_memory.d.ts +1 -0
- package/dist/memory/buffer_memory.js +3 -0
- package/dist/memory/buffer_window_memory.cjs +3 -0
- package/dist/memory/buffer_window_memory.d.ts +1 -0
- package/dist/memory/buffer_window_memory.js +3 -0
- package/dist/memory/motorhead_memory.cjs +3 -0
- package/dist/memory/motorhead_memory.d.ts +1 -0
- package/dist/memory/motorhead_memory.js +3 -0
- package/dist/memory/summary.cjs +3 -0
- package/dist/memory/summary.d.ts +1 -0
- package/dist/memory/summary.js +3 -0
- package/dist/retrievers/supabase.cjs +2 -2
- package/dist/retrievers/supabase.js +2 -2
- package/dist/tools/webbrowser.cjs +1 -1
- package/dist/tools/webbrowser.js +1 -1
- package/dist/util/async_caller.cjs +9 -0
- package/dist/util/async_caller.js +9 -0
- package/dist/util/axios-fetch-adapter.cjs +6 -0
- package/dist/util/axios-fetch-adapter.js +6 -0
- package/dist/util/axios-types.d.ts +3 -1
- package/dist/util/set.cjs +41 -0
- package/dist/util/set.d.ts +15 -0
- package/dist/util/set.js +35 -0
- package/dist/vectorstores/supabase.cjs +1 -1
- package/dist/vectorstores/supabase.js +1 -1
- package/experimental/babyagi.cjs +1 -0
- package/experimental/babyagi.d.ts +1 -0
- package/experimental/babyagi.js +1 -0
- package/package.json +11 -3
- package/dist/chains/simple_sequential_chain.cjs +0 -124
- package/dist/chains/simple_sequential_chain.js +0 -120
|
@@ -7,7 +7,7 @@ const index_js_2 = require("./chat_convo/index.cjs");
|
|
|
7
7
|
const executor_js_1 = require("./executor.cjs");
|
|
8
8
|
const index_js_3 = require("./mrkl/index.cjs");
|
|
9
9
|
/**
|
|
10
|
-
* @deprecated use
|
|
10
|
+
* @deprecated use initializeAgentExecutorWithOptions instead
|
|
11
11
|
*/
|
|
12
12
|
const initializeAgentExecutor = async (tools, llm, _agentType, _verbose, _callbackManager) => {
|
|
13
13
|
const agentType = _agentType ?? "zero-shot-react-description";
|
|
@@ -7,7 +7,7 @@ import { AgentExecutor, AgentExecutorInput } from "./executor.js";
|
|
|
7
7
|
import { ZeroShotAgent } from "./mrkl/index.js";
|
|
8
8
|
type AgentType = "zero-shot-react-description" | "chat-zero-shot-react-description" | "chat-conversational-react-description";
|
|
9
9
|
/**
|
|
10
|
-
* @deprecated use
|
|
10
|
+
* @deprecated use initializeAgentExecutorWithOptions instead
|
|
11
11
|
*/
|
|
12
12
|
export declare const initializeAgentExecutor: (tools: Tool[], llm: BaseLanguageModel, _agentType?: AgentType, _verbose?: boolean, _callbackManager?: CallbackManager) => Promise<AgentExecutor>;
|
|
13
13
|
/**
|
|
@@ -4,7 +4,7 @@ import { ChatConversationalAgent } from "./chat_convo/index.js";
|
|
|
4
4
|
import { AgentExecutor } from "./executor.js";
|
|
5
5
|
import { ZeroShotAgent } from "./mrkl/index.js";
|
|
6
6
|
/**
|
|
7
|
-
* @deprecated use
|
|
7
|
+
* @deprecated use initializeAgentExecutorWithOptions instead
|
|
8
8
|
*/
|
|
9
9
|
export const initializeAgentExecutor = async (tools, llm, _agentType, _verbose, _callbackManager) => {
|
|
10
10
|
const agentType = _agentType ?? "zero-shot-react-description";
|
|
@@ -31,17 +31,20 @@ export interface BaseLanguageModelParams extends AsyncCallerParams, BaseLangChai
|
|
|
31
31
|
*/
|
|
32
32
|
callbackManager?: CallbackManager;
|
|
33
33
|
}
|
|
34
|
+
export interface BaseLanguageModelCallOptions {
|
|
35
|
+
}
|
|
34
36
|
/**
|
|
35
37
|
* Base class for language models.
|
|
36
38
|
*/
|
|
37
39
|
export declare abstract class BaseLanguageModel extends BaseLangChain implements BaseLanguageModelParams {
|
|
40
|
+
CallOptions: BaseLanguageModelCallOptions;
|
|
38
41
|
/**
|
|
39
42
|
* The async caller should be used by subclasses to make any async calls,
|
|
40
43
|
* which will thus benefit from the concurrency and retry logic.
|
|
41
44
|
*/
|
|
42
45
|
caller: AsyncCaller;
|
|
43
46
|
constructor(params: BaseLanguageModelParams);
|
|
44
|
-
abstract generatePrompt(promptValues: BasePromptValue[], stop?: string[], callbacks?: Callbacks): Promise<LLMResult>;
|
|
47
|
+
abstract generatePrompt(promptValues: BasePromptValue[], stop?: string[] | this["CallOptions"], callbacks?: Callbacks): Promise<LLMResult>;
|
|
45
48
|
abstract _modelType(): string;
|
|
46
49
|
abstract _llmType(): string;
|
|
47
50
|
private _encoding?;
|
|
@@ -41,7 +41,7 @@ class AnalyzeDocumentChain extends base_js_1.BaseChain {
|
|
|
41
41
|
return this.combineDocumentsChain.outputKeys;
|
|
42
42
|
}
|
|
43
43
|
/** @ignore */
|
|
44
|
-
async _call(values) {
|
|
44
|
+
async _call(values, runManager) {
|
|
45
45
|
if (!(this.inputKey in values)) {
|
|
46
46
|
throw new Error(`Document key ${this.inputKey} not found.`);
|
|
47
47
|
}
|
|
@@ -49,7 +49,7 @@ class AnalyzeDocumentChain extends base_js_1.BaseChain {
|
|
|
49
49
|
const currentDoc = doc;
|
|
50
50
|
const currentDocs = await this.textSplitter.createDocuments([currentDoc]);
|
|
51
51
|
const newInputs = { input_documents: currentDocs, ...rest };
|
|
52
|
-
const result = await this.combineDocumentsChain.call(newInputs);
|
|
52
|
+
const result = await this.combineDocumentsChain.call(newInputs, runManager?.getChild());
|
|
53
53
|
return result;
|
|
54
54
|
}
|
|
55
55
|
_chainType() {
|
|
@@ -2,6 +2,7 @@ import { BaseChain, ChainInputs } from "./base.js";
|
|
|
2
2
|
import { TextSplitter } from "../text_splitter.js";
|
|
3
3
|
import { ChainValues } from "../schema/index.js";
|
|
4
4
|
import { SerializedAnalyzeDocumentChain } from "./serde.js";
|
|
5
|
+
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
5
6
|
export type LoadValues = Record<string, any>;
|
|
6
7
|
export interface AnalyzeDocumentChainInput extends Omit<ChainInputs, "memory"> {
|
|
7
8
|
combineDocumentsChain: BaseChain;
|
|
@@ -21,7 +22,7 @@ export declare class AnalyzeDocumentChain extends BaseChain implements AnalyzeDo
|
|
|
21
22
|
get inputKeys(): string[];
|
|
22
23
|
get outputKeys(): string[];
|
|
23
24
|
/** @ignore */
|
|
24
|
-
_call(values: ChainValues): Promise<ChainValues>;
|
|
25
|
+
_call(values: ChainValues, runManager?: CallbackManagerForChainRun): Promise<ChainValues>;
|
|
25
26
|
_chainType(): "analyze_document_chain";
|
|
26
27
|
static deserialize(data: SerializedAnalyzeDocumentChain, values: LoadValues): Promise<AnalyzeDocumentChain>;
|
|
27
28
|
serialize(): SerializedAnalyzeDocumentChain;
|
|
@@ -38,7 +38,7 @@ export class AnalyzeDocumentChain extends BaseChain {
|
|
|
38
38
|
return this.combineDocumentsChain.outputKeys;
|
|
39
39
|
}
|
|
40
40
|
/** @ignore */
|
|
41
|
-
async _call(values) {
|
|
41
|
+
async _call(values, runManager) {
|
|
42
42
|
if (!(this.inputKey in values)) {
|
|
43
43
|
throw new Error(`Document key ${this.inputKey} not found.`);
|
|
44
44
|
}
|
|
@@ -46,7 +46,7 @@ export class AnalyzeDocumentChain extends BaseChain {
|
|
|
46
46
|
const currentDoc = doc;
|
|
47
47
|
const currentDocs = await this.textSplitter.createDocuments([currentDoc]);
|
|
48
48
|
const newInputs = { input_documents: currentDocs, ...rest };
|
|
49
|
-
const result = await this.combineDocumentsChain.call(newInputs);
|
|
49
|
+
const result = await this.combineDocumentsChain.call(newInputs, runManager?.getChild());
|
|
50
50
|
return result;
|
|
51
51
|
}
|
|
52
52
|
_chainType() {
|
package/dist/chains/base.cjs
CHANGED
|
@@ -82,8 +82,12 @@ class BaseChain extends index_js_2.BaseLangChain {
|
|
|
82
82
|
const { LLMChain } = await import("./llm_chain.js");
|
|
83
83
|
return LLMChain.deserialize(data);
|
|
84
84
|
}
|
|
85
|
+
case "sequential_chain": {
|
|
86
|
+
const { SequentialChain } = await import("./sequential_chain.js");
|
|
87
|
+
return SequentialChain.deserialize(data);
|
|
88
|
+
}
|
|
85
89
|
case "simple_sequential_chain": {
|
|
86
|
-
const { SimpleSequentialChain } = await import("./
|
|
90
|
+
const { SimpleSequentialChain } = await import("./sequential_chain.js");
|
|
87
91
|
return SimpleSequentialChain.deserialize(data);
|
|
88
92
|
}
|
|
89
93
|
case "stuff_documents_chain": {
|
package/dist/chains/base.js
CHANGED
|
@@ -79,8 +79,12 @@ export class BaseChain extends BaseLangChain {
|
|
|
79
79
|
const { LLMChain } = await import("./llm_chain.js");
|
|
80
80
|
return LLMChain.deserialize(data);
|
|
81
81
|
}
|
|
82
|
+
case "sequential_chain": {
|
|
83
|
+
const { SequentialChain } = await import("./sequential_chain.js");
|
|
84
|
+
return SequentialChain.deserialize(data);
|
|
85
|
+
}
|
|
82
86
|
case "simple_sequential_chain": {
|
|
83
|
-
const { SimpleSequentialChain } = await import("./
|
|
87
|
+
const { SimpleSequentialChain } = await import("./sequential_chain.js");
|
|
84
88
|
return SimpleSequentialChain.deserialize(data);
|
|
85
89
|
}
|
|
86
90
|
case "stuff_documents_chain": {
|
|
@@ -84,7 +84,7 @@ class ChatVectorDBQAChain extends base_js_1.BaseChain {
|
|
|
84
84
|
fields.returnSourceDocuments ?? this.returnSourceDocuments;
|
|
85
85
|
}
|
|
86
86
|
/** @ignore */
|
|
87
|
-
async _call(values) {
|
|
87
|
+
async _call(values, runManager) {
|
|
88
88
|
if (!(this.inputKey in values)) {
|
|
89
89
|
throw new Error(`Question key ${this.inputKey} not found.`);
|
|
90
90
|
}
|
|
@@ -98,7 +98,7 @@ class ChatVectorDBQAChain extends base_js_1.BaseChain {
|
|
|
98
98
|
const result = await this.questionGeneratorChain.call({
|
|
99
99
|
question,
|
|
100
100
|
chat_history: chatHistory,
|
|
101
|
-
});
|
|
101
|
+
}, runManager?.getChild());
|
|
102
102
|
const keys = Object.keys(result);
|
|
103
103
|
console.log("_call", values, keys);
|
|
104
104
|
if (keys.length === 1) {
|
|
@@ -114,7 +114,7 @@ class ChatVectorDBQAChain extends base_js_1.BaseChain {
|
|
|
114
114
|
input_documents: docs,
|
|
115
115
|
chat_history: chatHistory,
|
|
116
116
|
};
|
|
117
|
-
const result = await this.combineDocumentsChain.call(inputs);
|
|
117
|
+
const result = await this.combineDocumentsChain.call(inputs, runManager?.getChild());
|
|
118
118
|
if (this.returnSourceDocuments) {
|
|
119
119
|
return {
|
|
120
120
|
...result,
|
|
@@ -4,6 +4,7 @@ import { SerializedChatVectorDBQAChain } from "./serde.js";
|
|
|
4
4
|
import { ChainValues } from "../schema/index.js";
|
|
5
5
|
import { BaseChain } from "./base.js";
|
|
6
6
|
import { LLMChain } from "./llm_chain.js";
|
|
7
|
+
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
7
8
|
export type LoadValues = Record<string, any>;
|
|
8
9
|
export interface ChatVectorDBQAChainInput {
|
|
9
10
|
vectorstore: VectorStore;
|
|
@@ -34,7 +35,7 @@ export declare class ChatVectorDBQAChain extends BaseChain implements ChatVector
|
|
|
34
35
|
returnSourceDocuments?: boolean;
|
|
35
36
|
});
|
|
36
37
|
/** @ignore */
|
|
37
|
-
_call(values: ChainValues): Promise<ChainValues>;
|
|
38
|
+
_call(values: ChainValues, runManager?: CallbackManagerForChainRun): Promise<ChainValues>;
|
|
38
39
|
_chainType(): "chat-vector-db";
|
|
39
40
|
static deserialize(data: SerializedChatVectorDBQAChain, values: LoadValues): Promise<ChatVectorDBQAChain>;
|
|
40
41
|
serialize(): SerializedChatVectorDBQAChain;
|
|
@@ -81,7 +81,7 @@ export class ChatVectorDBQAChain extends BaseChain {
|
|
|
81
81
|
fields.returnSourceDocuments ?? this.returnSourceDocuments;
|
|
82
82
|
}
|
|
83
83
|
/** @ignore */
|
|
84
|
-
async _call(values) {
|
|
84
|
+
async _call(values, runManager) {
|
|
85
85
|
if (!(this.inputKey in values)) {
|
|
86
86
|
throw new Error(`Question key ${this.inputKey} not found.`);
|
|
87
87
|
}
|
|
@@ -95,7 +95,7 @@ export class ChatVectorDBQAChain extends BaseChain {
|
|
|
95
95
|
const result = await this.questionGeneratorChain.call({
|
|
96
96
|
question,
|
|
97
97
|
chat_history: chatHistory,
|
|
98
|
-
});
|
|
98
|
+
}, runManager?.getChild());
|
|
99
99
|
const keys = Object.keys(result);
|
|
100
100
|
console.log("_call", values, keys);
|
|
101
101
|
if (keys.length === 1) {
|
|
@@ -111,7 +111,7 @@ export class ChatVectorDBQAChain extends BaseChain {
|
|
|
111
111
|
input_documents: docs,
|
|
112
112
|
chat_history: chatHistory,
|
|
113
113
|
};
|
|
114
|
-
const result = await this.combineDocumentsChain.call(inputs);
|
|
114
|
+
const result = await this.combineDocumentsChain.call(inputs, runManager?.getChild());
|
|
115
115
|
if (this.returnSourceDocuments) {
|
|
116
116
|
return {
|
|
117
117
|
...result,
|
|
@@ -42,7 +42,7 @@ class StuffDocumentsChain extends base_js_1.BaseChain {
|
|
|
42
42
|
this.inputKey = fields.inputKey ?? this.inputKey;
|
|
43
43
|
}
|
|
44
44
|
/** @ignore */
|
|
45
|
-
async _call(values) {
|
|
45
|
+
async _call(values, runManager) {
|
|
46
46
|
if (!(this.inputKey in values)) {
|
|
47
47
|
throw new Error(`Document key ${this.inputKey} not found.`);
|
|
48
48
|
}
|
|
@@ -52,7 +52,7 @@ class StuffDocumentsChain extends base_js_1.BaseChain {
|
|
|
52
52
|
const result = await this.llmChain.call({
|
|
53
53
|
...rest,
|
|
54
54
|
[this.documentVariableName]: text,
|
|
55
|
-
});
|
|
55
|
+
}, runManager?.getChild());
|
|
56
56
|
return result;
|
|
57
57
|
}
|
|
58
58
|
_chainType() {
|
|
@@ -140,7 +140,7 @@ class MapReduceDocumentsChain extends base_js_1.BaseChain {
|
|
|
140
140
|
this.maxIterations = fields.maxIterations ?? this.maxIterations;
|
|
141
141
|
}
|
|
142
142
|
/** @ignore */
|
|
143
|
-
async _call(values) {
|
|
143
|
+
async _call(values, runManager) {
|
|
144
144
|
if (!(this.inputKey in values)) {
|
|
145
145
|
throw new Error(`Document key ${this.inputKey} not found.`);
|
|
146
146
|
}
|
|
@@ -161,14 +161,14 @@ class MapReduceDocumentsChain extends base_js_1.BaseChain {
|
|
|
161
161
|
if (canSkipMapStep && withinTokenLimit) {
|
|
162
162
|
break;
|
|
163
163
|
}
|
|
164
|
-
const results = await this.llmChain.apply(inputs);
|
|
164
|
+
const results = await this.llmChain.apply(inputs, runManager ? [runManager.getChild()] : undefined);
|
|
165
165
|
const { outputKey } = this.llmChain;
|
|
166
166
|
currentDocs = results.map((r) => ({
|
|
167
167
|
pageContent: r[outputKey],
|
|
168
168
|
}));
|
|
169
169
|
}
|
|
170
170
|
const newInputs = { input_documents: currentDocs, ...rest };
|
|
171
|
-
const result = await this.combineDocumentChain.call(newInputs);
|
|
171
|
+
const result = await this.combineDocumentChain.call(newInputs, runManager?.getChild());
|
|
172
172
|
return result;
|
|
173
173
|
}
|
|
174
174
|
_chainType() {
|
|
@@ -304,19 +304,19 @@ class RefineDocumentsChain extends base_js_1.BaseChain {
|
|
|
304
304
|
return inputs;
|
|
305
305
|
}
|
|
306
306
|
/** @ignore */
|
|
307
|
-
async _call(values) {
|
|
307
|
+
async _call(values, runManager) {
|
|
308
308
|
if (!(this.inputKey in values)) {
|
|
309
309
|
throw new Error(`Document key ${this.inputKey} not found.`);
|
|
310
310
|
}
|
|
311
311
|
const { [this.inputKey]: docs, ...rest } = values;
|
|
312
312
|
const currentDocs = docs;
|
|
313
313
|
const initialInputs = await this._constructInitialInputs(currentDocs[0], rest);
|
|
314
|
-
let res = await this.llmChain.predict({ ...initialInputs });
|
|
314
|
+
let res = await this.llmChain.predict({ ...initialInputs }, runManager?.getChild());
|
|
315
315
|
const refineSteps = [res];
|
|
316
316
|
for (let i = 1; i < currentDocs.length; i += 1) {
|
|
317
317
|
const refineInputs = await this._constructRefineInputs(currentDocs[i], res);
|
|
318
318
|
const inputs = { ...refineInputs, ...rest };
|
|
319
|
-
res = await this.refineLLMChain.predict({ ...inputs });
|
|
319
|
+
res = await this.refineLLMChain.predict({ ...inputs }, runManager?.getChild());
|
|
320
320
|
refineSteps.push(res);
|
|
321
321
|
}
|
|
322
322
|
return { [this.outputKey]: res };
|
|
@@ -4,6 +4,7 @@ import { LLMChain } from "./llm_chain.js";
|
|
|
4
4
|
import { Document } from "../document.js";
|
|
5
5
|
import { ChainValues } from "../schema/index.js";
|
|
6
6
|
import { BasePromptTemplate } from "../prompts/base.js";
|
|
7
|
+
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
7
8
|
export interface StuffDocumentsChainInput {
|
|
8
9
|
/** LLM Wrapper to use after formatting documents */
|
|
9
10
|
llmChain: LLMChain;
|
|
@@ -24,7 +25,7 @@ export declare class StuffDocumentsChain extends BaseChain implements StuffDocum
|
|
|
24
25
|
get outputKeys(): string[];
|
|
25
26
|
constructor(fields: StuffDocumentsChainInput);
|
|
26
27
|
/** @ignore */
|
|
27
|
-
_call(values: ChainValues): Promise<ChainValues>;
|
|
28
|
+
_call(values: ChainValues, runManager?: CallbackManagerForChainRun): Promise<ChainValues>;
|
|
28
29
|
_chainType(): "stuff_documents_chain";
|
|
29
30
|
static deserialize(data: SerializedStuffDocumentsChain): Promise<StuffDocumentsChain>;
|
|
30
31
|
serialize(): SerializedStuffDocumentsChain;
|
|
@@ -52,7 +53,7 @@ export declare class MapReduceDocumentsChain extends BaseChain implements MapRed
|
|
|
52
53
|
combineDocumentChain: BaseChain;
|
|
53
54
|
constructor(fields: MapReduceDocumentsChainInput);
|
|
54
55
|
/** @ignore */
|
|
55
|
-
_call(values: ChainValues): Promise<ChainValues>;
|
|
56
|
+
_call(values: ChainValues, runManager?: CallbackManagerForChainRun): Promise<ChainValues>;
|
|
56
57
|
_chainType(): "map_reduce_documents_chain";
|
|
57
58
|
static deserialize(data: SerializedMapReduceDocumentsChain): Promise<MapReduceDocumentsChain>;
|
|
58
59
|
serialize(): SerializedMapReduceDocumentsChain;
|
|
@@ -90,7 +91,7 @@ export declare class RefineDocumentsChain extends BaseChain implements RefineDoc
|
|
|
90
91
|
[x: string]: unknown;
|
|
91
92
|
}>;
|
|
92
93
|
/** @ignore */
|
|
93
|
-
_call(values: ChainValues): Promise<ChainValues>;
|
|
94
|
+
_call(values: ChainValues, runManager?: CallbackManagerForChainRun): Promise<ChainValues>;
|
|
94
95
|
_chainType(): "refine_documents_chain";
|
|
95
96
|
static deserialize(data: SerializedRefineDocumentsChain): Promise<RefineDocumentsChain>;
|
|
96
97
|
serialize(): SerializedRefineDocumentsChain;
|
|
@@ -39,7 +39,7 @@ export class StuffDocumentsChain extends BaseChain {
|
|
|
39
39
|
this.inputKey = fields.inputKey ?? this.inputKey;
|
|
40
40
|
}
|
|
41
41
|
/** @ignore */
|
|
42
|
-
async _call(values) {
|
|
42
|
+
async _call(values, runManager) {
|
|
43
43
|
if (!(this.inputKey in values)) {
|
|
44
44
|
throw new Error(`Document key ${this.inputKey} not found.`);
|
|
45
45
|
}
|
|
@@ -49,7 +49,7 @@ export class StuffDocumentsChain extends BaseChain {
|
|
|
49
49
|
const result = await this.llmChain.call({
|
|
50
50
|
...rest,
|
|
51
51
|
[this.documentVariableName]: text,
|
|
52
|
-
});
|
|
52
|
+
}, runManager?.getChild());
|
|
53
53
|
return result;
|
|
54
54
|
}
|
|
55
55
|
_chainType() {
|
|
@@ -136,7 +136,7 @@ export class MapReduceDocumentsChain extends BaseChain {
|
|
|
136
136
|
this.maxIterations = fields.maxIterations ?? this.maxIterations;
|
|
137
137
|
}
|
|
138
138
|
/** @ignore */
|
|
139
|
-
async _call(values) {
|
|
139
|
+
async _call(values, runManager) {
|
|
140
140
|
if (!(this.inputKey in values)) {
|
|
141
141
|
throw new Error(`Document key ${this.inputKey} not found.`);
|
|
142
142
|
}
|
|
@@ -157,14 +157,14 @@ export class MapReduceDocumentsChain extends BaseChain {
|
|
|
157
157
|
if (canSkipMapStep && withinTokenLimit) {
|
|
158
158
|
break;
|
|
159
159
|
}
|
|
160
|
-
const results = await this.llmChain.apply(inputs);
|
|
160
|
+
const results = await this.llmChain.apply(inputs, runManager ? [runManager.getChild()] : undefined);
|
|
161
161
|
const { outputKey } = this.llmChain;
|
|
162
162
|
currentDocs = results.map((r) => ({
|
|
163
163
|
pageContent: r[outputKey],
|
|
164
164
|
}));
|
|
165
165
|
}
|
|
166
166
|
const newInputs = { input_documents: currentDocs, ...rest };
|
|
167
|
-
const result = await this.combineDocumentChain.call(newInputs);
|
|
167
|
+
const result = await this.combineDocumentChain.call(newInputs, runManager?.getChild());
|
|
168
168
|
return result;
|
|
169
169
|
}
|
|
170
170
|
_chainType() {
|
|
@@ -299,19 +299,19 @@ export class RefineDocumentsChain extends BaseChain {
|
|
|
299
299
|
return inputs;
|
|
300
300
|
}
|
|
301
301
|
/** @ignore */
|
|
302
|
-
async _call(values) {
|
|
302
|
+
async _call(values, runManager) {
|
|
303
303
|
if (!(this.inputKey in values)) {
|
|
304
304
|
throw new Error(`Document key ${this.inputKey} not found.`);
|
|
305
305
|
}
|
|
306
306
|
const { [this.inputKey]: docs, ...rest } = values;
|
|
307
307
|
const currentDocs = docs;
|
|
308
308
|
const initialInputs = await this._constructInitialInputs(currentDocs[0], rest);
|
|
309
|
-
let res = await this.llmChain.predict({ ...initialInputs });
|
|
309
|
+
let res = await this.llmChain.predict({ ...initialInputs }, runManager?.getChild());
|
|
310
310
|
const refineSteps = [res];
|
|
311
311
|
for (let i = 1; i < currentDocs.length; i += 1) {
|
|
312
312
|
const refineInputs = await this._constructRefineInputs(currentDocs[i], res);
|
|
313
313
|
const inputs = { ...refineInputs, ...rest };
|
|
314
|
-
res = await this.refineLLMChain.predict({ ...inputs });
|
|
314
|
+
res = await this.refineLLMChain.predict({ ...inputs }, runManager?.getChild());
|
|
315
315
|
refineSteps.push(res);
|
|
316
316
|
}
|
|
317
317
|
return { [this.outputKey]: res };
|
|
@@ -70,7 +70,7 @@ class ConversationalRetrievalQAChain extends base_js_1.BaseChain {
|
|
|
70
70
|
fields.returnSourceDocuments ?? this.returnSourceDocuments;
|
|
71
71
|
}
|
|
72
72
|
/** @ignore */
|
|
73
|
-
async _call(values) {
|
|
73
|
+
async _call(values, runManager) {
|
|
74
74
|
if (!(this.inputKey in values)) {
|
|
75
75
|
throw new Error(`Question key ${this.inputKey} not found.`);
|
|
76
76
|
}
|
|
@@ -84,7 +84,7 @@ class ConversationalRetrievalQAChain extends base_js_1.BaseChain {
|
|
|
84
84
|
const result = await this.questionGeneratorChain.call({
|
|
85
85
|
question,
|
|
86
86
|
chat_history: chatHistory,
|
|
87
|
-
});
|
|
87
|
+
}, runManager?.getChild());
|
|
88
88
|
const keys = Object.keys(result);
|
|
89
89
|
if (keys.length === 1) {
|
|
90
90
|
newQuestion = result[keys[0]];
|
|
@@ -99,7 +99,7 @@ class ConversationalRetrievalQAChain extends base_js_1.BaseChain {
|
|
|
99
99
|
input_documents: docs,
|
|
100
100
|
chat_history: chatHistory,
|
|
101
101
|
};
|
|
102
|
-
const result = await this.combineDocumentsChain.call(inputs);
|
|
102
|
+
const result = await this.combineDocumentsChain.call(inputs, runManager?.getChild());
|
|
103
103
|
if (this.returnSourceDocuments) {
|
|
104
104
|
return {
|
|
105
105
|
...result,
|
|
@@ -3,6 +3,7 @@ import { SerializedChatVectorDBQAChain } from "./serde.js";
|
|
|
3
3
|
import { ChainValues, BaseRetriever } from "../schema/index.js";
|
|
4
4
|
import { BaseChain, ChainInputs } from "./base.js";
|
|
5
5
|
import { LLMChain } from "./llm_chain.js";
|
|
6
|
+
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
6
7
|
export type LoadValues = Record<string, any>;
|
|
7
8
|
export interface ConversationalRetrievalQAChainInput extends Omit<ChainInputs, "memory"> {
|
|
8
9
|
retriever: BaseRetriever;
|
|
@@ -22,7 +23,7 @@ export declare class ConversationalRetrievalQAChain extends BaseChain implements
|
|
|
22
23
|
returnSourceDocuments: boolean;
|
|
23
24
|
constructor(fields: ConversationalRetrievalQAChainInput);
|
|
24
25
|
/** @ignore */
|
|
25
|
-
_call(values: ChainValues): Promise<ChainValues>;
|
|
26
|
+
_call(values: ChainValues, runManager?: CallbackManagerForChainRun): Promise<ChainValues>;
|
|
26
27
|
_chainType(): string;
|
|
27
28
|
static deserialize(_data: SerializedChatVectorDBQAChain, _values: LoadValues): Promise<ConversationalRetrievalQAChain>;
|
|
28
29
|
serialize(): SerializedChatVectorDBQAChain;
|
|
@@ -67,7 +67,7 @@ export class ConversationalRetrievalQAChain extends BaseChain {
|
|
|
67
67
|
fields.returnSourceDocuments ?? this.returnSourceDocuments;
|
|
68
68
|
}
|
|
69
69
|
/** @ignore */
|
|
70
|
-
async _call(values) {
|
|
70
|
+
async _call(values, runManager) {
|
|
71
71
|
if (!(this.inputKey in values)) {
|
|
72
72
|
throw new Error(`Question key ${this.inputKey} not found.`);
|
|
73
73
|
}
|
|
@@ -81,7 +81,7 @@ export class ConversationalRetrievalQAChain extends BaseChain {
|
|
|
81
81
|
const result = await this.questionGeneratorChain.call({
|
|
82
82
|
question,
|
|
83
83
|
chat_history: chatHistory,
|
|
84
|
-
});
|
|
84
|
+
}, runManager?.getChild());
|
|
85
85
|
const keys = Object.keys(result);
|
|
86
86
|
if (keys.length === 1) {
|
|
87
87
|
newQuestion = result[keys[0]];
|
|
@@ -96,7 +96,7 @@ export class ConversationalRetrievalQAChain extends BaseChain {
|
|
|
96
96
|
input_documents: docs,
|
|
97
97
|
chat_history: chatHistory,
|
|
98
98
|
};
|
|
99
|
-
const result = await this.combineDocumentsChain.call(inputs);
|
|
99
|
+
const result = await this.combineDocumentsChain.call(inputs, runManager?.getChild());
|
|
100
100
|
if (this.returnSourceDocuments) {
|
|
101
101
|
return {
|
|
102
102
|
...result,
|
package/dist/chains/index.cjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RetrievalQAChain = exports.ConversationalRetrievalQAChain = exports.SqlDatabaseChain = exports.loadSummarizationChain = exports.loadQARefineChain = exports.loadQAMapReduceChain = exports.loadQAStuffChain = exports.loadQAChain = exports.VectorDBQAChain = exports.AnalyzeDocumentChain = exports.ChatVectorDBQAChain = exports.RefineDocumentsChain = exports.MapReduceDocumentsChain = exports.StuffDocumentsChain = exports.SimpleSequentialChain = exports.ConversationChain = exports.LLMChain = exports.BaseChain = void 0;
|
|
3
|
+
exports.RetrievalQAChain = exports.ConversationalRetrievalQAChain = exports.SqlDatabaseChain = exports.loadSummarizationChain = exports.loadQARefineChain = exports.loadQAMapReduceChain = exports.loadQAStuffChain = exports.loadQAChain = exports.VectorDBQAChain = exports.AnalyzeDocumentChain = exports.ChatVectorDBQAChain = exports.RefineDocumentsChain = exports.MapReduceDocumentsChain = exports.StuffDocumentsChain = exports.SimpleSequentialChain = exports.SequentialChain = exports.ConversationChain = exports.LLMChain = exports.BaseChain = void 0;
|
|
4
4
|
var base_js_1 = require("./base.cjs");
|
|
5
5
|
Object.defineProperty(exports, "BaseChain", { enumerable: true, get: function () { return base_js_1.BaseChain; } });
|
|
6
6
|
var llm_chain_js_1 = require("./llm_chain.cjs");
|
|
7
7
|
Object.defineProperty(exports, "LLMChain", { enumerable: true, get: function () { return llm_chain_js_1.LLMChain; } });
|
|
8
8
|
var conversation_js_1 = require("./conversation.cjs");
|
|
9
9
|
Object.defineProperty(exports, "ConversationChain", { enumerable: true, get: function () { return conversation_js_1.ConversationChain; } });
|
|
10
|
-
var
|
|
11
|
-
Object.defineProperty(exports, "
|
|
10
|
+
var sequential_chain_js_1 = require("./sequential_chain.cjs");
|
|
11
|
+
Object.defineProperty(exports, "SequentialChain", { enumerable: true, get: function () { return sequential_chain_js_1.SequentialChain; } });
|
|
12
|
+
Object.defineProperty(exports, "SimpleSequentialChain", { enumerable: true, get: function () { return sequential_chain_js_1.SimpleSequentialChain; } });
|
|
12
13
|
var combine_docs_chain_js_1 = require("./combine_docs_chain.cjs");
|
|
13
14
|
Object.defineProperty(exports, "StuffDocumentsChain", { enumerable: true, get: function () { return combine_docs_chain_js_1.StuffDocumentsChain; } });
|
|
14
15
|
Object.defineProperty(exports, "MapReduceDocumentsChain", { enumerable: true, get: function () { return combine_docs_chain_js_1.MapReduceDocumentsChain; } });
|
package/dist/chains/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { BaseChain, ChainInputs } from "./base.js";
|
|
2
2
|
export { LLMChain, LLMChainInput } from "./llm_chain.js";
|
|
3
3
|
export { ConversationChain } from "./conversation.js";
|
|
4
|
-
export { SimpleSequentialChain, SimpleSequentialChainInput, } from "./
|
|
4
|
+
export { SequentialChain, SequentialChainInput, SimpleSequentialChain, SimpleSequentialChainInput, } from "./sequential_chain.js";
|
|
5
5
|
export { StuffDocumentsChain, StuffDocumentsChainInput, MapReduceDocumentsChain, MapReduceDocumentsChainInput, RefineDocumentsChain, RefineDocumentsChainInput, } from "./combine_docs_chain.js";
|
|
6
6
|
export { ChatVectorDBQAChain, ChatVectorDBQAChainInput, } from "./chat_vector_db_chain.js";
|
|
7
7
|
export { AnalyzeDocumentChain, AnalyzeDocumentChainInput, } from "./analyze_documents_chain.js";
|
|
@@ -11,4 +11,4 @@ export { loadSummarizationChain } from "./summarization/load.js";
|
|
|
11
11
|
export { SqlDatabaseChain, SqlDatabaseChainInput, } from "./sql_db/sql_db_chain.js";
|
|
12
12
|
export { ConversationalRetrievalQAChain, ConversationalRetrievalQAChainInput, } from "./conversational_retrieval_chain.js";
|
|
13
13
|
export { RetrievalQAChain, RetrievalQAChainInput } from "./retrieval_qa.js";
|
|
14
|
-
export { SerializedLLMChain, SerializedSimpleSequentialChain, SerializedSqlDatabaseChain, SerializedAnalyzeDocumentChain, SerializedBaseChain, SerializedChatVectorDBQAChain, SerializedMapReduceDocumentsChain, SerializedStuffDocumentsChain, SerializedVectorDBQAChain, SerializedRefineDocumentsChain, } from "./serde.js";
|
|
14
|
+
export { SerializedLLMChain, SerializedSequentialChain, SerializedSimpleSequentialChain, SerializedSqlDatabaseChain, SerializedAnalyzeDocumentChain, SerializedBaseChain, SerializedChatVectorDBQAChain, SerializedMapReduceDocumentsChain, SerializedStuffDocumentsChain, SerializedVectorDBQAChain, SerializedRefineDocumentsChain, } from "./serde.js";
|
package/dist/chains/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { BaseChain } from "./base.js";
|
|
2
2
|
export { LLMChain } from "./llm_chain.js";
|
|
3
3
|
export { ConversationChain } from "./conversation.js";
|
|
4
|
-
export { SimpleSequentialChain, } from "./
|
|
4
|
+
export { SequentialChain, SimpleSequentialChain, } from "./sequential_chain.js";
|
|
5
5
|
export { StuffDocumentsChain, MapReduceDocumentsChain, RefineDocumentsChain, } from "./combine_docs_chain.js";
|
|
6
6
|
export { ChatVectorDBQAChain, } from "./chat_vector_db_chain.js";
|
|
7
7
|
export { AnalyzeDocumentChain, } from "./analyze_documents_chain.js";
|
|
@@ -43,14 +43,14 @@ class RetrievalQAChain extends base_js_1.BaseChain {
|
|
|
43
43
|
fields.returnSourceDocuments ?? this.returnSourceDocuments;
|
|
44
44
|
}
|
|
45
45
|
/** @ignore */
|
|
46
|
-
async _call(values) {
|
|
46
|
+
async _call(values, runManager) {
|
|
47
47
|
if (!(this.inputKey in values)) {
|
|
48
48
|
throw new Error(`Question key ${this.inputKey} not found.`);
|
|
49
49
|
}
|
|
50
50
|
const question = values[this.inputKey];
|
|
51
51
|
const docs = await this.retriever.getRelevantDocuments(question);
|
|
52
52
|
const inputs = { question, input_documents: docs };
|
|
53
|
-
const result = await this.combineDocumentsChain.call(inputs);
|
|
53
|
+
const result = await this.combineDocumentsChain.call(inputs, runManager?.getChild());
|
|
54
54
|
if (this.returnSourceDocuments) {
|
|
55
55
|
return {
|
|
56
56
|
...result,
|
|
@@ -2,6 +2,7 @@ import { BaseChain, ChainInputs } from "./base.js";
|
|
|
2
2
|
import { BaseLLM } from "../llms/base.js";
|
|
3
3
|
import { SerializedVectorDBQAChain } from "./serde.js";
|
|
4
4
|
import { ChainValues, BaseRetriever } from "../schema/index.js";
|
|
5
|
+
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
5
6
|
export type LoadValues = Record<string, any>;
|
|
6
7
|
export interface RetrievalQAChainInput extends Omit<ChainInputs, "memory"> {
|
|
7
8
|
retriever: BaseRetriever;
|
|
@@ -18,7 +19,7 @@ export declare class RetrievalQAChain extends BaseChain implements RetrievalQACh
|
|
|
18
19
|
returnSourceDocuments: boolean;
|
|
19
20
|
constructor(fields: RetrievalQAChainInput);
|
|
20
21
|
/** @ignore */
|
|
21
|
-
_call(values: ChainValues): Promise<ChainValues>;
|
|
22
|
+
_call(values: ChainValues, runManager?: CallbackManagerForChainRun): Promise<ChainValues>;
|
|
22
23
|
_chainType(): "retrieval_qa";
|
|
23
24
|
static deserialize(_data: SerializedVectorDBQAChain, _values: LoadValues): Promise<RetrievalQAChain>;
|
|
24
25
|
serialize(): SerializedVectorDBQAChain;
|
|
@@ -40,14 +40,14 @@ export class RetrievalQAChain extends BaseChain {
|
|
|
40
40
|
fields.returnSourceDocuments ?? this.returnSourceDocuments;
|
|
41
41
|
}
|
|
42
42
|
/** @ignore */
|
|
43
|
-
async _call(values) {
|
|
43
|
+
async _call(values, runManager) {
|
|
44
44
|
if (!(this.inputKey in values)) {
|
|
45
45
|
throw new Error(`Question key ${this.inputKey} not found.`);
|
|
46
46
|
}
|
|
47
47
|
const question = values[this.inputKey];
|
|
48
48
|
const docs = await this.retriever.getRelevantDocuments(question);
|
|
49
49
|
const inputs = { question, input_documents: docs };
|
|
50
|
-
const result = await this.combineDocumentsChain.call(inputs);
|
|
50
|
+
const result = await this.combineDocumentsChain.call(inputs, runManager?.getChild());
|
|
51
51
|
if (this.returnSourceDocuments) {
|
|
52
52
|
return {
|
|
53
53
|
...result,
|