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.
- package/dist/agents/agent.cjs +3 -4
- package/dist/agents/agent.js +3 -4
- package/dist/agents/chat_convo/prompt.cjs +1 -1
- package/dist/agents/chat_convo/prompt.d.ts +1 -1
- package/dist/agents/chat_convo/prompt.js +1 -1
- package/dist/agents/types.cjs +2 -2
- package/dist/agents/types.d.ts +2 -1
- package/dist/agents/types.js +1 -1
- package/dist/callbacks/manager.cjs +5 -1
- package/dist/callbacks/manager.js +5 -1
- package/dist/chains/analyze_documents_chain.cjs +1 -1
- package/dist/chains/analyze_documents_chain.js +1 -1
- package/dist/chains/base.cjs +25 -10
- package/dist/chains/base.d.ts +7 -3
- package/dist/chains/base.js +25 -10
- package/dist/chains/chat_vector_db_chain.cjs +1 -1
- package/dist/chains/chat_vector_db_chain.d.ts +7 -14
- package/dist/chains/chat_vector_db_chain.js +1 -1
- package/dist/chains/combine_docs_chain.cjs +3 -3
- package/dist/chains/combine_docs_chain.d.ts +2 -2
- package/dist/chains/combine_docs_chain.js +3 -3
- package/dist/chains/conversational_retrieval_chain.cjs +1 -1
- package/dist/chains/conversational_retrieval_chain.js +1 -1
- package/dist/chains/llm_chain.cjs +4 -4
- package/dist/chains/llm_chain.d.ts +3 -2
- package/dist/chains/llm_chain.js +4 -4
- package/dist/chains/retrieval_qa.cjs +1 -1
- package/dist/chains/retrieval_qa.js +1 -1
- package/dist/chains/sequential_chain.cjs +1 -1
- package/dist/chains/sequential_chain.js +1 -1
- package/dist/chains/sql_db/sql_db_chain.cjs +1 -1
- package/dist/chains/sql_db/sql_db_chain.js +1 -1
- package/dist/chains/vector_db_qa.cjs +1 -1
- package/dist/chains/vector_db_qa.js +1 -1
- package/dist/document_loaders/fs/unstructured.cjs +48 -1
- package/dist/document_loaders/fs/unstructured.d.ts +9 -1
- package/dist/document_loaders/fs/unstructured.js +46 -0
- package/dist/embeddings/tensorflow.cjs +67 -0
- package/dist/embeddings/tensorflow.d.ts +12 -0
- package/dist/embeddings/tensorflow.js +40 -0
- package/dist/experimental/autogpt/output_parser.cjs +2 -2
- package/dist/experimental/autogpt/output_parser.d.ts +1 -1
- package/dist/experimental/autogpt/output_parser.js +1 -1
- package/dist/memory/buffer_window_memory.cjs +2 -0
- package/dist/memory/buffer_window_memory.js +2 -0
- package/dist/output_parsers/combining.cjs +4 -4
- package/dist/output_parsers/combining.d.ts +3 -2
- package/dist/output_parsers/combining.js +3 -3
- package/dist/output_parsers/fix.cjs +6 -6
- package/dist/output_parsers/fix.d.ts +3 -2
- package/dist/output_parsers/fix.js +4 -4
- package/dist/output_parsers/list.cjs +3 -3
- package/dist/output_parsers/list.d.ts +1 -1
- package/dist/output_parsers/list.js +1 -1
- package/dist/output_parsers/regex.cjs +3 -3
- package/dist/output_parsers/regex.d.ts +1 -1
- package/dist/output_parsers/regex.js +1 -1
- package/dist/output_parsers/structured.cjs +10 -4
- package/dist/output_parsers/structured.d.ts +1 -1
- package/dist/output_parsers/structured.js +9 -3
- package/dist/prompts/base.d.ts +2 -1
- package/dist/prompts/chat.cjs +16 -2
- package/dist/prompts/chat.d.ts +2 -2
- package/dist/prompts/chat.js +16 -2
- package/dist/schema/index.cjs +1 -21
- package/dist/schema/index.d.ts +0 -30
- package/dist/schema/index.js +0 -18
- package/dist/schema/output_parser.cjs +23 -0
- package/dist/schema/output_parser.d.ts +32 -0
- package/dist/schema/output_parser.js +18 -0
- package/dist/tools/base.cjs +4 -4
- package/dist/tools/base.d.ts +4 -7
- package/dist/tools/base.js +4 -4
- package/dist/tools/fs.cjs +4 -4
- package/dist/tools/fs.d.ts +2 -2
- package/dist/tools/fs.js +4 -4
- package/dist/tools/serpapi.cjs +17 -10
- package/dist/tools/serpapi.d.ts +4 -1
- package/dist/tools/serpapi.js +17 -10
- package/dist/tools/webbrowser.cjs +4 -4
- package/dist/tools/webbrowser.d.ts +6 -6
- package/dist/tools/webbrowser.js +4 -4
- package/dist/util/flatten.cjs +21 -0
- package/dist/util/flatten.d.ts +1 -0
- package/dist/util/flatten.js +17 -0
- package/dist/vectorstores/pinecone.cjs +4 -0
- package/dist/vectorstores/pinecone.js +4 -0
- package/dist/vectorstores/weaviate.cjs +15 -9
- package/dist/vectorstores/weaviate.js +15 -9
- package/embeddings/tensorflow.cjs +1 -0
- package/embeddings/tensorflow.d.ts +1 -0
- package/embeddings/tensorflow.js +1 -0
- package/package.json +26 -3
package/dist/agents/agent.cjs
CHANGED
|
@@ -100,9 +100,8 @@ class LLMSingleActionAgent extends BaseSingleActionAgent {
|
|
|
100
100
|
intermediate_steps: steps,
|
|
101
101
|
stop: this.stop,
|
|
102
102
|
...inputs,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return this.outputParser.parse(output[this.llmChain.outputKey]);
|
|
103
|
+
}, callbackManager);
|
|
104
|
+
return this.outputParser.parse(output[this.llmChain.outputKey], callbackManager);
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
exports.LLMSingleActionAgent = LLMSingleActionAgent;
|
|
@@ -203,7 +202,7 @@ class Agent extends BaseSingleActionAgent {
|
|
|
203
202
|
newInputs.stop = this._stop();
|
|
204
203
|
}
|
|
205
204
|
const output = await this.llmChain.predict(newInputs, callbackManager);
|
|
206
|
-
return this.outputParser.parse(output);
|
|
205
|
+
return this.outputParser.parse(output, callbackManager);
|
|
207
206
|
}
|
|
208
207
|
/**
|
|
209
208
|
* Decide what to do given some input.
|
package/dist/agents/agent.js
CHANGED
|
@@ -94,9 +94,8 @@ export class LLMSingleActionAgent extends BaseSingleActionAgent {
|
|
|
94
94
|
intermediate_steps: steps,
|
|
95
95
|
stop: this.stop,
|
|
96
96
|
...inputs,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return this.outputParser.parse(output[this.llmChain.outputKey]);
|
|
97
|
+
}, callbackManager);
|
|
98
|
+
return this.outputParser.parse(output[this.llmChain.outputKey], callbackManager);
|
|
100
99
|
}
|
|
101
100
|
}
|
|
102
101
|
/**
|
|
@@ -196,7 +195,7 @@ export class Agent extends BaseSingleActionAgent {
|
|
|
196
195
|
newInputs.stop = this._stop();
|
|
197
196
|
}
|
|
198
197
|
const output = await this.llmChain.predict(newInputs, callbackManager);
|
|
199
|
-
return this.outputParser.parse(output);
|
|
198
|
+
return this.outputParser.parse(output, callbackManager);
|
|
200
199
|
}
|
|
201
200
|
/**
|
|
202
201
|
* Decide what to do given some input.
|
|
@@ -31,7 +31,7 @@ Use this if you want to respond directly to the human. Markdown code snippet for
|
|
|
31
31
|
\`\`\`json
|
|
32
32
|
{{{{
|
|
33
33
|
"action": "Final Answer",
|
|
34
|
-
"action_input": string \\ You should put what you want to return to use here
|
|
34
|
+
"action_input": string \\ You should put what you want to return to use here and make sure to use valid json newline characters.
|
|
35
35
|
}}}}
|
|
36
36
|
\`\`\``;
|
|
37
37
|
exports.DEFAULT_SUFFIX = `TOOLS
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const DEFAULT_PREFIX = "Assistant is a large language model trained by OpenAI.\n\nAssistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-like text based on the input it receives, allowing it to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.\n\nAssistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.\n\nOverall, Assistant is a powerful system that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist.";
|
|
2
2
|
export declare const PREFIX_END = " However, above all else, all responses must adhere to the format of RESPONSE FORMAT INSTRUCTIONS.";
|
|
3
|
-
export declare const FORMAT_INSTRUCTIONS = "RESPONSE FORMAT INSTRUCTIONS\n----------------------------\n\nWhen responding to me please, please output a response in one of two formats:\n\n**Option 1:**\nUse this if you want the human to use a tool.\nMarkdown code snippet formatted in the following schema:\n\n```json\n{{{{\n \"action\": string \\ The action to take. Must be one of {tool_names}\n \"action_input\": string \\ The input to the action\n}}}}\n```\n\n**Option #2:**\nUse this if you want to respond directly to the human. Markdown code snippet formatted in the following schema:\n\n```json\n{{{{\n \"action\": \"Final Answer\",\n \"action_input\": string \\ You should put what you want to return to use here
|
|
3
|
+
export declare const FORMAT_INSTRUCTIONS = "RESPONSE FORMAT INSTRUCTIONS\n----------------------------\n\nWhen responding to me please, please output a response in one of two formats:\n\n**Option 1:**\nUse this if you want the human to use a tool.\nMarkdown code snippet formatted in the following schema:\n\n```json\n{{{{\n \"action\": string \\ The action to take. Must be one of {tool_names}\n \"action_input\": string \\ The input to the action\n}}}}\n```\n\n**Option #2:**\nUse this if you want to respond directly to the human. Markdown code snippet formatted in the following schema:\n\n```json\n{{{{\n \"action\": \"Final Answer\",\n \"action_input\": string \\ You should put what you want to return to use here and make sure to use valid json newline characters.\n}}}}\n```";
|
|
4
4
|
export declare const DEFAULT_SUFFIX = "TOOLS\n------\nAssistant can ask the user to use tools to look up information that may be helpful in answering the users original question. The tools the human can use are:\n\n{{tools}}\n\n{format_instructions}\n\nUSER'S INPUT\n--------------------\nHere is the user's input (remember to respond with a markdown code snippet of a json blob with a single action, and NOTHING else):\n\n{{{{input}}}}";
|
|
5
5
|
export declare const TEMPLATE_TOOL_RESPONSE = "TOOL RESPONSE:\n---------------------\n{observation}\n\nUSER'S INPUT\n--------------------\n\nOkay, so what is the response to my original question? If using information from tools, you must say it explicitly - I have forgotten all TOOL RESPONSES! Remember to respond with a markdown code snippet of a json blob with a single action, and NOTHING else.";
|
|
@@ -28,7 +28,7 @@ Use this if you want to respond directly to the human. Markdown code snippet for
|
|
|
28
28
|
\`\`\`json
|
|
29
29
|
{{{{
|
|
30
30
|
"action": "Final Answer",
|
|
31
|
-
"action_input": string \\ You should put what you want to return to use here
|
|
31
|
+
"action_input": string \\ You should put what you want to return to use here and make sure to use valid json newline characters.
|
|
32
32
|
}}}}
|
|
33
33
|
\`\`\``;
|
|
34
34
|
export const DEFAULT_SUFFIX = `TOOLS
|
package/dist/agents/types.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AgentActionOutputParser = void 0;
|
|
4
|
-
const
|
|
5
|
-
class AgentActionOutputParser extends
|
|
4
|
+
const output_parser_js_1 = require("../schema/output_parser.cjs");
|
|
5
|
+
class AgentActionOutputParser extends output_parser_js_1.BaseOutputParser {
|
|
6
6
|
}
|
|
7
7
|
exports.AgentActionOutputParser = AgentActionOutputParser;
|
package/dist/agents/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LLMChain } from "../chains/llm_chain.js";
|
|
2
2
|
import { SerializedLLMChain } from "../chains/serde.js";
|
|
3
|
-
import { AgentAction, AgentFinish
|
|
3
|
+
import { AgentAction, AgentFinish } from "../schema/index.js";
|
|
4
|
+
import { BaseOutputParser } from "../schema/output_parser.js";
|
|
4
5
|
export interface AgentInput {
|
|
5
6
|
llmChain: LLMChain;
|
|
6
7
|
outputParser: AgentActionOutputParser;
|
package/dist/agents/types.js
CHANGED
|
@@ -319,7 +319,11 @@ class CallbackManager extends BaseCallbackManager {
|
|
|
319
319
|
}
|
|
320
320
|
if (tracingEnabled &&
|
|
321
321
|
!callbackManager.handlers.some((handler) => handler.name === "langchain_tracer")) {
|
|
322
|
-
|
|
322
|
+
const session = typeof process !== "undefined"
|
|
323
|
+
? // eslint-disable-next-line no-process-env
|
|
324
|
+
process.env?.LANGCHAIN_SESSION
|
|
325
|
+
: undefined;
|
|
326
|
+
callbackManager.addHandler(await (0, initialize_js_1.getTracingCallbackHandler)(session), true);
|
|
323
327
|
}
|
|
324
328
|
}
|
|
325
329
|
return callbackManager;
|
|
@@ -312,7 +312,11 @@ export class CallbackManager extends BaseCallbackManager {
|
|
|
312
312
|
}
|
|
313
313
|
if (tracingEnabled &&
|
|
314
314
|
!callbackManager.handlers.some((handler) => handler.name === "langchain_tracer")) {
|
|
315
|
-
|
|
315
|
+
const session = typeof process !== "undefined"
|
|
316
|
+
? // eslint-disable-next-line no-process-env
|
|
317
|
+
process.env?.LANGCHAIN_SESSION
|
|
318
|
+
: undefined;
|
|
319
|
+
callbackManager.addHandler(await getTracingCallbackHandler(session), true);
|
|
316
320
|
}
|
|
317
321
|
}
|
|
318
322
|
return callbackManager;
|
|
@@ -10,7 +10,7 @@ const text_splitter_js_1 = require("../text_splitter.cjs");
|
|
|
10
10
|
*/
|
|
11
11
|
class AnalyzeDocumentChain extends base_js_1.BaseChain {
|
|
12
12
|
constructor(fields) {
|
|
13
|
-
super(
|
|
13
|
+
super(fields);
|
|
14
14
|
Object.defineProperty(this, "inputKey", {
|
|
15
15
|
enumerable: true,
|
|
16
16
|
configurable: true,
|
|
@@ -7,7 +7,7 @@ import { RecursiveCharacterTextSplitter, } from "../text_splitter.js";
|
|
|
7
7
|
*/
|
|
8
8
|
export class AnalyzeDocumentChain extends BaseChain {
|
|
9
9
|
constructor(fields) {
|
|
10
|
-
super(
|
|
10
|
+
super(fields);
|
|
11
11
|
Object.defineProperty(this, "inputKey", {
|
|
12
12
|
enumerable: true,
|
|
13
13
|
configurable: true,
|
package/dist/chains/base.cjs
CHANGED
|
@@ -8,15 +8,30 @@ const index_js_2 = require("../base_language/index.cjs");
|
|
|
8
8
|
* Base interface that all chains must implement.
|
|
9
9
|
*/
|
|
10
10
|
class BaseChain extends index_js_2.BaseLangChain {
|
|
11
|
-
constructor(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
constructor(fields,
|
|
12
|
+
/** @deprecated */
|
|
13
|
+
verbose,
|
|
14
|
+
/** @deprecated */
|
|
15
|
+
callbacks) {
|
|
16
|
+
if (arguments.length === 1 &&
|
|
17
|
+
typeof fields === "object" &&
|
|
18
|
+
!("saveContext" in fields)) {
|
|
19
|
+
// fields is not a BaseMemory
|
|
20
|
+
const { memory, callbackManager, ...rest } = fields;
|
|
21
|
+
super({ ...rest, callbacks: callbackManager ?? rest.callbacks });
|
|
22
|
+
this.memory = memory;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// fields is a BaseMemory
|
|
26
|
+
super({ verbose, callbacks });
|
|
27
|
+
this.memory = fields;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Return a json-like object representing this chain.
|
|
32
|
+
*/
|
|
33
|
+
serialize() {
|
|
34
|
+
throw new Error("Method not implemented.");
|
|
20
35
|
}
|
|
21
36
|
async run(
|
|
22
37
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -36,7 +51,7 @@ class BaseChain extends index_js_2.BaseLangChain {
|
|
|
36
51
|
/**
|
|
37
52
|
* Run the core logic of this chain and add to output if desired.
|
|
38
53
|
*
|
|
39
|
-
* Wraps
|
|
54
|
+
* Wraps _call and handles memory.
|
|
40
55
|
*/
|
|
41
56
|
async call(values, callbacks) {
|
|
42
57
|
const fullValues = { ...values };
|
package/dist/chains/base.d.ts
CHANGED
|
@@ -16,7 +16,11 @@ export interface ChainInputs extends BaseLangChainParams {
|
|
|
16
16
|
*/
|
|
17
17
|
export declare abstract class BaseChain extends BaseLangChain implements ChainInputs {
|
|
18
18
|
memory?: BaseMemory;
|
|
19
|
-
constructor(
|
|
19
|
+
constructor(fields?: BaseMemory | ChainInputs,
|
|
20
|
+
/** @deprecated */
|
|
21
|
+
verbose?: boolean,
|
|
22
|
+
/** @deprecated */
|
|
23
|
+
callbacks?: Callbacks);
|
|
20
24
|
/**
|
|
21
25
|
* Run the core logic of this chain and return the output
|
|
22
26
|
*/
|
|
@@ -28,14 +32,14 @@ export declare abstract class BaseChain extends BaseLangChain implements ChainIn
|
|
|
28
32
|
/**
|
|
29
33
|
* Return a json-like object representing this chain.
|
|
30
34
|
*/
|
|
31
|
-
|
|
35
|
+
serialize(): SerializedBaseChain;
|
|
32
36
|
abstract get inputKeys(): string[];
|
|
33
37
|
abstract get outputKeys(): string[];
|
|
34
38
|
run(input: any, callbacks?: Callbacks): Promise<string>;
|
|
35
39
|
/**
|
|
36
40
|
* Run the core logic of this chain and add to output if desired.
|
|
37
41
|
*
|
|
38
|
-
* Wraps
|
|
42
|
+
* Wraps _call and handles memory.
|
|
39
43
|
*/
|
|
40
44
|
call(values: ChainValues, callbacks?: Callbacks): Promise<ChainValues>;
|
|
41
45
|
/**
|
package/dist/chains/base.js
CHANGED
|
@@ -5,15 +5,30 @@ import { BaseLangChain } from "../base_language/index.js";
|
|
|
5
5
|
* Base interface that all chains must implement.
|
|
6
6
|
*/
|
|
7
7
|
export class BaseChain extends BaseLangChain {
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
constructor(fields,
|
|
9
|
+
/** @deprecated */
|
|
10
|
+
verbose,
|
|
11
|
+
/** @deprecated */
|
|
12
|
+
callbacks) {
|
|
13
|
+
if (arguments.length === 1 &&
|
|
14
|
+
typeof fields === "object" &&
|
|
15
|
+
!("saveContext" in fields)) {
|
|
16
|
+
// fields is not a BaseMemory
|
|
17
|
+
const { memory, callbackManager, ...rest } = fields;
|
|
18
|
+
super({ ...rest, callbacks: callbackManager ?? rest.callbacks });
|
|
19
|
+
this.memory = memory;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
// fields is a BaseMemory
|
|
23
|
+
super({ verbose, callbacks });
|
|
24
|
+
this.memory = fields;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Return a json-like object representing this chain.
|
|
29
|
+
*/
|
|
30
|
+
serialize() {
|
|
31
|
+
throw new Error("Method not implemented.");
|
|
17
32
|
}
|
|
18
33
|
async run(
|
|
19
34
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -33,7 +48,7 @@ export class BaseChain extends BaseLangChain {
|
|
|
33
48
|
/**
|
|
34
49
|
* Run the core logic of this chain and add to output if desired.
|
|
35
50
|
*
|
|
36
|
-
* Wraps
|
|
51
|
+
* Wraps _call and handles memory.
|
|
37
52
|
*/
|
|
38
53
|
async call(values, callbacks) {
|
|
39
54
|
const fullValues = { ...values };
|
|
@@ -2,17 +2,18 @@ import { BaseLanguageModel } from "../base_language/index.js";
|
|
|
2
2
|
import { VectorStore } from "../vectorstores/base.js";
|
|
3
3
|
import { SerializedChatVectorDBQAChain } from "./serde.js";
|
|
4
4
|
import { ChainValues } from "../schema/index.js";
|
|
5
|
-
import { BaseChain } from "./base.js";
|
|
5
|
+
import { BaseChain, ChainInputs } from "./base.js";
|
|
6
6
|
import { LLMChain } from "./llm_chain.js";
|
|
7
7
|
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
8
8
|
export type LoadValues = Record<string, any>;
|
|
9
|
-
export interface ChatVectorDBQAChainInput {
|
|
9
|
+
export interface ChatVectorDBQAChainInput extends ChainInputs {
|
|
10
10
|
vectorstore: VectorStore;
|
|
11
|
-
k: number;
|
|
12
11
|
combineDocumentsChain: BaseChain;
|
|
13
12
|
questionGeneratorChain: LLMChain;
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
returnSourceDocuments?: boolean;
|
|
14
|
+
outputKey?: string;
|
|
15
|
+
inputKey?: string;
|
|
16
|
+
k?: number;
|
|
16
17
|
}
|
|
17
18
|
export declare class ChatVectorDBQAChain extends BaseChain implements ChatVectorDBQAChainInput {
|
|
18
19
|
k: number;
|
|
@@ -25,15 +26,7 @@ export declare class ChatVectorDBQAChain extends BaseChain implements ChatVector
|
|
|
25
26
|
combineDocumentsChain: BaseChain;
|
|
26
27
|
questionGeneratorChain: LLMChain;
|
|
27
28
|
returnSourceDocuments: boolean;
|
|
28
|
-
constructor(fields:
|
|
29
|
-
vectorstore: VectorStore;
|
|
30
|
-
combineDocumentsChain: BaseChain;
|
|
31
|
-
questionGeneratorChain: LLMChain;
|
|
32
|
-
inputKey?: string;
|
|
33
|
-
outputKey?: string;
|
|
34
|
-
k?: number;
|
|
35
|
-
returnSourceDocuments?: boolean;
|
|
36
|
-
});
|
|
29
|
+
constructor(fields: ChatVectorDBQAChainInput);
|
|
37
30
|
/** @ignore */
|
|
38
31
|
_call(values: ChainValues, runManager?: CallbackManagerForChainRun): Promise<ChainValues>;
|
|
39
32
|
_chainType(): "chat-vector-db";
|
|
@@ -17,7 +17,7 @@ class StuffDocumentsChain extends base_js_1.BaseChain {
|
|
|
17
17
|
return this.llmChain.outputKeys;
|
|
18
18
|
}
|
|
19
19
|
constructor(fields) {
|
|
20
|
-
super();
|
|
20
|
+
super(fields);
|
|
21
21
|
Object.defineProperty(this, "llmChain", {
|
|
22
22
|
enumerable: true,
|
|
23
23
|
configurable: true,
|
|
@@ -87,7 +87,7 @@ class MapReduceDocumentsChain extends base_js_1.BaseChain {
|
|
|
87
87
|
return this.combineDocumentChain.outputKeys;
|
|
88
88
|
}
|
|
89
89
|
constructor(fields) {
|
|
90
|
-
super();
|
|
90
|
+
super(fields);
|
|
91
91
|
Object.defineProperty(this, "llmChain", {
|
|
92
92
|
enumerable: true,
|
|
93
93
|
configurable: true,
|
|
@@ -214,7 +214,7 @@ class RefineDocumentsChain extends base_js_1.BaseChain {
|
|
|
214
214
|
return [this.outputKey];
|
|
215
215
|
}
|
|
216
216
|
constructor(fields) {
|
|
217
|
-
super();
|
|
217
|
+
super(fields);
|
|
218
218
|
Object.defineProperty(this, "llmChain", {
|
|
219
219
|
enumerable: true,
|
|
220
220
|
configurable: true,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { SerializedStuffDocumentsChain, SerializedMapReduceDocumentsChain, SerializedRefineDocumentsChain } from "./serde.js";
|
|
2
|
-
import { BaseChain } from "./base.js";
|
|
2
|
+
import { BaseChain, ChainInputs } from "./base.js";
|
|
3
3
|
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
7
|
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
8
|
-
export interface StuffDocumentsChainInput {
|
|
8
|
+
export interface StuffDocumentsChainInput extends ChainInputs {
|
|
9
9
|
/** LLM Wrapper to use after formatting documents */
|
|
10
10
|
llmChain: LLMChain;
|
|
11
11
|
inputKey?: string;
|
|
@@ -14,7 +14,7 @@ export class StuffDocumentsChain extends BaseChain {
|
|
|
14
14
|
return this.llmChain.outputKeys;
|
|
15
15
|
}
|
|
16
16
|
constructor(fields) {
|
|
17
|
-
super();
|
|
17
|
+
super(fields);
|
|
18
18
|
Object.defineProperty(this, "llmChain", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
configurable: true,
|
|
@@ -83,7 +83,7 @@ export class MapReduceDocumentsChain extends BaseChain {
|
|
|
83
83
|
return this.combineDocumentChain.outputKeys;
|
|
84
84
|
}
|
|
85
85
|
constructor(fields) {
|
|
86
|
-
super();
|
|
86
|
+
super(fields);
|
|
87
87
|
Object.defineProperty(this, "llmChain", {
|
|
88
88
|
enumerable: true,
|
|
89
89
|
configurable: true,
|
|
@@ -209,7 +209,7 @@ export class RefineDocumentsChain extends BaseChain {
|
|
|
209
209
|
return [this.outputKey];
|
|
210
210
|
}
|
|
211
211
|
constructor(fields) {
|
|
212
|
-
super();
|
|
212
|
+
super(fields);
|
|
213
213
|
Object.defineProperty(this, "llmChain", {
|
|
214
214
|
enumerable: true,
|
|
215
215
|
configurable: true,
|
|
@@ -25,7 +25,7 @@ class ConversationalRetrievalQAChain extends base_js_1.BaseChain {
|
|
|
25
25
|
return this.combineDocumentsChain.outputKeys.concat(this.returnSourceDocuments ? ["sourceDocuments"] : []);
|
|
26
26
|
}
|
|
27
27
|
constructor(fields) {
|
|
28
|
-
super(
|
|
28
|
+
super(fields);
|
|
29
29
|
Object.defineProperty(this, "inputKey", {
|
|
30
30
|
enumerable: true,
|
|
31
31
|
configurable: true,
|
|
@@ -22,7 +22,7 @@ export class ConversationalRetrievalQAChain extends BaseChain {
|
|
|
22
22
|
return this.combineDocumentsChain.outputKeys.concat(this.returnSourceDocuments ? ["sourceDocuments"] : []);
|
|
23
23
|
}
|
|
24
24
|
constructor(fields) {
|
|
25
|
-
super(
|
|
25
|
+
super(fields);
|
|
26
26
|
Object.defineProperty(this, "inputKey", {
|
|
27
27
|
enumerable: true,
|
|
28
28
|
configurable: true,
|
|
@@ -25,7 +25,7 @@ class LLMChain extends base_js_1.BaseChain {
|
|
|
25
25
|
return [this.outputKey];
|
|
26
26
|
}
|
|
27
27
|
constructor(fields) {
|
|
28
|
-
super(fields
|
|
28
|
+
super(fields);
|
|
29
29
|
Object.defineProperty(this, "prompt", {
|
|
30
30
|
enumerable: true,
|
|
31
31
|
configurable: true,
|
|
@@ -62,11 +62,11 @@ class LLMChain extends base_js_1.BaseChain {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
/** @ignore */
|
|
65
|
-
async _getFinalOutput(generations, promptValue) {
|
|
65
|
+
async _getFinalOutput(generations, promptValue, runManager) {
|
|
66
66
|
const completion = generations[0].text;
|
|
67
67
|
let finalCompletion;
|
|
68
68
|
if (this.outputParser) {
|
|
69
|
-
finalCompletion = await this.outputParser.parseWithPrompt(completion, promptValue);
|
|
69
|
+
finalCompletion = await this.outputParser.parseWithPrompt(completion, promptValue, runManager?.getChild());
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
72
|
finalCompletion = completion;
|
|
@@ -82,7 +82,7 @@ class LLMChain extends base_js_1.BaseChain {
|
|
|
82
82
|
const promptValue = await this.prompt.formatPromptValue(values);
|
|
83
83
|
const { generations } = await this.llm.generatePrompt([promptValue], stop, runManager?.getChild());
|
|
84
84
|
return {
|
|
85
|
-
[this.outputKey]: await this._getFinalOutput(generations[0], promptValue),
|
|
85
|
+
[this.outputKey]: await this._getFinalOutput(generations[0], promptValue, runManager),
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { BaseChain, ChainInputs } from "./base.js";
|
|
2
2
|
import { BasePromptTemplate } from "../prompts/base.js";
|
|
3
3
|
import { BaseLanguageModel } from "../base_language/index.js";
|
|
4
|
-
import { ChainValues, Generation, BasePromptValue
|
|
4
|
+
import { ChainValues, Generation, BasePromptValue } from "../schema/index.js";
|
|
5
|
+
import { BaseOutputParser } from "../schema/output_parser.js";
|
|
5
6
|
import { SerializedLLMChain } from "./serde.js";
|
|
6
7
|
import { CallbackManager } from "../callbacks/index.js";
|
|
7
8
|
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
@@ -37,7 +38,7 @@ export declare class LLMChain extends BaseChain implements LLMChainInput {
|
|
|
37
38
|
get outputKeys(): string[];
|
|
38
39
|
constructor(fields: LLMChainInput);
|
|
39
40
|
/** @ignore */
|
|
40
|
-
_getFinalOutput(generations: Generation[], promptValue: BasePromptValue): Promise<unknown>;
|
|
41
|
+
_getFinalOutput(generations: Generation[], promptValue: BasePromptValue, runManager?: CallbackManagerForChainRun): Promise<unknown>;
|
|
41
42
|
/** @ignore */
|
|
42
43
|
_call(values: ChainValues, runManager?: CallbackManagerForChainRun): Promise<ChainValues>;
|
|
43
44
|
/**
|
package/dist/chains/llm_chain.js
CHANGED
|
@@ -22,7 +22,7 @@ export class LLMChain extends BaseChain {
|
|
|
22
22
|
return [this.outputKey];
|
|
23
23
|
}
|
|
24
24
|
constructor(fields) {
|
|
25
|
-
super(fields
|
|
25
|
+
super(fields);
|
|
26
26
|
Object.defineProperty(this, "prompt", {
|
|
27
27
|
enumerable: true,
|
|
28
28
|
configurable: true,
|
|
@@ -59,11 +59,11 @@ export class LLMChain extends BaseChain {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
/** @ignore */
|
|
62
|
-
async _getFinalOutput(generations, promptValue) {
|
|
62
|
+
async _getFinalOutput(generations, promptValue, runManager) {
|
|
63
63
|
const completion = generations[0].text;
|
|
64
64
|
let finalCompletion;
|
|
65
65
|
if (this.outputParser) {
|
|
66
|
-
finalCompletion = await this.outputParser.parseWithPrompt(completion, promptValue);
|
|
66
|
+
finalCompletion = await this.outputParser.parseWithPrompt(completion, promptValue, runManager?.getChild());
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
69
69
|
finalCompletion = completion;
|
|
@@ -79,7 +79,7 @@ export class LLMChain extends BaseChain {
|
|
|
79
79
|
const promptValue = await this.prompt.formatPromptValue(values);
|
|
80
80
|
const { generations } = await this.llm.generatePrompt([promptValue], stop, runManager?.getChild());
|
|
81
81
|
return {
|
|
82
|
-
[this.outputKey]: await this._getFinalOutput(generations[0], promptValue),
|
|
82
|
+
[this.outputKey]: await this._getFinalOutput(generations[0], promptValue, runManager),
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
@@ -11,7 +11,7 @@ class RetrievalQAChain extends base_js_1.BaseChain {
|
|
|
11
11
|
return this.combineDocumentsChain.outputKeys.concat(this.returnSourceDocuments ? ["sourceDocuments"] : []);
|
|
12
12
|
}
|
|
13
13
|
constructor(fields) {
|
|
14
|
-
super(
|
|
14
|
+
super(fields);
|
|
15
15
|
Object.defineProperty(this, "inputKey", {
|
|
16
16
|
enumerable: true,
|
|
17
17
|
configurable: true,
|
|
@@ -8,7 +8,7 @@ export class RetrievalQAChain extends BaseChain {
|
|
|
8
8
|
return this.combineDocumentsChain.outputKeys.concat(this.returnSourceDocuments ? ["sourceDocuments"] : []);
|
|
9
9
|
}
|
|
10
10
|
constructor(fields) {
|
|
11
|
-
super(
|
|
11
|
+
super(fields);
|
|
12
12
|
Object.defineProperty(this, "inputKey", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
configurable: true,
|
|
@@ -19,7 +19,7 @@ class SequentialChain extends base_js_1.BaseChain {
|
|
|
19
19
|
return this.outputVariables;
|
|
20
20
|
}
|
|
21
21
|
constructor(fields) {
|
|
22
|
-
super(fields
|
|
22
|
+
super(fields);
|
|
23
23
|
Object.defineProperty(this, "chains", {
|
|
24
24
|
enumerable: true,
|
|
25
25
|
configurable: true,
|
|
@@ -16,7 +16,7 @@ export class SequentialChain extends BaseChain {
|
|
|
16
16
|
return this.outputVariables;
|
|
17
17
|
}
|
|
18
18
|
constructor(fields) {
|
|
19
|
-
super(fields
|
|
19
|
+
super(fields);
|
|
20
20
|
Object.defineProperty(this, "chains", {
|
|
21
21
|
enumerable: true,
|
|
22
22
|
configurable: true,
|
|
@@ -8,7 +8,7 @@ const index_js_1 = require("../../base_language/index.cjs");
|
|
|
8
8
|
const count_tokens_js_1 = require("../../base_language/count_tokens.cjs");
|
|
9
9
|
class SqlDatabaseChain extends base_js_1.BaseChain {
|
|
10
10
|
constructor(fields) {
|
|
11
|
-
super(fields
|
|
11
|
+
super(fields);
|
|
12
12
|
// LLM wrapper to use
|
|
13
13
|
Object.defineProperty(this, "llm", {
|
|
14
14
|
enumerable: true,
|
|
@@ -5,7 +5,7 @@ import { BaseLanguageModel } from "../../base_language/index.js";
|
|
|
5
5
|
import { calculateMaxTokens, getModelContextSize, } from "../../base_language/count_tokens.js";
|
|
6
6
|
export class SqlDatabaseChain extends BaseChain {
|
|
7
7
|
constructor(fields) {
|
|
8
|
-
super(fields
|
|
8
|
+
super(fields);
|
|
9
9
|
// LLM wrapper to use
|
|
10
10
|
Object.defineProperty(this, "llm", {
|
|
11
11
|
enumerable: true,
|
|
@@ -11,7 +11,7 @@ class VectorDBQAChain extends base_js_1.BaseChain {
|
|
|
11
11
|
return this.combineDocumentsChain.outputKeys.concat(this.returnSourceDocuments ? ["sourceDocuments"] : []);
|
|
12
12
|
}
|
|
13
13
|
constructor(fields) {
|
|
14
|
-
super(
|
|
14
|
+
super(fields);
|
|
15
15
|
Object.defineProperty(this, "k", {
|
|
16
16
|
enumerable: true,
|
|
17
17
|
configurable: true,
|
|
@@ -8,7 +8,7 @@ export class VectorDBQAChain extends BaseChain {
|
|
|
8
8
|
return this.combineDocumentsChain.outputKeys.concat(this.returnSourceDocuments ? ["sourceDocuments"] : []);
|
|
9
9
|
}
|
|
10
10
|
constructor(fields) {
|
|
11
|
-
super(
|
|
11
|
+
super(fields);
|
|
12
12
|
Object.defineProperty(this, "k", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
configurable: true,
|