langchain 0.0.61 → 0.0.63
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/base_language/count_tokens.cjs +16 -1
- package/dist/base_language/count_tokens.d.ts +1 -0
- package/dist/base_language/count_tokens.js +14 -0
- package/dist/callbacks/handlers/tracers.cjs +3 -3
- package/dist/callbacks/handlers/tracers.js +3 -3
- package/dist/callbacks/manager.cjs +1 -1
- package/dist/callbacks/manager.js +1 -1
- package/dist/chains/base.cjs +3 -2
- package/dist/chains/base.js +3 -2
- package/dist/chains/question_answering/map_reduce_prompts.cjs +0 -1
- package/dist/chains/question_answering/map_reduce_prompts.js +0 -1
- package/dist/chains/question_answering/refine_prompts.cjs +0 -1
- package/dist/chains/question_answering/refine_prompts.js +0 -1
- package/dist/chains/question_answering/stuff_prompts.cjs +0 -1
- package/dist/chains/question_answering/stuff_prompts.js +0 -1
- package/dist/chains/sql_db/sql_db_prompt.cjs +0 -1
- package/dist/chains/sql_db/sql_db_prompt.js +0 -1
- package/dist/chains/summarization/stuff_prompts.cjs +0 -1
- package/dist/chains/summarization/stuff_prompts.js +0 -1
- package/dist/chat_models/anthropic.cjs +1 -1
- package/dist/chat_models/anthropic.js +1 -1
- package/dist/chat_models/base.cjs +1 -0
- package/dist/chat_models/base.js +1 -0
- package/dist/chat_models/index.cjs +0 -1
- package/dist/chat_models/index.js +0 -1
- package/dist/chat_models/openai.cjs +4 -2
- package/dist/chat_models/openai.js +4 -2
- package/dist/document_loaders/index.cjs +0 -1
- package/dist/document_loaders/index.js +0 -1
- package/dist/document_loaders/web/github.cjs +1 -1
- package/dist/document_loaders/web/github.js +1 -1
- package/dist/embeddings/cohere.cjs +4 -2
- package/dist/embeddings/cohere.js +4 -2
- package/dist/embeddings/index.cjs +0 -1
- package/dist/embeddings/index.js +0 -1
- package/dist/experimental/autogpt/agent.cjs +19 -4
- package/dist/experimental/autogpt/agent.d.ts +2 -0
- package/dist/experimental/autogpt/agent.js +19 -4
- package/dist/experimental/autogpt/prompt_generator.cjs +1 -1
- package/dist/experimental/autogpt/prompt_generator.js +1 -1
- package/dist/index.cjs +0 -1
- package/dist/index.js +0 -1
- package/dist/llms/base.cjs +1 -0
- package/dist/llms/base.js +1 -0
- package/dist/llms/cohere.cjs +1 -1
- package/dist/llms/cohere.js +1 -1
- package/dist/llms/hf.cjs +1 -1
- package/dist/llms/hf.js +1 -1
- package/dist/llms/index.cjs +0 -1
- package/dist/llms/index.js +0 -1
- package/dist/llms/openai.cjs +5 -3
- package/dist/llms/openai.js +5 -3
- package/dist/llms/replicate.cjs +1 -1
- package/dist/llms/replicate.js +1 -1
- package/dist/memory/prompt.cjs +0 -1
- package/dist/memory/prompt.js +0 -1
- package/dist/output_parsers/prompts.cjs +0 -1
- package/dist/output_parsers/prompts.js +0 -1
- package/dist/retrievers/contextual_compression.cjs +29 -0
- package/dist/retrievers/contextual_compression.d.ts +13 -0
- package/dist/retrievers/contextual_compression.js +25 -0
- package/dist/retrievers/document_compressors/index.cjs +9 -0
- package/dist/retrievers/document_compressors/index.d.ts +7 -0
- package/dist/retrievers/document_compressors/index.js +5 -0
- package/dist/retrievers/index.cjs +0 -1
- package/dist/retrievers/index.js +0 -1
- package/dist/tools/base.cjs +4 -6
- package/dist/tools/base.d.ts +6 -6
- package/dist/tools/base.js +4 -6
- package/dist/tools/bingserpapi.cjs +1 -1
- package/dist/tools/bingserpapi.js +1 -1
- package/dist/tools/chain.cjs +7 -31
- package/dist/tools/chain.d.ts +3 -10
- package/dist/tools/chain.js +7 -31
- package/dist/tools/dynamic.cjs +2 -2
- package/dist/tools/dynamic.d.ts +3 -3
- package/dist/tools/dynamic.js +2 -2
- package/dist/tools/fs.cjs +5 -10
- package/dist/tools/fs.js +5 -10
- package/dist/tools/serpapi.cjs +1 -1
- package/dist/tools/serpapi.js +1 -1
- package/dist/tools/serper.cjs +1 -1
- package/dist/tools/serper.js +1 -1
- package/dist/tools/zapier.cjs +1 -1
- package/dist/tools/zapier.js +1 -1
- package/dist/util/hub.cjs +2 -2
- package/dist/util/hub.js +2 -2
- package/dist/vectorstores/chroma.cjs +25 -27
- package/dist/vectorstores/chroma.d.ts +8 -4
- package/dist/vectorstores/chroma.js +25 -27
- package/dist/vectorstores/index.cjs +0 -1
- package/dist/vectorstores/index.js +0 -1
- package/dist/vectorstores/milvus.cjs +1 -1
- package/dist/vectorstores/milvus.js +1 -1
- package/package.json +19 -3
- package/retrievers/contextual_compression.cjs +1 -0
- package/retrievers/contextual_compression.d.ts +1 -0
- package/retrievers/contextual_compression.js +1 -0
- package/retrievers/document_compressors.cjs +1 -0
- package/retrievers/document_compressors.d.ts +1 -0
- package/retrievers/document_compressors.js +1 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateMaxTokens = exports.importTiktoken = exports.getModelContextSize = exports.getModelNameForTiktoken = void 0;
|
|
3
|
+
exports.calculateMaxTokens = exports.importTiktoken = exports.getModelContextSize = exports.getEmbeddingContextSize = exports.getModelNameForTiktoken = void 0;
|
|
4
4
|
// https://www.npmjs.com/package/@dqbd/tiktoken
|
|
5
5
|
const getModelNameForTiktoken = (modelName) => {
|
|
6
6
|
if (modelName.startsWith("gpt-3.5-turbo-")) {
|
|
@@ -15,8 +15,23 @@ const getModelNameForTiktoken = (modelName) => {
|
|
|
15
15
|
return modelName;
|
|
16
16
|
};
|
|
17
17
|
exports.getModelNameForTiktoken = getModelNameForTiktoken;
|
|
18
|
+
const getEmbeddingContextSize = (modelName) => {
|
|
19
|
+
switch (modelName) {
|
|
20
|
+
case "text-embedding-ada-002":
|
|
21
|
+
return 8191;
|
|
22
|
+
default:
|
|
23
|
+
return 2046;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.getEmbeddingContextSize = getEmbeddingContextSize;
|
|
18
27
|
const getModelContextSize = (modelName) => {
|
|
19
28
|
switch ((0, exports.getModelNameForTiktoken)(modelName)) {
|
|
29
|
+
case "gpt-3.5-turbo":
|
|
30
|
+
return 4096;
|
|
31
|
+
case "gpt-4-32k":
|
|
32
|
+
return 32768;
|
|
33
|
+
case "gpt-4":
|
|
34
|
+
return 8192;
|
|
20
35
|
case "text-davinci-003":
|
|
21
36
|
return 4097;
|
|
22
37
|
case "text-curie-001":
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TiktokenModel } from "@dqbd/tiktoken";
|
|
2
2
|
export declare const getModelNameForTiktoken: (modelName: string) => TiktokenModel;
|
|
3
|
+
export declare const getEmbeddingContextSize: (modelName?: string) => number;
|
|
3
4
|
export declare const getModelContextSize: (modelName: string) => number;
|
|
4
5
|
interface CalculateMaxTokenProps {
|
|
5
6
|
prompt: string;
|
|
@@ -11,8 +11,22 @@ export const getModelNameForTiktoken = (modelName) => {
|
|
|
11
11
|
}
|
|
12
12
|
return modelName;
|
|
13
13
|
};
|
|
14
|
+
export const getEmbeddingContextSize = (modelName) => {
|
|
15
|
+
switch (modelName) {
|
|
16
|
+
case "text-embedding-ada-002":
|
|
17
|
+
return 8191;
|
|
18
|
+
default:
|
|
19
|
+
return 2046;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
14
22
|
export const getModelContextSize = (modelName) => {
|
|
15
23
|
switch (getModelNameForTiktoken(modelName)) {
|
|
24
|
+
case "gpt-3.5-turbo":
|
|
25
|
+
return 4096;
|
|
26
|
+
case "gpt-4-32k":
|
|
27
|
+
return 32768;
|
|
28
|
+
case "gpt-4":
|
|
29
|
+
return 8192;
|
|
16
30
|
case "text-davinci-003":
|
|
17
31
|
return 4097;
|
|
18
32
|
case "text-curie-001":
|
|
@@ -207,7 +207,7 @@ class LangChainTracer extends BaseTracer {
|
|
|
207
207
|
writable: true,
|
|
208
208
|
value: (typeof process !== "undefined"
|
|
209
209
|
? // eslint-disable-next-line no-process-env
|
|
210
|
-
process.env
|
|
210
|
+
process.env?.LANGCHAIN_ENDPOINT
|
|
211
211
|
: undefined) || "http://localhost:8000"
|
|
212
212
|
});
|
|
213
213
|
Object.defineProperty(this, "headers", {
|
|
@@ -219,9 +219,9 @@ class LangChainTracer extends BaseTracer {
|
|
|
219
219
|
}
|
|
220
220
|
});
|
|
221
221
|
// eslint-disable-next-line no-process-env
|
|
222
|
-
if (typeof process !== "undefined" && process.env
|
|
222
|
+
if (typeof process !== "undefined" && process.env?.LANGCHAIN_API_KEY) {
|
|
223
223
|
// eslint-disable-next-line no-process-env
|
|
224
|
-
this.headers["x-api-key"] = process.env
|
|
224
|
+
this.headers["x-api-key"] = process.env?.LANGCHAIN_API_KEY;
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
async persistRun(run) {
|
|
@@ -203,7 +203,7 @@ export class LangChainTracer extends BaseTracer {
|
|
|
203
203
|
writable: true,
|
|
204
204
|
value: (typeof process !== "undefined"
|
|
205
205
|
? // eslint-disable-next-line no-process-env
|
|
206
|
-
process.env
|
|
206
|
+
process.env?.LANGCHAIN_ENDPOINT
|
|
207
207
|
: undefined) || "http://localhost:8000"
|
|
208
208
|
});
|
|
209
209
|
Object.defineProperty(this, "headers", {
|
|
@@ -215,9 +215,9 @@ export class LangChainTracer extends BaseTracer {
|
|
|
215
215
|
}
|
|
216
216
|
});
|
|
217
217
|
// eslint-disable-next-line no-process-env
|
|
218
|
-
if (typeof process !== "undefined" && process.env
|
|
218
|
+
if (typeof process !== "undefined" && process.env?.LANGCHAIN_API_KEY) {
|
|
219
219
|
// eslint-disable-next-line no-process-env
|
|
220
|
-
this.headers["x-api-key"] = process.env
|
|
220
|
+
this.headers["x-api-key"] = process.env?.LANGCHAIN_API_KEY;
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
async persistRun(run) {
|
|
@@ -306,7 +306,7 @@ class CallbackManager extends BaseCallbackManager {
|
|
|
306
306
|
}
|
|
307
307
|
const tracingEnabled = typeof process !== "undefined"
|
|
308
308
|
? // eslint-disable-next-line no-process-env
|
|
309
|
-
process.env
|
|
309
|
+
process.env?.LANGCHAIN_TRACING !== undefined
|
|
310
310
|
: false;
|
|
311
311
|
if (options?.verbose || tracingEnabled) {
|
|
312
312
|
if (!callbackManager) {
|
|
@@ -299,7 +299,7 @@ export class CallbackManager extends BaseCallbackManager {
|
|
|
299
299
|
}
|
|
300
300
|
const tracingEnabled = typeof process !== "undefined"
|
|
301
301
|
? // eslint-disable-next-line no-process-env
|
|
302
|
-
process.env
|
|
302
|
+
process.env?.LANGCHAIN_TRACING !== undefined
|
|
303
303
|
: false;
|
|
304
304
|
if (options?.verbose || tracingEnabled) {
|
|
305
305
|
if (!callbackManager) {
|
package/dist/chains/base.cjs
CHANGED
|
@@ -21,11 +21,11 @@ class BaseChain extends index_js_2.BaseLangChain {
|
|
|
21
21
|
async run(
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
23
|
input, callbacks) {
|
|
24
|
-
const isKeylessInput = this.inputKeys.length
|
|
24
|
+
const isKeylessInput = this.inputKeys.length <= 1;
|
|
25
25
|
if (!isKeylessInput) {
|
|
26
26
|
throw new Error(`Chain ${this._chainType()} expects multiple inputs, cannot use 'run' `);
|
|
27
27
|
}
|
|
28
|
-
const values = { [this.inputKeys[0]]: input };
|
|
28
|
+
const values = this.inputKeys.length ? { [this.inputKeys[0]]: input } : {};
|
|
29
29
|
const returnValues = await this.call(values, callbacks);
|
|
30
30
|
const keys = Object.keys(returnValues);
|
|
31
31
|
if (keys.length === 1) {
|
|
@@ -63,6 +63,7 @@ class BaseChain extends index_js_2.BaseLangChain {
|
|
|
63
63
|
// add the runManager's currentRunId to the outputValues
|
|
64
64
|
Object.defineProperty(outputValues, index_js_1.RUN_KEY, {
|
|
65
65
|
value: runManager ? { runId: runManager?.runId } : undefined,
|
|
66
|
+
configurable: true,
|
|
66
67
|
});
|
|
67
68
|
return outputValues;
|
|
68
69
|
}
|
package/dist/chains/base.js
CHANGED
|
@@ -18,11 +18,11 @@ export class BaseChain extends BaseLangChain {
|
|
|
18
18
|
async run(
|
|
19
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
20
|
input, callbacks) {
|
|
21
|
-
const isKeylessInput = this.inputKeys.length
|
|
21
|
+
const isKeylessInput = this.inputKeys.length <= 1;
|
|
22
22
|
if (!isKeylessInput) {
|
|
23
23
|
throw new Error(`Chain ${this._chainType()} expects multiple inputs, cannot use 'run' `);
|
|
24
24
|
}
|
|
25
|
-
const values = { [this.inputKeys[0]]: input };
|
|
25
|
+
const values = this.inputKeys.length ? { [this.inputKeys[0]]: input } : {};
|
|
26
26
|
const returnValues = await this.call(values, callbacks);
|
|
27
27
|
const keys = Object.keys(returnValues);
|
|
28
28
|
if (keys.length === 1) {
|
|
@@ -60,6 +60,7 @@ export class BaseChain extends BaseLangChain {
|
|
|
60
60
|
// add the runManager's currentRunId to the outputValues
|
|
61
61
|
Object.defineProperty(outputValues, RUN_KEY, {
|
|
62
62
|
value: runManager ? { runId: runManager?.runId } : undefined,
|
|
63
|
+
configurable: true,
|
|
63
64
|
});
|
|
64
65
|
return outputValues;
|
|
65
66
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.COMBINE_PROMPT_SELECTOR = exports.COMBINE_PROMPT = exports.COMBINE_QA_PROMPT_SELECTOR = exports.DEFAULT_COMBINE_QA_PROMPT = void 0;
|
|
4
|
-
/* eslint-disable tree-shaking/no-side-effects-in-initialization */
|
|
5
4
|
/* eslint-disable spaced-comment */
|
|
6
5
|
const prompt_js_1 = require("../../prompts/prompt.cjs");
|
|
7
6
|
const chat_js_1 = require("../../prompts/chat.cjs");
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable tree-shaking/no-side-effects-in-initialization */
|
|
2
1
|
/* eslint-disable spaced-comment */
|
|
3
2
|
import { PromptTemplate } from "../../prompts/prompt.js";
|
|
4
3
|
import { ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, } from "../../prompts/chat.js";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
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
|
-
/* eslint-disable tree-shaking/no-side-effects-in-initialization */
|
|
5
4
|
/* eslint-disable spaced-comment */
|
|
6
5
|
const index_js_1 = require("../../prompts/index.cjs");
|
|
7
6
|
const prompt_selector_js_1 = require("../prompt_selector.cjs");
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable tree-shaking/no-side-effects-in-initialization */
|
|
2
1
|
/* eslint-disable spaced-comment */
|
|
3
2
|
import { PromptTemplate, ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, AIMessagePromptTemplate, } from "../../prompts/index.js";
|
|
4
3
|
import { ConditionalPromptSelector, isChatModel } from "../prompt_selector.js";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QA_PROMPT_SELECTOR = exports.DEFAULT_QA_PROMPT = void 0;
|
|
4
|
-
/* eslint-disable tree-shaking/no-side-effects-in-initialization */
|
|
5
4
|
/* eslint-disable spaced-comment */
|
|
6
5
|
const prompt_js_1 = require("../../prompts/prompt.cjs");
|
|
7
6
|
const chat_js_1 = require("../../prompts/chat.cjs");
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable tree-shaking/no-side-effects-in-initialization */
|
|
2
1
|
/* eslint-disable spaced-comment */
|
|
3
2
|
import { PromptTemplate } from "../../prompts/prompt.js";
|
|
4
3
|
import { ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, } from "../../prompts/chat.js";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_SQL_DATABASE_PROMPT = void 0;
|
|
4
|
-
/* eslint-disable tree-shaking/no-side-effects-in-initialization */
|
|
5
4
|
/* eslint-disable spaced-comment */
|
|
6
5
|
const prompt_js_1 = require("../../prompts/prompt.cjs");
|
|
7
6
|
exports.DEFAULT_SQL_DATABASE_PROMPT = new prompt_js_1.PromptTemplate({
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_PROMPT = void 0;
|
|
4
|
-
/* eslint-disable tree-shaking/no-side-effects-in-initialization */
|
|
5
4
|
/* eslint-disable spaced-comment */
|
|
6
5
|
const prompt_js_1 = require("../../prompts/prompt.cjs");
|
|
7
6
|
const template = `Write a concise summary of the following:
|
|
@@ -105,7 +105,7 @@ class ChatAnthropic extends base_js_1.BaseChatModel {
|
|
|
105
105
|
fields?.anthropicApiKey ??
|
|
106
106
|
(typeof process !== "undefined"
|
|
107
107
|
? // eslint-disable-next-line no-process-env
|
|
108
|
-
process.env
|
|
108
|
+
process.env?.ANTHROPIC_API_KEY
|
|
109
109
|
: undefined);
|
|
110
110
|
if (!this.apiKey) {
|
|
111
111
|
throw new Error("Anthropic API key not found");
|
|
@@ -102,7 +102,7 @@ export class ChatAnthropic extends BaseChatModel {
|
|
|
102
102
|
fields?.anthropicApiKey ??
|
|
103
103
|
(typeof process !== "undefined"
|
|
104
104
|
? // eslint-disable-next-line no-process-env
|
|
105
|
-
process.env
|
|
105
|
+
process.env?.ANTHROPIC_API_KEY
|
|
106
106
|
: undefined);
|
|
107
107
|
if (!this.apiKey) {
|
|
108
108
|
throw new Error("Anthropic API key not found");
|
|
@@ -37,6 +37,7 @@ class BaseChatModel extends index_js_2.BaseLanguageModel {
|
|
|
37
37
|
await runManager?.handleLLMEnd(output);
|
|
38
38
|
Object.defineProperty(output, index_js_1.RUN_KEY, {
|
|
39
39
|
value: runManager ? { runId: runManager?.runId } : undefined,
|
|
40
|
+
configurable: true,
|
|
40
41
|
});
|
|
41
42
|
return output;
|
|
42
43
|
}
|
package/dist/chat_models/base.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChatAnthropic = exports.ChatOpenAI = exports.SimpleChatModel = exports.BaseChatModel = void 0;
|
|
4
|
-
// eslint-disable-next-line tree-shaking/no-side-effects-in-initialization
|
|
5
4
|
/* #__PURE__ */ console.error("[WARN] Importing from 'langchain/chat_models' is deprecated. Import from eg. 'langchain/chat_models/openai' instead. See https://js.langchain.com/docs/getting-started/install#updating-from-0052 for upgrade instructions.");
|
|
6
5
|
var base_js_1 = require("./base.cjs");
|
|
7
6
|
Object.defineProperty(exports, "BaseChatModel", { enumerable: true, get: function () { return base_js_1.BaseChatModel; } });
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line tree-shaking/no-side-effects-in-initialization
|
|
2
1
|
/* #__PURE__ */ console.error("[WARN] Importing from 'langchain/chat_models' is deprecated. Import from eg. 'langchain/chat_models/openai' instead. See https://js.langchain.com/docs/getting-started/install#updating-from-0052 for upgrade instructions.");
|
|
3
2
|
export { BaseChatModel, SimpleChatModel } from "./base.js";
|
|
4
3
|
export { ChatOpenAI } from "./openai.js";
|
|
@@ -136,8 +136,10 @@ class ChatOpenAI extends base_js_1.BaseChatModel {
|
|
|
136
136
|
value: void 0
|
|
137
137
|
});
|
|
138
138
|
const apiKey = fields?.openAIApiKey ??
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
(typeof process !== "undefined"
|
|
140
|
+
? // eslint-disable-next-line no-process-env
|
|
141
|
+
process.env?.OPENAI_API_KEY
|
|
142
|
+
: undefined);
|
|
141
143
|
if (!apiKey) {
|
|
142
144
|
throw new Error("OpenAI API key not found");
|
|
143
145
|
}
|
|
@@ -130,8 +130,10 @@ export class ChatOpenAI extends BaseChatModel {
|
|
|
130
130
|
value: void 0
|
|
131
131
|
});
|
|
132
132
|
const apiKey = fields?.openAIApiKey ??
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
(typeof process !== "undefined"
|
|
134
|
+
? // eslint-disable-next-line no-process-env
|
|
135
|
+
process.env?.OPENAI_API_KEY
|
|
136
|
+
: undefined);
|
|
135
137
|
if (!apiKey) {
|
|
136
138
|
throw new Error("OpenAI API key not found");
|
|
137
139
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnstructuredLoader = exports.GithubRepoLoader = exports.NotionLoader = exports.CSVLoader = exports.JSONLinesLoader = exports.JSONLoader = exports.TextLoader = exports.EPubLoader = exports.DocxLoader = exports.PDFLoader = exports.SRTLoader = exports.UnknownHandling = exports.DirectoryLoader = exports.IMSDBLoader = exports.HNLoader = exports.GitbookLoader = exports.CollegeConfidentialLoader = exports.PuppeteerWebBaseLoader = exports.CheerioWebBaseLoader = exports.BaseDocumentLoader = void 0;
|
|
4
|
-
// eslint-disable-next-line tree-shaking/no-side-effects-in-initialization
|
|
5
4
|
/* #__PURE__ */ console.error("[WARN] Importing from 'langchain/document_loaders' is deprecated. Import from eg. 'langchain/document_loaders/fs/text' or 'langchain/document_loaders/web/cheerio' instead. See https://js.langchain.com/docs/getting-started/install#updating-from-0052 for upgrade instructions.");
|
|
6
5
|
var base_js_1 = require("./base.cjs");
|
|
7
6
|
Object.defineProperty(exports, "BaseDocumentLoader", { enumerable: true, get: function () { return base_js_1.BaseDocumentLoader; } });
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line tree-shaking/no-side-effects-in-initialization
|
|
2
1
|
/* #__PURE__ */ console.error("[WARN] Importing from 'langchain/document_loaders' is deprecated. Import from eg. 'langchain/document_loaders/fs/text' or 'langchain/document_loaders/web/cheerio' instead. See https://js.langchain.com/docs/getting-started/install#updating-from-0052 for upgrade instructions.");
|
|
3
2
|
export { BaseDocumentLoader } from "./base.js";
|
|
4
3
|
export { CheerioWebBaseLoader } from "./web/cheerio.js";
|
|
@@ -16,7 +16,7 @@ function isBinaryPath(name) {
|
|
|
16
16
|
class GithubRepoLoader extends base_js_1.BaseDocumentLoader {
|
|
17
17
|
constructor(githubUrl, { accessToken = typeof process !== "undefined"
|
|
18
18
|
? // eslint-disable-next-line no-process-env
|
|
19
|
-
process.env
|
|
19
|
+
process.env?.GITHUB_ACCESS_TOKEN
|
|
20
20
|
: undefined, branch = "main", recursive = true, unknown = directory_js_1.UnknownHandling.Warn, ignoreFiles = [], } = {}) {
|
|
21
21
|
super();
|
|
22
22
|
Object.defineProperty(this, "owner", {
|
|
@@ -10,7 +10,7 @@ function isBinaryPath(name) {
|
|
|
10
10
|
export class GithubRepoLoader extends BaseDocumentLoader {
|
|
11
11
|
constructor(githubUrl, { accessToken = typeof process !== "undefined"
|
|
12
12
|
? // eslint-disable-next-line no-process-env
|
|
13
|
-
process.env
|
|
13
|
+
process.env?.GITHUB_ACCESS_TOKEN
|
|
14
14
|
: undefined, branch = "main", recursive = true, unknown = UnknownHandling.Warn, ignoreFiles = [], } = {}) {
|
|
15
15
|
super();
|
|
16
16
|
Object.defineProperty(this, "owner", {
|
|
@@ -38,8 +38,10 @@ class CohereEmbeddings extends base_js_1.Embeddings {
|
|
|
38
38
|
value: void 0
|
|
39
39
|
});
|
|
40
40
|
const apiKey = fields?.apiKey ||
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
(typeof process !== "undefined"
|
|
42
|
+
? // eslint-disable-next-line no-process-env
|
|
43
|
+
process.env?.COHERE_API_KEY
|
|
44
|
+
: undefined);
|
|
43
45
|
if (!apiKey) {
|
|
44
46
|
throw new Error("Cohere API key not found");
|
|
45
47
|
}
|
|
@@ -35,8 +35,10 @@ export class CohereEmbeddings extends Embeddings {
|
|
|
35
35
|
value: void 0
|
|
36
36
|
});
|
|
37
37
|
const apiKey = fields?.apiKey ||
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
(typeof process !== "undefined"
|
|
39
|
+
? // eslint-disable-next-line no-process-env
|
|
40
|
+
process.env?.COHERE_API_KEY
|
|
41
|
+
: undefined);
|
|
40
42
|
if (!apiKey) {
|
|
41
43
|
throw new Error("Cohere API key not found");
|
|
42
44
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FakeEmbeddings = exports.Embeddings = exports.CohereEmbeddings = exports.OpenAIEmbeddings = void 0;
|
|
4
|
-
// eslint-disable-next-line tree-shaking/no-side-effects-in-initialization
|
|
5
4
|
/* #__PURE__ */ console.error("[WARN] Importing from 'langchain/embeddings' is deprecated. Import from eg. 'langchain/embeddings/openai' instead. See https://js.langchain.com/docs/getting-started/install#updating-from-0052 for upgrade instructions.");
|
|
6
5
|
var openai_js_1 = require("./openai.cjs");
|
|
7
6
|
Object.defineProperty(exports, "OpenAIEmbeddings", { enumerable: true, get: function () { return openai_js_1.OpenAIEmbeddings; } });
|
package/dist/embeddings/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line tree-shaking/no-side-effects-in-initialization
|
|
2
1
|
/* #__PURE__ */ console.error("[WARN] Importing from 'langchain/embeddings' is deprecated. Import from eg. 'langchain/embeddings/openai' instead. See https://js.langchain.com/docs/getting-started/install#updating-from-0052 for upgrade instructions.");
|
|
3
2
|
export { OpenAIEmbeddings } from "./openai.js";
|
|
4
3
|
export { CohereEmbeddings } from "./cohere.js";
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AutoGPT = void 0;
|
|
4
4
|
const llm_chain_js_1 = require("../../chains/llm_chain.cjs");
|
|
5
|
-
const document_js_1 = require("../../document.cjs");
|
|
6
5
|
const output_parser_js_1 = require("./output_parser.cjs");
|
|
7
6
|
const prompt_js_1 = require("./prompt.cjs");
|
|
8
7
|
const index_js_1 = require("../../schema/index.cjs");
|
|
9
8
|
// import { HumanInputRun } from "./tools/human/tool"; // TODO
|
|
10
9
|
const schema_js_1 = require("./schema.cjs");
|
|
10
|
+
const text_splitter_js_1 = require("../../text_splitter.cjs");
|
|
11
|
+
const count_tokens_js_1 = require("../../base_language/count_tokens.cjs");
|
|
11
12
|
class AutoGPT {
|
|
12
13
|
constructor({ aiName, memory, chain, outputParser, tools, feedbackTool, maxIterations, }) {
|
|
13
14
|
Object.defineProperty(this, "aiName", {
|
|
@@ -64,6 +65,13 @@ class AutoGPT {
|
|
|
64
65
|
writable: true,
|
|
65
66
|
value: void 0
|
|
66
67
|
});
|
|
68
|
+
// Currently not generic enough to support any text splitter.
|
|
69
|
+
Object.defineProperty(this, "textSplitter", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: void 0
|
|
74
|
+
});
|
|
67
75
|
this.aiName = aiName;
|
|
68
76
|
this.memory = memory;
|
|
69
77
|
this.fullMessageHistory = [];
|
|
@@ -73,6 +81,13 @@ class AutoGPT {
|
|
|
73
81
|
this.tools = tools;
|
|
74
82
|
this.feedbackTool = feedbackTool;
|
|
75
83
|
this.maxIterations = maxIterations;
|
|
84
|
+
const chunkSize = (0, count_tokens_js_1.getEmbeddingContextSize)("modelName" in memory.vectorStore.embeddings
|
|
85
|
+
? memory.vectorStore.embeddings.modelName
|
|
86
|
+
: undefined);
|
|
87
|
+
this.textSplitter = new text_splitter_js_1.TokenTextSplitter({
|
|
88
|
+
chunkSize,
|
|
89
|
+
chunkOverlap: Math.round(chunkSize / 10),
|
|
90
|
+
});
|
|
76
91
|
}
|
|
77
92
|
static fromLLMAndTools(llm, tools, { aiName, aiRole, memory, maxIterations = 100,
|
|
78
93
|
// humanInTheLoop = false,
|
|
@@ -82,6 +97,7 @@ class AutoGPT {
|
|
|
82
97
|
aiRole,
|
|
83
98
|
tools,
|
|
84
99
|
tokenCounter: llm.getNumTokens.bind(llm),
|
|
100
|
+
sendTokenLimit: (0, count_tokens_js_1.getModelContextSize)("modelName" in llm ? llm.modelName : "gpt2"),
|
|
85
101
|
});
|
|
86
102
|
// const feedbackTool = humanInTheLoop ? new HumanInputRun() : null;
|
|
87
103
|
const chain = new llm_chain_js_1.LLMChain({ llm, prompt });
|
|
@@ -142,9 +158,8 @@ class AutoGPT {
|
|
|
142
158
|
}
|
|
143
159
|
memoryToAdd += feedback;
|
|
144
160
|
}
|
|
145
|
-
await this.
|
|
146
|
-
|
|
147
|
-
]);
|
|
161
|
+
const documents = await this.textSplitter.createDocuments([memoryToAdd]);
|
|
162
|
+
await this.memory.addDocuments(documents);
|
|
148
163
|
this.fullMessageHistory.push(new index_js_1.SystemChatMessage(result));
|
|
149
164
|
}
|
|
150
165
|
return undefined;
|
|
@@ -5,6 +5,7 @@ import { Tool } from "../../tools/base.js";
|
|
|
5
5
|
import { AutoGPTOutputParser } from "./output_parser.js";
|
|
6
6
|
import { BaseChatMessage } from "../../schema/index.js";
|
|
7
7
|
import { ObjectTool } from "./schema.js";
|
|
8
|
+
import { TokenTextSplitter } from "../../text_splitter.js";
|
|
8
9
|
export interface AutoGPTInput {
|
|
9
10
|
aiName: string;
|
|
10
11
|
aiRole: string;
|
|
@@ -23,6 +24,7 @@ export declare class AutoGPT {
|
|
|
23
24
|
tools: ObjectTool[];
|
|
24
25
|
feedbackTool?: Tool;
|
|
25
26
|
maxIterations: number;
|
|
27
|
+
textSplitter: TokenTextSplitter;
|
|
26
28
|
constructor({ aiName, memory, chain, outputParser, tools, feedbackTool, maxIterations, }: Omit<Required<AutoGPTInput>, "aiRole" | "humanInTheLoop"> & {
|
|
27
29
|
chain: LLMChain;
|
|
28
30
|
tools: ObjectTool[];
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { LLMChain } from "../../chains/llm_chain.js";
|
|
2
|
-
import { Document } from "../../document.js";
|
|
3
2
|
import { AutoGPTOutputParser } from "./output_parser.js";
|
|
4
3
|
import { AutoGPTPrompt } from "./prompt.js";
|
|
5
4
|
import { AIChatMessage, HumanChatMessage, SystemChatMessage, } from "../../schema/index.js";
|
|
6
5
|
// import { HumanInputRun } from "./tools/human/tool"; // TODO
|
|
7
6
|
import { FINISH_NAME } from "./schema.js";
|
|
7
|
+
import { TokenTextSplitter } from "../../text_splitter.js";
|
|
8
|
+
import { getEmbeddingContextSize, getModelContextSize, } from "../../base_language/count_tokens.js";
|
|
8
9
|
export class AutoGPT {
|
|
9
10
|
constructor({ aiName, memory, chain, outputParser, tools, feedbackTool, maxIterations, }) {
|
|
10
11
|
Object.defineProperty(this, "aiName", {
|
|
@@ -61,6 +62,13 @@ export class AutoGPT {
|
|
|
61
62
|
writable: true,
|
|
62
63
|
value: void 0
|
|
63
64
|
});
|
|
65
|
+
// Currently not generic enough to support any text splitter.
|
|
66
|
+
Object.defineProperty(this, "textSplitter", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: void 0
|
|
71
|
+
});
|
|
64
72
|
this.aiName = aiName;
|
|
65
73
|
this.memory = memory;
|
|
66
74
|
this.fullMessageHistory = [];
|
|
@@ -70,6 +78,13 @@ export class AutoGPT {
|
|
|
70
78
|
this.tools = tools;
|
|
71
79
|
this.feedbackTool = feedbackTool;
|
|
72
80
|
this.maxIterations = maxIterations;
|
|
81
|
+
const chunkSize = getEmbeddingContextSize("modelName" in memory.vectorStore.embeddings
|
|
82
|
+
? memory.vectorStore.embeddings.modelName
|
|
83
|
+
: undefined);
|
|
84
|
+
this.textSplitter = new TokenTextSplitter({
|
|
85
|
+
chunkSize,
|
|
86
|
+
chunkOverlap: Math.round(chunkSize / 10),
|
|
87
|
+
});
|
|
73
88
|
}
|
|
74
89
|
static fromLLMAndTools(llm, tools, { aiName, aiRole, memory, maxIterations = 100,
|
|
75
90
|
// humanInTheLoop = false,
|
|
@@ -79,6 +94,7 @@ export class AutoGPT {
|
|
|
79
94
|
aiRole,
|
|
80
95
|
tools,
|
|
81
96
|
tokenCounter: llm.getNumTokens.bind(llm),
|
|
97
|
+
sendTokenLimit: getModelContextSize("modelName" in llm ? llm.modelName : "gpt2"),
|
|
82
98
|
});
|
|
83
99
|
// const feedbackTool = humanInTheLoop ? new HumanInputRun() : null;
|
|
84
100
|
const chain = new LLMChain({ llm, prompt });
|
|
@@ -139,9 +155,8 @@ export class AutoGPT {
|
|
|
139
155
|
}
|
|
140
156
|
memoryToAdd += feedback;
|
|
141
157
|
}
|
|
142
|
-
await this.
|
|
143
|
-
|
|
144
|
-
]);
|
|
158
|
+
const documents = await this.textSplitter.createDocuments([memoryToAdd]);
|
|
159
|
+
await this.memory.addDocuments(documents);
|
|
145
160
|
this.fullMessageHistory.push(new SystemChatMessage(result));
|
|
146
161
|
}
|
|
147
162
|
return undefined;
|
|
@@ -57,7 +57,7 @@ class PromptGenerator {
|
|
|
57
57
|
this.commands.push(tool);
|
|
58
58
|
}
|
|
59
59
|
_generate_command_string(tool) {
|
|
60
|
-
let output =
|
|
60
|
+
let output = `"${tool.name}": ${tool.description}`;
|
|
61
61
|
output += `, args json schema: ${JSON.stringify((0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema).properties)}`;
|
|
62
62
|
return output;
|
|
63
63
|
}
|
|
@@ -54,7 +54,7 @@ export class PromptGenerator {
|
|
|
54
54
|
this.commands.push(tool);
|
|
55
55
|
}
|
|
56
56
|
_generate_command_string(tool) {
|
|
57
|
-
let output =
|
|
57
|
+
let output = `"${tool.name}": ${tool.description}`;
|
|
58
58
|
output += `, args json schema: ${JSON.stringify(zodToJsonSchema(tool.schema).properties)}`;
|
|
59
59
|
return output;
|
|
60
60
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OpenAI = exports.LLMChain = exports.FewShotPromptTemplate = exports.BasePromptTemplate = exports.PromptTemplate = void 0;
|
|
4
|
-
// eslint-disable-next-line tree-shaking/no-side-effects-in-initialization
|
|
5
4
|
/* #__PURE__ */ console.error("[WARN] Importing from 'langchain' is deprecated. See https://js.langchain.com/docs/getting-started/install#updating-from-0052 for upgrade instructions.");
|
|
6
5
|
var index_js_1 = require("./prompts/index.cjs");
|
|
7
6
|
Object.defineProperty(exports, "PromptTemplate", { enumerable: true, get: function () { return index_js_1.PromptTemplate; } });
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line tree-shaking/no-side-effects-in-initialization
|
|
2
1
|
/* #__PURE__ */ console.error("[WARN] Importing from 'langchain' is deprecated. See https://js.langchain.com/docs/getting-started/install#updating-from-0052 for upgrade instructions.");
|
|
3
2
|
export { PromptTemplate, BasePromptTemplate, FewShotPromptTemplate, } from "./prompts/index.js";
|
|
4
3
|
export { LLMChain } from "./chains/llm_chain.js";
|
package/dist/llms/base.cjs
CHANGED
|
@@ -58,6 +58,7 @@ class BaseLLM extends index_js_3.BaseLanguageModel {
|
|
|
58
58
|
// it isnt included when listing the keys of the output object.
|
|
59
59
|
Object.defineProperty(output, index_js_2.RUN_KEY, {
|
|
60
60
|
value: runManager ? { runId: runManager?.runId } : undefined,
|
|
61
|
+
configurable: true,
|
|
61
62
|
});
|
|
62
63
|
return output;
|
|
63
64
|
}
|
package/dist/llms/base.js
CHANGED
|
@@ -55,6 +55,7 @@ export class BaseLLM extends BaseLanguageModel {
|
|
|
55
55
|
// it isnt included when listing the keys of the output object.
|
|
56
56
|
Object.defineProperty(output, RUN_KEY, {
|
|
57
57
|
value: runManager ? { runId: runManager?.runId } : undefined,
|
|
58
|
+
configurable: true,
|
|
58
59
|
});
|
|
59
60
|
return output;
|
|
60
61
|
}
|
package/dist/llms/cohere.cjs
CHANGED
|
@@ -31,7 +31,7 @@ class Cohere extends base_js_1.LLM {
|
|
|
31
31
|
});
|
|
32
32
|
const apiKey = fields?.apiKey ?? typeof process !== "undefined"
|
|
33
33
|
? // eslint-disable-next-line no-process-env
|
|
34
|
-
process.env
|
|
34
|
+
process.env?.COHERE_API_KEY
|
|
35
35
|
: undefined;
|
|
36
36
|
if (!apiKey) {
|
|
37
37
|
throw new Error("Please set the COHERE_API_KEY environment variable or pass it to the constructor as the apiKey field.");
|