langchain 0.0.74 → 0.0.76
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/client.cjs +1 -0
- package/client.d.ts +1 -0
- package/client.js +1 -0
- package/dist/base_language/count_tokens.cjs +5 -21
- package/dist/base_language/count_tokens.d.ts +1 -6
- package/dist/base_language/count_tokens.js +4 -19
- package/dist/base_language/index.cjs +16 -24
- package/dist/base_language/index.d.ts +22 -3
- package/dist/base_language/index.js +17 -25
- package/dist/cache/redis.d.ts +3 -1
- package/dist/callbacks/base.d.ts +17 -3
- package/dist/callbacks/handlers/console.cjs +15 -28
- package/dist/callbacks/handlers/console.d.ts +11 -20
- package/dist/callbacks/handlers/console.js +14 -27
- package/dist/callbacks/handlers/initialize.cjs +8 -3
- package/dist/callbacks/handlers/initialize.d.ts +4 -2
- package/dist/callbacks/handlers/initialize.js +6 -2
- package/dist/callbacks/handlers/tracer.cjs +193 -0
- package/dist/callbacks/handlers/tracer.d.ts +65 -0
- package/dist/callbacks/handlers/tracer.js +189 -0
- package/dist/callbacks/handlers/tracer_langchain.cjs +163 -0
- package/dist/callbacks/handlers/tracer_langchain.d.ts +39 -0
- package/dist/callbacks/handlers/tracer_langchain.js +159 -0
- package/dist/callbacks/handlers/tracer_langchain_v1.cjs +202 -0
- package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +57 -0
- package/dist/callbacks/handlers/tracer_langchain_v1.js +198 -0
- package/dist/callbacks/index.cjs +10 -5
- package/dist/callbacks/index.d.ts +5 -3
- package/dist/callbacks/index.js +5 -3
- package/dist/callbacks/manager.cjs +39 -9
- package/dist/callbacks/manager.d.ts +5 -2
- package/dist/callbacks/manager.js +40 -10
- package/dist/chains/llm_chain.cjs +17 -5
- package/dist/chains/llm_chain.d.ts +9 -3
- package/dist/chains/llm_chain.js +17 -5
- package/dist/chains/question_answering/map_reduce_prompts.cjs +5 -5
- package/dist/chains/question_answering/map_reduce_prompts.d.ts +1 -1
- package/dist/chains/question_answering/map_reduce_prompts.js +1 -1
- package/dist/chains/question_answering/refine_prompts.cjs +5 -5
- package/dist/chains/question_answering/refine_prompts.d.ts +1 -1
- package/dist/chains/question_answering/refine_prompts.js +1 -1
- package/dist/chains/question_answering/stuff_prompts.cjs +2 -2
- package/dist/chains/question_answering/stuff_prompts.d.ts +1 -1
- package/dist/chains/question_answering/stuff_prompts.js +1 -1
- package/dist/chains/sequential_chain.cjs +2 -2
- package/dist/chains/sequential_chain.d.ts +2 -2
- package/dist/chains/sequential_chain.js +2 -2
- package/dist/chains/sql_db/sql_db_prompt.cjs +20 -1
- package/dist/chains/sql_db/sql_db_prompt.d.ts +1 -0
- package/dist/chains/sql_db/sql_db_prompt.js +19 -0
- package/dist/chains/summarization/load.cjs +14 -5
- package/dist/chains/summarization/load.d.ts +7 -2
- package/dist/chains/summarization/load.js +14 -5
- package/dist/chat_models/anthropic.cjs +36 -9
- package/dist/chat_models/anthropic.d.ts +6 -3
- package/dist/chat_models/anthropic.js +36 -9
- package/dist/chat_models/base.cjs +40 -13
- package/dist/chat_models/base.d.ts +14 -7
- package/dist/chat_models/base.js +41 -14
- package/dist/chat_models/openai.cjs +20 -14
- package/dist/chat_models/openai.d.ts +2 -1
- package/dist/chat_models/openai.js +20 -14
- package/dist/client/index.cjs +5 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.js +1 -0
- package/dist/client/langchainplus.cjs +405 -0
- package/dist/client/langchainplus.d.ts +65 -0
- package/dist/client/langchainplus.js +398 -0
- package/dist/document_loaders/fs/unstructured.cjs +8 -0
- package/dist/document_loaders/fs/unstructured.d.ts +3 -0
- package/dist/document_loaders/fs/unstructured.js +8 -0
- package/dist/document_loaders/web/apify_dataset.cjs +64 -0
- package/dist/document_loaders/web/apify_dataset.d.ts +28 -0
- package/dist/document_loaders/web/apify_dataset.js +60 -0
- package/dist/embeddings/openai.cjs +2 -2
- package/dist/embeddings/openai.js +2 -2
- package/dist/llms/base.cjs +43 -17
- package/dist/llms/base.d.ts +16 -9
- package/dist/llms/base.js +44 -18
- package/dist/llms/cohere.cjs +3 -2
- package/dist/llms/cohere.d.ts +1 -1
- package/dist/llms/cohere.js +3 -2
- package/dist/llms/hf.cjs +2 -2
- package/dist/llms/hf.d.ts +1 -1
- package/dist/llms/hf.js +2 -2
- package/dist/llms/openai-chat.cjs +13 -14
- package/dist/llms/openai-chat.d.ts +2 -1
- package/dist/llms/openai-chat.js +13 -14
- package/dist/llms/openai.cjs +15 -13
- package/dist/llms/openai.d.ts +4 -3
- package/dist/llms/openai.js +15 -13
- package/dist/llms/replicate.cjs +2 -2
- package/dist/llms/replicate.d.ts +1 -1
- package/dist/llms/replicate.js +2 -2
- package/dist/memory/base.cjs +9 -1
- package/dist/memory/base.d.ts +1 -0
- package/dist/memory/base.js +7 -0
- package/dist/memory/entity_memory.cjs +151 -0
- package/dist/memory/entity_memory.d.ts +35 -0
- package/dist/memory/entity_memory.js +147 -0
- package/dist/memory/index.cjs +5 -1
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.js +2 -0
- package/dist/memory/prompt.cjs +84 -1
- package/dist/memory/prompt.d.ts +6 -0
- package/dist/memory/prompt.js +83 -0
- package/dist/memory/stores/entity/in_memory.cjs +32 -0
- package/dist/memory/stores/entity/in_memory.d.ts +10 -0
- package/dist/memory/stores/entity/in_memory.js +28 -0
- package/dist/prompts/index.cjs +6 -1
- package/dist/prompts/index.d.ts +1 -0
- package/dist/prompts/index.js +1 -0
- package/dist/{chains/prompt_selector.d.ts → prompts/selectors/conditional.d.ts} +4 -4
- package/dist/retrievers/document_compressors/chain_extract.cjs +9 -11
- package/dist/retrievers/document_compressors/chain_extract.js +9 -11
- package/dist/schema/index.cjs +13 -1
- package/dist/schema/index.d.ts +19 -0
- package/dist/schema/index.js +11 -0
- package/dist/stores/message/dynamodb.cjs +8 -6
- package/dist/stores/message/dynamodb.js +8 -6
- package/dist/stores/message/redis.cjs +69 -0
- package/dist/stores/message/redis.d.ts +18 -0
- package/dist/stores/message/redis.js +65 -0
- package/dist/stores/message/utils.cjs +30 -15
- package/dist/stores/message/utils.d.ts +4 -2
- package/dist/stores/message/utils.js +28 -14
- package/dist/text_splitter.cjs +3 -23
- package/dist/text_splitter.d.ts +1 -3
- package/dist/text_splitter.js +3 -23
- package/dist/tools/webbrowser.cjs +5 -7
- package/dist/tools/webbrowser.js +3 -5
- package/dist/types/openai-types.d.ts +3 -2
- package/dist/util/async_caller.cjs +16 -0
- package/dist/util/async_caller.d.ts +4 -0
- package/dist/util/async_caller.js +16 -0
- package/dist/util/axios-fetch-adapter.cjs +6 -0
- package/dist/util/axios-fetch-adapter.js +6 -0
- package/dist/util/env.cjs +39 -7
- package/dist/util/env.d.ts +19 -0
- package/dist/util/env.js +32 -6
- package/dist/util/sql_utils.cjs +18 -0
- package/dist/util/sql_utils.js +19 -1
- package/dist/util/tiktoken.cjs +26 -0
- package/dist/util/tiktoken.d.ts +9 -0
- package/dist/util/tiktoken.js +21 -0
- package/dist/vectorstores/redis.cjs +236 -0
- package/dist/vectorstores/redis.d.ts +80 -0
- package/dist/vectorstores/redis.js +232 -0
- package/document_loaders/web/apify_dataset.cjs +1 -0
- package/document_loaders/web/apify_dataset.d.ts +1 -0
- package/document_loaders/web/apify_dataset.js +1 -0
- package/package.json +41 -5
- package/stores/message/redis.cjs +1 -0
- package/stores/message/redis.d.ts +1 -0
- package/stores/message/redis.js +1 -0
- package/vectorstores/redis.cjs +1 -0
- package/vectorstores/redis.d.ts +1 -0
- package/vectorstores/redis.js +1 -0
- package/dist/callbacks/handlers/tracers.cjs +0 -341
- package/dist/callbacks/handlers/tracers.d.ts +0 -100
- package/dist/callbacks/handlers/tracers.js +0 -336
- /package/dist/{chains/prompt_selector.cjs → prompts/selectors/conditional.cjs} +0 -0
- /package/dist/{chains/prompt_selector.js → prompts/selectors/conditional.js} +0 -0
|
@@ -5,6 +5,7 @@ const uuid_1 = require("uuid");
|
|
|
5
5
|
const base_js_1 = require("./base.cjs");
|
|
6
6
|
const console_js_1 = require("./handlers/console.cjs");
|
|
7
7
|
const initialize_js_1 = require("./handlers/initialize.cjs");
|
|
8
|
+
const base_js_2 = require("../memory/base.cjs");
|
|
8
9
|
class BaseCallbackManager {
|
|
9
10
|
setHandler(handler) {
|
|
10
11
|
return this.setHandlers([handler]);
|
|
@@ -209,11 +210,30 @@ class CallbackManager extends BaseCallbackManager {
|
|
|
209
210
|
this.inheritableHandlers = [];
|
|
210
211
|
this._parentRunId = parentRunId;
|
|
211
212
|
}
|
|
212
|
-
async handleLLMStart(llm, prompts, runId = (0, uuid_1.v4)()) {
|
|
213
|
+
async handleLLMStart(llm, prompts, runId = (0, uuid_1.v4)(), _parentRunId = undefined, extraParams = undefined) {
|
|
213
214
|
await Promise.all(this.handlers.map(async (handler) => {
|
|
214
215
|
if (!handler.ignoreLLM) {
|
|
215
216
|
try {
|
|
216
|
-
await handler.handleLLMStart?.(llm, prompts, runId, this._parentRunId);
|
|
217
|
+
await handler.handleLLMStart?.(llm, prompts, runId, this._parentRunId, extraParams);
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
console.error(`Error in handler ${handler.constructor.name}, handleLLMStart: ${err}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}));
|
|
224
|
+
return new CallbackManagerForLLMRun(runId, this.handlers, this.inheritableHandlers, this._parentRunId);
|
|
225
|
+
}
|
|
226
|
+
async handleChatModelStart(llm, messages, runId = (0, uuid_1.v4)(), _parentRunId = undefined, extraParams = undefined) {
|
|
227
|
+
let messageStrings;
|
|
228
|
+
await Promise.all(this.handlers.map(async (handler) => {
|
|
229
|
+
if (!handler.ignoreLLM) {
|
|
230
|
+
try {
|
|
231
|
+
if (handler.handleChatModelStart)
|
|
232
|
+
await handler.handleChatModelStart?.(llm, messages, runId, this._parentRunId, extraParams);
|
|
233
|
+
else if (handler.handleLLMStart) {
|
|
234
|
+
messageStrings = messages.map((x) => (0, base_js_2.getBufferString)(x));
|
|
235
|
+
await handler.handleLLMStart?.(llm, messageStrings, runId, this._parentRunId, extraParams);
|
|
236
|
+
}
|
|
217
237
|
}
|
|
218
238
|
catch (err) {
|
|
219
239
|
console.error(`Error in handler ${handler.constructor.name}, handleLLMStart: ${err}`);
|
|
@@ -314,10 +334,15 @@ class CallbackManager extends BaseCallbackManager {
|
|
|
314
334
|
? localHandlers.map(ensureHandler)
|
|
315
335
|
: localHandlers?.handlers, false);
|
|
316
336
|
}
|
|
317
|
-
const
|
|
337
|
+
const tracingV2Enabled = typeof process !== "undefined"
|
|
318
338
|
? // eslint-disable-next-line no-process-env
|
|
319
|
-
process.env?.
|
|
339
|
+
process.env?.LANGCHAIN_TRACING_V2 !== undefined
|
|
320
340
|
: false;
|
|
341
|
+
const tracingEnabled = tracingV2Enabled ||
|
|
342
|
+
(typeof process !== "undefined"
|
|
343
|
+
? // eslint-disable-next-line no-process-env
|
|
344
|
+
process.env?.LANGCHAIN_TRACING !== undefined
|
|
345
|
+
: false);
|
|
321
346
|
if (options?.verbose || tracingEnabled) {
|
|
322
347
|
if (!callbackManager) {
|
|
323
348
|
callbackManager = new CallbackManager();
|
|
@@ -329,11 +354,16 @@ class CallbackManager extends BaseCallbackManager {
|
|
|
329
354
|
}
|
|
330
355
|
if (tracingEnabled &&
|
|
331
356
|
!callbackManager.handlers.some((handler) => handler.name === "langchain_tracer")) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
357
|
+
if (tracingV2Enabled) {
|
|
358
|
+
callbackManager.addHandler(await (0, initialize_js_1.getTracingV2CallbackHandler)(), true);
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
const session = typeof process !== "undefined"
|
|
362
|
+
? // eslint-disable-next-line no-process-env
|
|
363
|
+
process.env?.LANGCHAIN_SESSION
|
|
364
|
+
: undefined;
|
|
365
|
+
callbackManager.addHandler(await (0, initialize_js_1.getTracingCallbackHandler)(session), true);
|
|
366
|
+
}
|
|
337
367
|
}
|
|
338
368
|
}
|
|
339
369
|
return callbackManager;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AgentAction, AgentFinish, ChainValues, LLMResult } from "../schema/index.js";
|
|
1
|
+
import { AgentAction, AgentFinish, BaseChatMessage, ChainValues, LLMResult } from "../schema/index.js";
|
|
2
2
|
import { BaseCallbackHandler, CallbackHandlerMethods } from "./base.js";
|
|
3
3
|
type BaseCallbackManagerMethods = {
|
|
4
4
|
[K in keyof CallbackHandlerMethods]?: (...args: Parameters<Required<CallbackHandlerMethods>[K]>) => Promise<unknown>;
|
|
@@ -47,7 +47,10 @@ export declare class CallbackManager extends BaseCallbackManager implements Base
|
|
|
47
47
|
constructor(parentRunId?: string);
|
|
48
48
|
handleLLMStart(llm: {
|
|
49
49
|
name: string;
|
|
50
|
-
}, prompts: string[], runId?: string): Promise<CallbackManagerForLLMRun>;
|
|
50
|
+
}, prompts: string[], runId?: string, _parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined): Promise<CallbackManagerForLLMRun>;
|
|
51
|
+
handleChatModelStart(llm: {
|
|
52
|
+
name: string;
|
|
53
|
+
}, messages: BaseChatMessage[][], runId?: string, _parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined): Promise<CallbackManagerForLLMRun>;
|
|
51
54
|
handleChainStart(chain: {
|
|
52
55
|
name: string;
|
|
53
56
|
}, inputs: ChainValues, runId?: string): Promise<CallbackManagerForChainRun>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from "uuid";
|
|
2
2
|
import { BaseCallbackHandler } from "./base.js";
|
|
3
3
|
import { ConsoleCallbackHandler } from "./handlers/console.js";
|
|
4
|
-
import { getTracingCallbackHandler } from "./handlers/initialize.js";
|
|
4
|
+
import { getTracingCallbackHandler, getTracingV2CallbackHandler, } from "./handlers/initialize.js";
|
|
5
|
+
import { getBufferString } from "../memory/base.js";
|
|
5
6
|
export class BaseCallbackManager {
|
|
6
7
|
setHandler(handler) {
|
|
7
8
|
return this.setHandlers([handler]);
|
|
@@ -202,11 +203,30 @@ export class CallbackManager extends BaseCallbackManager {
|
|
|
202
203
|
this.inheritableHandlers = [];
|
|
203
204
|
this._parentRunId = parentRunId;
|
|
204
205
|
}
|
|
205
|
-
async handleLLMStart(llm, prompts, runId = uuidv4()) {
|
|
206
|
+
async handleLLMStart(llm, prompts, runId = uuidv4(), _parentRunId = undefined, extraParams = undefined) {
|
|
206
207
|
await Promise.all(this.handlers.map(async (handler) => {
|
|
207
208
|
if (!handler.ignoreLLM) {
|
|
208
209
|
try {
|
|
209
|
-
await handler.handleLLMStart?.(llm, prompts, runId, this._parentRunId);
|
|
210
|
+
await handler.handleLLMStart?.(llm, prompts, runId, this._parentRunId, extraParams);
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
console.error(`Error in handler ${handler.constructor.name}, handleLLMStart: ${err}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}));
|
|
217
|
+
return new CallbackManagerForLLMRun(runId, this.handlers, this.inheritableHandlers, this._parentRunId);
|
|
218
|
+
}
|
|
219
|
+
async handleChatModelStart(llm, messages, runId = uuidv4(), _parentRunId = undefined, extraParams = undefined) {
|
|
220
|
+
let messageStrings;
|
|
221
|
+
await Promise.all(this.handlers.map(async (handler) => {
|
|
222
|
+
if (!handler.ignoreLLM) {
|
|
223
|
+
try {
|
|
224
|
+
if (handler.handleChatModelStart)
|
|
225
|
+
await handler.handleChatModelStart?.(llm, messages, runId, this._parentRunId, extraParams);
|
|
226
|
+
else if (handler.handleLLMStart) {
|
|
227
|
+
messageStrings = messages.map((x) => getBufferString(x));
|
|
228
|
+
await handler.handleLLMStart?.(llm, messageStrings, runId, this._parentRunId, extraParams);
|
|
229
|
+
}
|
|
210
230
|
}
|
|
211
231
|
catch (err) {
|
|
212
232
|
console.error(`Error in handler ${handler.constructor.name}, handleLLMStart: ${err}`);
|
|
@@ -307,10 +327,15 @@ export class CallbackManager extends BaseCallbackManager {
|
|
|
307
327
|
? localHandlers.map(ensureHandler)
|
|
308
328
|
: localHandlers?.handlers, false);
|
|
309
329
|
}
|
|
310
|
-
const
|
|
330
|
+
const tracingV2Enabled = typeof process !== "undefined"
|
|
311
331
|
? // eslint-disable-next-line no-process-env
|
|
312
|
-
process.env?.
|
|
332
|
+
process.env?.LANGCHAIN_TRACING_V2 !== undefined
|
|
313
333
|
: false;
|
|
334
|
+
const tracingEnabled = tracingV2Enabled ||
|
|
335
|
+
(typeof process !== "undefined"
|
|
336
|
+
? // eslint-disable-next-line no-process-env
|
|
337
|
+
process.env?.LANGCHAIN_TRACING !== undefined
|
|
338
|
+
: false);
|
|
314
339
|
if (options?.verbose || tracingEnabled) {
|
|
315
340
|
if (!callbackManager) {
|
|
316
341
|
callbackManager = new CallbackManager();
|
|
@@ -322,11 +347,16 @@ export class CallbackManager extends BaseCallbackManager {
|
|
|
322
347
|
}
|
|
323
348
|
if (tracingEnabled &&
|
|
324
349
|
!callbackManager.handlers.some((handler) => handler.name === "langchain_tracer")) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
350
|
+
if (tracingV2Enabled) {
|
|
351
|
+
callbackManager.addHandler(await getTracingV2CallbackHandler(), true);
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
const session = typeof process !== "undefined"
|
|
355
|
+
? // eslint-disable-next-line no-process-env
|
|
356
|
+
process.env?.LANGCHAIN_SESSION
|
|
357
|
+
: undefined;
|
|
358
|
+
callbackManager.addHandler(await getTracingCallbackHandler(session), true);
|
|
359
|
+
}
|
|
330
360
|
}
|
|
331
361
|
}
|
|
332
362
|
return callbackManager;
|
|
@@ -73,14 +73,26 @@ class LLMChain extends base_js_1.BaseChain {
|
|
|
73
73
|
}
|
|
74
74
|
return finalCompletion;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Run the core logic of this chain and add to output if desired.
|
|
78
|
+
*
|
|
79
|
+
* Wraps _call and handles memory.
|
|
80
|
+
*/
|
|
81
|
+
call(values, callbacks) {
|
|
82
|
+
return super.call(values, callbacks);
|
|
83
|
+
}
|
|
76
84
|
/** @ignore */
|
|
77
85
|
async _call(values, runManager) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
86
|
+
const valuesForPrompt = { ...values };
|
|
87
|
+
const valuesForLLM = {};
|
|
88
|
+
for (const key of this.llm.callKeys) {
|
|
89
|
+
if (key in values) {
|
|
90
|
+
valuesForLLM[key] = values[key];
|
|
91
|
+
delete valuesForPrompt[key];
|
|
92
|
+
}
|
|
81
93
|
}
|
|
82
|
-
const promptValue = await this.prompt.formatPromptValue(
|
|
83
|
-
const { generations } = await this.llm.generatePrompt([promptValue],
|
|
94
|
+
const promptValue = await this.prompt.formatPromptValue(valuesForPrompt);
|
|
95
|
+
const { generations } = await this.llm.generatePrompt([promptValue], valuesForLLM, runManager?.getChild());
|
|
84
96
|
return {
|
|
85
97
|
[this.outputKey]: await this._getFinalOutput(generations[0], promptValue, runManager),
|
|
86
98
|
};
|
|
@@ -5,7 +5,7 @@ import { ChainValues, Generation, BasePromptValue } from "../schema/index.js";
|
|
|
5
5
|
import { BaseOutputParser } from "../schema/output_parser.js";
|
|
6
6
|
import { SerializedLLMChain } from "./serde.js";
|
|
7
7
|
import { CallbackManager } from "../callbacks/index.js";
|
|
8
|
-
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
8
|
+
import { CallbackManagerForChainRun, Callbacks } from "../callbacks/manager.js";
|
|
9
9
|
export interface LLMChainInput<T extends string | object = string> extends ChainInputs {
|
|
10
10
|
/** Prompt object to use */
|
|
11
11
|
prompt: BasePromptTemplate;
|
|
@@ -39,8 +39,14 @@ export declare class LLMChain<T extends string | object = string> extends BaseCh
|
|
|
39
39
|
constructor(fields: LLMChainInput<T>);
|
|
40
40
|
/** @ignore */
|
|
41
41
|
_getFinalOutput(generations: Generation[], promptValue: BasePromptValue, runManager?: CallbackManagerForChainRun): Promise<unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* Run the core logic of this chain and add to output if desired.
|
|
44
|
+
*
|
|
45
|
+
* Wraps _call and handles memory.
|
|
46
|
+
*/
|
|
47
|
+
call(values: ChainValues & this["llm"]["CallOptions"], callbacks?: Callbacks | undefined): Promise<ChainValues>;
|
|
42
48
|
/** @ignore */
|
|
43
|
-
_call(values: ChainValues, runManager?: CallbackManagerForChainRun): Promise<ChainValues>;
|
|
49
|
+
_call(values: ChainValues & this["llm"]["CallOptions"], runManager?: CallbackManagerForChainRun): Promise<ChainValues>;
|
|
44
50
|
/**
|
|
45
51
|
* Format prompt with values and pass to LLM
|
|
46
52
|
*
|
|
@@ -53,7 +59,7 @@ export declare class LLMChain<T extends string | object = string> extends BaseCh
|
|
|
53
59
|
* llm.predict({ adjective: "funny" })
|
|
54
60
|
* ```
|
|
55
61
|
*/
|
|
56
|
-
predict(values: ChainValues, callbackManager?: CallbackManager): Promise<T>;
|
|
62
|
+
predict(values: ChainValues & this["llm"]["CallOptions"], callbackManager?: CallbackManager): Promise<T>;
|
|
57
63
|
_chainType(): "llm_chain";
|
|
58
64
|
static deserialize(data: SerializedLLMChain): Promise<LLMChain<string>>;
|
|
59
65
|
serialize(): SerializedLLMChain;
|
package/dist/chains/llm_chain.js
CHANGED
|
@@ -70,14 +70,26 @@ export class LLMChain extends BaseChain {
|
|
|
70
70
|
}
|
|
71
71
|
return finalCompletion;
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Run the core logic of this chain and add to output if desired.
|
|
75
|
+
*
|
|
76
|
+
* Wraps _call and handles memory.
|
|
77
|
+
*/
|
|
78
|
+
call(values, callbacks) {
|
|
79
|
+
return super.call(values, callbacks);
|
|
80
|
+
}
|
|
73
81
|
/** @ignore */
|
|
74
82
|
async _call(values, runManager) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
const valuesForPrompt = { ...values };
|
|
84
|
+
const valuesForLLM = {};
|
|
85
|
+
for (const key of this.llm.callKeys) {
|
|
86
|
+
if (key in values) {
|
|
87
|
+
valuesForLLM[key] = values[key];
|
|
88
|
+
delete valuesForPrompt[key];
|
|
89
|
+
}
|
|
78
90
|
}
|
|
79
|
-
const promptValue = await this.prompt.formatPromptValue(
|
|
80
|
-
const { generations } = await this.llm.generatePrompt([promptValue],
|
|
91
|
+
const promptValue = await this.prompt.formatPromptValue(valuesForPrompt);
|
|
92
|
+
const { generations } = await this.llm.generatePrompt([promptValue], valuesForLLM, runManager?.getChild());
|
|
81
93
|
return {
|
|
82
94
|
[this.outputKey]: await this._getFinalOutput(generations[0], promptValue, runManager),
|
|
83
95
|
};
|
|
@@ -4,7 +4,7 @@ exports.COMBINE_PROMPT_SELECTOR = exports.COMBINE_PROMPT = exports.COMBINE_QA_PR
|
|
|
4
4
|
/* eslint-disable spaced-comment */
|
|
5
5
|
const prompt_js_1 = require("../../prompts/prompt.cjs");
|
|
6
6
|
const chat_js_1 = require("../../prompts/chat.cjs");
|
|
7
|
-
const
|
|
7
|
+
const conditional_js_1 = require("../../prompts/selectors/conditional.cjs");
|
|
8
8
|
const qa_template = `Use the following portion of a long document to see if any of the text is relevant to answer the question.
|
|
9
9
|
Return any relevant text verbatim.
|
|
10
10
|
{context}
|
|
@@ -24,8 +24,8 @@ const messages = [
|
|
|
24
24
|
const CHAT_QA_PROMPT =
|
|
25
25
|
/*#__PURE__*/ chat_js_1.ChatPromptTemplate.fromPromptMessages(messages);
|
|
26
26
|
exports.COMBINE_QA_PROMPT_SELECTOR =
|
|
27
|
-
/*#__PURE__*/ new
|
|
28
|
-
[
|
|
27
|
+
/*#__PURE__*/ new conditional_js_1.ConditionalPromptSelector(exports.DEFAULT_COMBINE_QA_PROMPT, [
|
|
28
|
+
[conditional_js_1.isChatModel, CHAT_QA_PROMPT],
|
|
29
29
|
]);
|
|
30
30
|
const combine_prompt = `Given the following extracted parts of a long document and a question, create a final answer.
|
|
31
31
|
If you don't know the answer, just say that you don't know. Don't try to make up an answer.
|
|
@@ -70,6 +70,6 @@ const combine_messages = [
|
|
|
70
70
|
const CHAT_COMBINE_PROMPT =
|
|
71
71
|
/*#__PURE__*/ chat_js_1.ChatPromptTemplate.fromPromptMessages(combine_messages);
|
|
72
72
|
exports.COMBINE_PROMPT_SELECTOR =
|
|
73
|
-
/*#__PURE__*/ new
|
|
74
|
-
[
|
|
73
|
+
/*#__PURE__*/ new conditional_js_1.ConditionalPromptSelector(exports.COMBINE_PROMPT, [
|
|
74
|
+
[conditional_js_1.isChatModel, CHAT_COMBINE_PROMPT],
|
|
75
75
|
]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PromptTemplate } from "../../prompts/prompt.js";
|
|
2
|
-
import { ConditionalPromptSelector } from "
|
|
2
|
+
import { ConditionalPromptSelector } from "../../prompts/selectors/conditional.js";
|
|
3
3
|
export declare const DEFAULT_COMBINE_QA_PROMPT: PromptTemplate;
|
|
4
4
|
export declare const COMBINE_QA_PROMPT_SELECTOR: ConditionalPromptSelector;
|
|
5
5
|
export declare const COMBINE_PROMPT: PromptTemplate;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable spaced-comment */
|
|
2
2
|
import { PromptTemplate } from "../../prompts/prompt.js";
|
|
3
3
|
import { ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, } from "../../prompts/chat.js";
|
|
4
|
-
import { ConditionalPromptSelector, isChatModel } from "
|
|
4
|
+
import { ConditionalPromptSelector, isChatModel, } from "../../prompts/selectors/conditional.js";
|
|
5
5
|
const qa_template = `Use the following portion of a long document to see if any of the text is relevant to answer the question.
|
|
6
6
|
Return any relevant text verbatim.
|
|
7
7
|
{context}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.QUESTION_PROMPT_SELECTOR = exports.CHAT_QUESTION_PROMPT = exports.DEFAULT_TEXT_QA_PROMPT = exports.DEFAULT_TEXT_QA_PROMPT_TMPL = exports.REFINE_PROMPT_SELECTOR = exports.CHAT_REFINE_PROMPT = exports.DEFAULT_REFINE_PROMPT = exports.DEFAULT_REFINE_PROMPT_TMPL = void 0;
|
|
4
4
|
/* eslint-disable spaced-comment */
|
|
5
5
|
const index_js_1 = require("../../prompts/index.cjs");
|
|
6
|
-
const
|
|
6
|
+
const conditional_js_1 = require("../../prompts/selectors/conditional.cjs");
|
|
7
7
|
exports.DEFAULT_REFINE_PROMPT_TMPL = `The original question is as follows: {question}
|
|
8
8
|
We have provided an existing answer: {existing_answer}
|
|
9
9
|
We have the opportunity to refine the existing answer
|
|
@@ -34,8 +34,8 @@ const messages = [
|
|
|
34
34
|
exports.CHAT_REFINE_PROMPT =
|
|
35
35
|
/*#__PURE__*/ index_js_1.ChatPromptTemplate.fromPromptMessages(messages);
|
|
36
36
|
exports.REFINE_PROMPT_SELECTOR =
|
|
37
|
-
/*#__PURE__*/ new
|
|
38
|
-
[
|
|
37
|
+
/*#__PURE__*/ new conditional_js_1.ConditionalPromptSelector(exports.DEFAULT_REFINE_PROMPT, [
|
|
38
|
+
[conditional_js_1.isChatModel, exports.CHAT_REFINE_PROMPT],
|
|
39
39
|
]);
|
|
40
40
|
exports.DEFAULT_TEXT_QA_PROMPT_TMPL = `Context information is below.
|
|
41
41
|
---------------------
|
|
@@ -58,6 +58,6 @@ const chat_messages = [
|
|
|
58
58
|
exports.CHAT_QUESTION_PROMPT =
|
|
59
59
|
/*#__PURE__*/ index_js_1.ChatPromptTemplate.fromPromptMessages(chat_messages);
|
|
60
60
|
exports.QUESTION_PROMPT_SELECTOR =
|
|
61
|
-
/*#__PURE__*/ new
|
|
62
|
-
[
|
|
61
|
+
/*#__PURE__*/ new conditional_js_1.ConditionalPromptSelector(exports.DEFAULT_TEXT_QA_PROMPT, [
|
|
62
|
+
[conditional_js_1.isChatModel, exports.CHAT_QUESTION_PROMPT],
|
|
63
63
|
]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PromptTemplate, ChatPromptTemplate } from "../../prompts/index.js";
|
|
2
|
-
import { ConditionalPromptSelector } from "
|
|
2
|
+
import { ConditionalPromptSelector } from "../../prompts/selectors/conditional.js";
|
|
3
3
|
export declare const DEFAULT_REFINE_PROMPT_TMPL = "The original question is as follows: {question}\nWe have provided an existing answer: {existing_answer}\nWe have the opportunity to refine the existing answer\n(only if needed) with some more context below.\n------------\n{context}\n------------\nGiven the new context, refine the original answer to better answer the question. \nIf the context isn't useful, return the original answer.";
|
|
4
4
|
export declare const DEFAULT_REFINE_PROMPT: PromptTemplate;
|
|
5
5
|
export declare const CHAT_REFINE_PROMPT: ChatPromptTemplate;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable spaced-comment */
|
|
2
2
|
import { PromptTemplate, ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, AIMessagePromptTemplate, } from "../../prompts/index.js";
|
|
3
|
-
import { ConditionalPromptSelector, isChatModel } from "
|
|
3
|
+
import { ConditionalPromptSelector, isChatModel, } from "../../prompts/selectors/conditional.js";
|
|
4
4
|
export const DEFAULT_REFINE_PROMPT_TMPL = `The original question is as follows: {question}
|
|
5
5
|
We have provided an existing answer: {existing_answer}
|
|
6
6
|
We have the opportunity to refine the existing answer
|
|
@@ -4,7 +4,7 @@ exports.QA_PROMPT_SELECTOR = exports.DEFAULT_QA_PROMPT = void 0;
|
|
|
4
4
|
/* eslint-disable spaced-comment */
|
|
5
5
|
const prompt_js_1 = require("../../prompts/prompt.cjs");
|
|
6
6
|
const chat_js_1 = require("../../prompts/chat.cjs");
|
|
7
|
-
const
|
|
7
|
+
const conditional_js_1 = require("../../prompts/selectors/conditional.cjs");
|
|
8
8
|
exports.DEFAULT_QA_PROMPT = new prompt_js_1.PromptTemplate({
|
|
9
9
|
template: "Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n\n{context}\n\nQuestion: {question}\nHelpful Answer:",
|
|
10
10
|
inputVariables: ["context", "question"],
|
|
@@ -19,4 +19,4 @@ const messages = [
|
|
|
19
19
|
];
|
|
20
20
|
const CHAT_PROMPT =
|
|
21
21
|
/*#__PURE__*/ chat_js_1.ChatPromptTemplate.fromPromptMessages(messages);
|
|
22
|
-
exports.QA_PROMPT_SELECTOR = new
|
|
22
|
+
exports.QA_PROMPT_SELECTOR = new conditional_js_1.ConditionalPromptSelector(exports.DEFAULT_QA_PROMPT, [[conditional_js_1.isChatModel, CHAT_PROMPT]]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { PromptTemplate } from "../../prompts/prompt.js";
|
|
2
|
-
import { ConditionalPromptSelector } from "
|
|
2
|
+
import { ConditionalPromptSelector } from "../../prompts/selectors/conditional.js";
|
|
3
3
|
export declare const DEFAULT_QA_PROMPT: PromptTemplate;
|
|
4
4
|
export declare const QA_PROMPT_SELECTOR: ConditionalPromptSelector;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable spaced-comment */
|
|
2
2
|
import { PromptTemplate } from "../../prompts/prompt.js";
|
|
3
3
|
import { ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, } from "../../prompts/chat.js";
|
|
4
|
-
import { ConditionalPromptSelector, isChatModel } from "
|
|
4
|
+
import { ConditionalPromptSelector, isChatModel, } from "../../prompts/selectors/conditional.js";
|
|
5
5
|
export const DEFAULT_QA_PROMPT = /*#__PURE__*/ new PromptTemplate({
|
|
6
6
|
template: "Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n\n{context}\n\nQuestion: {question}\nHelpful Answer:",
|
|
7
7
|
inputVariables: ["context", "question"],
|
|
@@ -168,8 +168,8 @@ exports.SequentialChain = SequentialChain;
|
|
|
168
168
|
* Play Synopsis:
|
|
169
169
|
* {synopsis}
|
|
170
170
|
* Review from a New York Times play critic of the above play:`
|
|
171
|
-
* const
|
|
172
|
-
* const reviewChain = new LLMChain({ llm: reviewLLM, prompt:
|
|
171
|
+
* const reviewPromptTemplate = new PromptTemplate({ template: reviewTemplate, inputVariables: ["synopsis"] });
|
|
172
|
+
* const reviewChain = new LLMChain({ llm: reviewLLM, prompt: reviewPromptTemplate });
|
|
173
173
|
*
|
|
174
174
|
* const overallChain = new SimpleSequentialChain({chains: [synopsisChain, reviewChain], verbose:true})
|
|
175
175
|
* const review = await overallChain.run("Tragedy at sunset on the beach")
|
|
@@ -65,8 +65,8 @@ export interface SimpleSequentialChainInput extends ChainInputs {
|
|
|
65
65
|
* Play Synopsis:
|
|
66
66
|
* {synopsis}
|
|
67
67
|
* Review from a New York Times play critic of the above play:`
|
|
68
|
-
* const
|
|
69
|
-
* const reviewChain = new LLMChain({ llm: reviewLLM, prompt:
|
|
68
|
+
* const reviewPromptTemplate = new PromptTemplate({ template: reviewTemplate, inputVariables: ["synopsis"] });
|
|
69
|
+
* const reviewChain = new LLMChain({ llm: reviewLLM, prompt: reviewPromptTemplate });
|
|
70
70
|
*
|
|
71
71
|
* const overallChain = new SimpleSequentialChain({chains: [synopsisChain, reviewChain], verbose:true})
|
|
72
72
|
* const review = await overallChain.run("Tragedy at sunset on the beach")
|
|
@@ -164,8 +164,8 @@ export class SequentialChain extends BaseChain {
|
|
|
164
164
|
* Play Synopsis:
|
|
165
165
|
* {synopsis}
|
|
166
166
|
* Review from a New York Times play critic of the above play:`
|
|
167
|
-
* const
|
|
168
|
-
* const reviewChain = new LLMChain({ llm: reviewLLM, prompt:
|
|
167
|
+
* const reviewPromptTemplate = new PromptTemplate({ template: reviewTemplate, inputVariables: ["synopsis"] });
|
|
168
|
+
* const reviewChain = new LLMChain({ llm: reviewLLM, prompt: reviewPromptTemplate });
|
|
169
169
|
*
|
|
170
170
|
* const overallChain = new SimpleSequentialChain({chains: [synopsisChain, reviewChain], verbose:true})
|
|
171
171
|
* const review = await overallChain.run("Tragedy at sunset on the beach")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SQL_MYSQL_PROMPT = exports.SQL_SQLITE_PROMPT = exports.SQL_POSTGRES_PROMPT = exports.DEFAULT_SQL_DATABASE_PROMPT = void 0;
|
|
3
|
+
exports.SQL_MSSQL_PROMPT = exports.SQL_MYSQL_PROMPT = exports.SQL_SQLITE_PROMPT = exports.SQL_POSTGRES_PROMPT = exports.DEFAULT_SQL_DATABASE_PROMPT = void 0;
|
|
4
4
|
/* eslint-disable spaced-comment */
|
|
5
5
|
const prompt_js_1 = require("../../prompts/prompt.cjs");
|
|
6
6
|
exports.DEFAULT_SQL_DATABASE_PROMPT = new prompt_js_1.PromptTemplate({
|
|
@@ -81,3 +81,22 @@ Only use the following tables:
|
|
|
81
81
|
Question: {input}`,
|
|
82
82
|
inputVariables: ["dialect", "table_info", "input", "top_k"],
|
|
83
83
|
});
|
|
84
|
+
exports.SQL_MSSQL_PROMPT = new prompt_js_1.PromptTemplate({
|
|
85
|
+
template: `You are an MS SQL expert. Given an input question, first create a syntactically correct MS SQL query to run, then look at the results of the query and return the answer to the input question.
|
|
86
|
+
Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the TOP clause as per MS SQL. You can order the results to return the most informative data in the database.
|
|
87
|
+
Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in square brackets ([]) to denote them as delimited identifiers.
|
|
88
|
+
Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
|
|
89
|
+
|
|
90
|
+
Use the following format:
|
|
91
|
+
|
|
92
|
+
Question: "Question here"
|
|
93
|
+
SQLQuery: "SQL Query to run"
|
|
94
|
+
SQLResult: "Result of the SQLQuery"
|
|
95
|
+
Answer: "Final answer here"
|
|
96
|
+
|
|
97
|
+
Only use the following tables:
|
|
98
|
+
{table_info}
|
|
99
|
+
|
|
100
|
+
Question: {input}`,
|
|
101
|
+
inputVariables: ["dialect", "table_info", "input", "top_k"],
|
|
102
|
+
});
|
|
@@ -3,3 +3,4 @@ export declare const DEFAULT_SQL_DATABASE_PROMPT: PromptTemplate;
|
|
|
3
3
|
export declare const SQL_POSTGRES_PROMPT: PromptTemplate;
|
|
4
4
|
export declare const SQL_SQLITE_PROMPT: PromptTemplate;
|
|
5
5
|
export declare const SQL_MYSQL_PROMPT: PromptTemplate;
|
|
6
|
+
export declare const SQL_MSSQL_PROMPT: PromptTemplate;
|
|
@@ -78,3 +78,22 @@ Only use the following tables:
|
|
|
78
78
|
Question: {input}`,
|
|
79
79
|
inputVariables: ["dialect", "table_info", "input", "top_k"],
|
|
80
80
|
});
|
|
81
|
+
export const SQL_MSSQL_PROMPT = /*#__PURE__*/ new PromptTemplate({
|
|
82
|
+
template: `You are an MS SQL expert. Given an input question, first create a syntactically correct MS SQL query to run, then look at the results of the query and return the answer to the input question.
|
|
83
|
+
Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the TOP clause as per MS SQL. You can order the results to return the most informative data in the database.
|
|
84
|
+
Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in square brackets ([]) to denote them as delimited identifiers.
|
|
85
|
+
Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
|
|
86
|
+
|
|
87
|
+
Use the following format:
|
|
88
|
+
|
|
89
|
+
Question: "Question here"
|
|
90
|
+
SQLQuery: "SQL Query to run"
|
|
91
|
+
SQLResult: "Result of the SQLQuery"
|
|
92
|
+
Answer: "Final answer here"
|
|
93
|
+
|
|
94
|
+
Only use the following tables:
|
|
95
|
+
{table_info}
|
|
96
|
+
|
|
97
|
+
Question: {input}`,
|
|
98
|
+
inputVariables: ["dialect", "table_info", "input", "top_k"],
|
|
99
|
+
});
|
|
@@ -6,39 +6,48 @@ const combine_docs_chain_js_1 = require("../combine_docs_chain.cjs");
|
|
|
6
6
|
const stuff_prompts_js_1 = require("./stuff_prompts.cjs");
|
|
7
7
|
const refine_prompts_js_1 = require("./refine_prompts.cjs");
|
|
8
8
|
const loadSummarizationChain = (llm, params = { type: "map_reduce" }) => {
|
|
9
|
+
const { verbose } = params;
|
|
9
10
|
if (params.type === "stuff") {
|
|
10
11
|
const { prompt = stuff_prompts_js_1.DEFAULT_PROMPT } = params;
|
|
11
|
-
const llmChain = new llm_chain_js_1.LLMChain({ prompt, llm });
|
|
12
|
+
const llmChain = new llm_chain_js_1.LLMChain({ prompt, llm, verbose });
|
|
12
13
|
const chain = new combine_docs_chain_js_1.StuffDocumentsChain({
|
|
13
14
|
llmChain,
|
|
14
15
|
documentVariableName: "text",
|
|
16
|
+
verbose,
|
|
15
17
|
});
|
|
16
18
|
return chain;
|
|
17
19
|
}
|
|
18
20
|
if (params.type === "map_reduce") {
|
|
19
21
|
const { combineMapPrompt = stuff_prompts_js_1.DEFAULT_PROMPT, combinePrompt = stuff_prompts_js_1.DEFAULT_PROMPT, returnIntermediateSteps, } = params;
|
|
20
|
-
const llmChain = new llm_chain_js_1.LLMChain({ prompt: combineMapPrompt, llm });
|
|
21
|
-
const combineLLMChain = new llm_chain_js_1.LLMChain({
|
|
22
|
+
const llmChain = new llm_chain_js_1.LLMChain({ prompt: combineMapPrompt, llm, verbose });
|
|
23
|
+
const combineLLMChain = new llm_chain_js_1.LLMChain({
|
|
24
|
+
prompt: combinePrompt,
|
|
25
|
+
llm,
|
|
26
|
+
verbose,
|
|
27
|
+
});
|
|
22
28
|
const combineDocumentChain = new combine_docs_chain_js_1.StuffDocumentsChain({
|
|
23
29
|
llmChain: combineLLMChain,
|
|
24
30
|
documentVariableName: "text",
|
|
31
|
+
verbose,
|
|
25
32
|
});
|
|
26
33
|
const chain = new combine_docs_chain_js_1.MapReduceDocumentsChain({
|
|
27
34
|
llmChain,
|
|
28
35
|
combineDocumentChain,
|
|
29
36
|
documentVariableName: "text",
|
|
30
37
|
returnIntermediateSteps,
|
|
38
|
+
verbose,
|
|
31
39
|
});
|
|
32
40
|
return chain;
|
|
33
41
|
}
|
|
34
42
|
if (params.type === "refine") {
|
|
35
43
|
const { refinePrompt = refine_prompts_js_1.REFINE_PROMPT, questionPrompt = stuff_prompts_js_1.DEFAULT_PROMPT } = params;
|
|
36
|
-
const llmChain = new llm_chain_js_1.LLMChain({ prompt: questionPrompt, llm });
|
|
37
|
-
const refineLLMChain = new llm_chain_js_1.LLMChain({ prompt: refinePrompt, llm });
|
|
44
|
+
const llmChain = new llm_chain_js_1.LLMChain({ prompt: questionPrompt, llm, verbose });
|
|
45
|
+
const refineLLMChain = new llm_chain_js_1.LLMChain({ prompt: refinePrompt, llm, verbose });
|
|
38
46
|
const chain = new combine_docs_chain_js_1.RefineDocumentsChain({
|
|
39
47
|
llmChain,
|
|
40
48
|
refineLLMChain,
|
|
41
49
|
documentVariableName: "text",
|
|
50
|
+
verbose,
|
|
42
51
|
});
|
|
43
52
|
return chain;
|
|
44
53
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { BaseLanguageModel } from "../../base_language/index.js";
|
|
2
2
|
import { BasePromptTemplate } from "../../prompts/base.js";
|
|
3
3
|
import { StuffDocumentsChain, MapReduceDocumentsChain, RefineDocumentsChain, MapReduceDocumentsChainInput } from "../combine_docs_chain.js";
|
|
4
|
-
|
|
4
|
+
type BaseParams = {
|
|
5
|
+
verbose?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/** @interface */
|
|
8
|
+
export type SummarizationChainParams = BaseParams & ({
|
|
5
9
|
type?: "stuff";
|
|
6
10
|
prompt?: BasePromptTemplate;
|
|
7
11
|
} | ({
|
|
@@ -12,5 +16,6 @@ export type SummarizationChainParams = {
|
|
|
12
16
|
type?: "refine";
|
|
13
17
|
refinePrompt?: BasePromptTemplate;
|
|
14
18
|
questionPrompt?: BasePromptTemplate;
|
|
15
|
-
};
|
|
19
|
+
});
|
|
16
20
|
export declare const loadSummarizationChain: (llm: BaseLanguageModel, params?: SummarizationChainParams) => StuffDocumentsChain | MapReduceDocumentsChain | RefineDocumentsChain;
|
|
21
|
+
export {};
|