langchain 0.0.212 → 0.0.214
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/README.md +1 -1
- package/chains/combine_documents.cjs +1 -0
- package/chains/combine_documents.d.ts +1 -0
- package/chains/combine_documents.js +1 -0
- package/chains/history_aware_retriever.cjs +1 -0
- package/chains/history_aware_retriever.d.ts +1 -0
- package/chains/history_aware_retriever.js +1 -0
- package/chains/retrieval.cjs +1 -0
- package/chains/retrieval.d.ts +1 -0
- package/chains/retrieval.js +1 -0
- package/dist/agents/agent.cjs +1 -0
- package/dist/agents/agent.js +1 -0
- package/dist/agents/executor.cjs +21 -3
- package/dist/agents/executor.d.ts +1 -0
- package/dist/agents/executor.js +21 -3
- package/dist/agents/format_scratchpad/openai_functions.cjs +22 -1
- package/dist/agents/format_scratchpad/openai_functions.d.ts +10 -0
- package/dist/agents/format_scratchpad/openai_functions.js +21 -1
- package/dist/agents/index.cjs +11 -4
- package/dist/agents/index.d.ts +6 -3
- package/dist/agents/index.js +5 -3
- package/dist/agents/initialize.cjs +1 -1
- package/dist/agents/initialize.d.ts +1 -1
- package/dist/agents/initialize.js +1 -1
- package/dist/agents/openai/output_parser.cjs +20 -196
- package/dist/agents/openai/output_parser.d.ts +2 -111
- package/dist/agents/openai/output_parser.js +6 -193
- package/dist/agents/{openai → openai_functions}/index.cjs +80 -2
- package/dist/agents/{openai → openai_functions}/index.d.ts +77 -3
- package/dist/agents/{openai → openai_functions}/index.js +78 -1
- package/dist/agents/openai_functions/output_parser.cjs +102 -0
- package/dist/agents/openai_functions/output_parser.d.ts +56 -0
- package/dist/agents/openai_functions/output_parser.js +98 -0
- package/dist/agents/openai_tools/index.cjs +83 -0
- package/dist/agents/openai_tools/index.d.ts +82 -0
- package/dist/agents/openai_tools/index.js +79 -0
- package/dist/agents/openai_tools/output_parser.cjs +102 -0
- package/dist/agents/openai_tools/output_parser.d.ts +57 -0
- package/dist/agents/openai_tools/output_parser.js +98 -0
- package/dist/agents/react/index.cjs +77 -0
- package/dist/agents/react/index.d.ts +62 -0
- package/dist/agents/react/index.js +73 -0
- package/dist/agents/react/output_parser.cjs +0 -1
- package/dist/agents/react/output_parser.d.ts +0 -1
- package/dist/agents/react/output_parser.js +0 -1
- package/dist/agents/structured_chat/index.cjs +87 -1
- package/dist/agents/structured_chat/index.d.ts +73 -0
- package/dist/agents/structured_chat/index.js +85 -0
- package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.cjs +1 -1
- package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.js +1 -1
- package/dist/agents/toolkits/conversational_retrieval/tool.cjs +1 -0
- package/dist/agents/toolkits/conversational_retrieval/tool.d.ts +1 -0
- package/dist/agents/toolkits/conversational_retrieval/tool.js +1 -0
- package/dist/agents/toolkits/json/json.cjs +2 -0
- package/dist/agents/toolkits/json/json.d.ts +2 -0
- package/dist/agents/toolkits/json/json.js +2 -0
- package/dist/agents/toolkits/openapi/openapi.cjs +2 -0
- package/dist/agents/toolkits/openapi/openapi.d.ts +2 -0
- package/dist/agents/toolkits/openapi/openapi.js +2 -0
- package/dist/agents/toolkits/vectorstore/vectorstore.cjs +2 -0
- package/dist/agents/toolkits/vectorstore/vectorstore.d.ts +2 -0
- package/dist/agents/toolkits/vectorstore/vectorstore.js +2 -0
- package/dist/agents/xml/index.cjs +77 -1
- package/dist/agents/xml/index.d.ts +67 -0
- package/dist/agents/xml/index.js +75 -0
- package/dist/callbacks/index.cjs +1 -4
- package/dist/callbacks/index.d.ts +1 -2
- package/dist/callbacks/index.js +1 -2
- package/dist/chains/combine_documents/base.cjs +16 -0
- package/dist/chains/combine_documents/base.d.ts +13 -0
- package/dist/chains/combine_documents/base.js +12 -0
- package/dist/chains/combine_documents/index.cjs +5 -0
- package/dist/chains/combine_documents/index.d.ts +1 -0
- package/dist/chains/combine_documents/index.js +1 -0
- package/dist/chains/combine_documents/reduce.cjs +5 -2
- package/dist/chains/combine_documents/reduce.js +4 -1
- package/dist/chains/combine_documents/stuff.cjs +42 -0
- package/dist/chains/combine_documents/stuff.d.ts +28 -0
- package/dist/chains/combine_documents/stuff.js +38 -0
- package/dist/chains/conversational_retrieval_chain.cjs +3 -3
- package/dist/chains/conversational_retrieval_chain.js +1 -1
- package/dist/chains/history_aware_retriever.cjs +55 -0
- package/dist/chains/history_aware_retriever.d.ts +55 -0
- package/dist/chains/history_aware_retriever.js +51 -0
- package/dist/chains/openai_functions/structured_output.cjs +63 -21
- package/dist/chains/openai_functions/structured_output.d.ts +25 -17
- package/dist/chains/openai_functions/structured_output.js +62 -20
- package/dist/chains/retrieval.cjs +60 -0
- package/dist/chains/retrieval.d.ts +65 -0
- package/dist/chains/retrieval.js +56 -0
- package/dist/experimental/autogpt/prompt.cjs +1 -1
- package/dist/experimental/autogpt/prompt.d.ts +1 -1
- package/dist/experimental/autogpt/prompt.js +1 -1
- package/dist/load/import_map.cjs +7 -3
- package/dist/load/import_map.d.ts +4 -0
- package/dist/load/import_map.js +4 -0
- package/dist/output_parsers/json.cjs +2 -78
- package/dist/output_parsers/json.d.ts +1 -1
- package/dist/output_parsers/json.js +1 -77
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/retrievers/multi_vector.cjs +11 -2
- package/dist/retrievers/multi_vector.d.ts +5 -3
- package/dist/retrievers/multi_vector.js +11 -2
- package/dist/retrievers/parent_document.cjs +1 -2
- package/dist/retrievers/parent_document.d.ts +1 -1
- package/dist/retrievers/parent_document.js +1 -2
- package/dist/retrievers/remote/chatgpt-plugin.cjs +5 -4
- package/dist/retrievers/remote/chatgpt-plugin.d.ts +5 -2
- package/dist/retrievers/remote/chatgpt-plugin.js +3 -2
- package/dist/retrievers/remote/index.cjs +2 -2
- package/dist/retrievers/remote/index.d.ts +1 -1
- package/dist/retrievers/remote/index.js +1 -1
- package/dist/retrievers/remote/remote-retriever.cjs +3 -2
- package/dist/retrievers/remote/remote-retriever.d.ts +3 -1
- package/dist/retrievers/remote/remote-retriever.js +2 -1
- package/dist/retrievers/vespa.cjs +15 -78
- package/dist/retrievers/vespa.d.ts +1 -54
- package/dist/retrievers/vespa.js +1 -76
- package/dist/schema/runnable/config.d.ts +1 -1
- package/dist/tools/retriever.cjs +17 -0
- package/dist/tools/retriever.d.ts +10 -0
- package/dist/tools/retriever.js +13 -0
- package/dist/util/entrypoint_deprecation.cjs +18 -0
- package/dist/util/entrypoint_deprecation.d.ts +5 -0
- package/dist/util/entrypoint_deprecation.js +14 -0
- package/package.json +36 -4
- package/tools/retriever.cjs +1 -0
- package/tools/retriever.d.ts +1 -0
- package/tools/retriever.js +1 -0
- package/dist/callbacks/handlers/tracer_langchain_v1.cjs +0 -17
- package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +0 -1
- package/dist/callbacks/handlers/tracer_langchain_v1.js +0 -1
- package/dist/retrievers/remote/base.cjs +0 -68
- package/dist/retrievers/remote/base.d.ts +0 -60
- package/dist/retrievers/remote/base.js +0 -64
- /package/dist/agents/{openai → openai_functions}/prompt.cjs +0 -0
- /package/dist/agents/{openai → openai_functions}/prompt.d.ts +0 -0
- /package/dist/agents/{openai → openai_functions}/prompt.js +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { RunnableSequence, RunnablePassthrough, } from "@langchain/core/runnables";
|
|
2
|
+
function isBaseRetriever(x) {
|
|
3
|
+
return (!!x &&
|
|
4
|
+
typeof x.getRelevantDocuments === "function");
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Create a retrieval chain that retrieves documents and then passes them on.
|
|
8
|
+
* @param {CreateRetrievalChainParams} params A params object
|
|
9
|
+
* containing a retriever and a combineDocsChain.
|
|
10
|
+
* @returns An LCEL Runnable which returns a an object
|
|
11
|
+
* containing at least `context` and `answer` keys.
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // yarn add langchain @langchain/openai
|
|
15
|
+
*
|
|
16
|
+
* import { ChatOpenAI } from "@langchain/openai";
|
|
17
|
+
* import { pull } from "langchain/hub";
|
|
18
|
+
* import { createRetrievalChain } from "langchain/chains/retrieval";
|
|
19
|
+
* import { createStuffDocumentsChain } from "langchain/chains/combine_documents";
|
|
20
|
+
*
|
|
21
|
+
* const retrievalQAChatPrompt = await pull("langchain-ai/retrieval-qa-chat");
|
|
22
|
+
* const llm = new ChatOpenAI({});
|
|
23
|
+
* const retriever = ...
|
|
24
|
+
* const combineDocsChain = await createStuffDocumentsChain(...);
|
|
25
|
+
* const retrievalChain = await createRetrievalChain({
|
|
26
|
+
* retriever,
|
|
27
|
+
* combineDocsChain,
|
|
28
|
+
* });
|
|
29
|
+
* const response = await chain.invoke({ input: "..." });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export async function createRetrievalChain({ retriever, combineDocsChain, }) {
|
|
33
|
+
let retrieveDocumentsChain;
|
|
34
|
+
if (isBaseRetriever(retriever)) {
|
|
35
|
+
retrieveDocumentsChain = RunnableSequence.from([
|
|
36
|
+
(input) => input.input,
|
|
37
|
+
retriever,
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// TODO: Fix typing by adding withConfig to core RunnableInterface
|
|
42
|
+
retrieveDocumentsChain = retriever;
|
|
43
|
+
}
|
|
44
|
+
const retrievalChain = RunnableSequence.from([
|
|
45
|
+
RunnablePassthrough.assign({
|
|
46
|
+
context: retrieveDocumentsChain.withConfig({
|
|
47
|
+
runName: "retrieve_documents",
|
|
48
|
+
}),
|
|
49
|
+
chat_history: (input) => input.chat_history ?? [],
|
|
50
|
+
}),
|
|
51
|
+
RunnablePassthrough.assign({
|
|
52
|
+
answer: combineDocsChain,
|
|
53
|
+
}),
|
|
54
|
+
]).withConfig({ runName: "retrieval_chain" });
|
|
55
|
+
return retrievalChain;
|
|
56
|
+
}
|
|
@@ -99,7 +99,7 @@ class AutoGPTPrompt extends chat_js_1.BaseChatPromptTemplate {
|
|
|
99
99
|
if (typeof memoryMessage.content !== "string") {
|
|
100
100
|
throw new Error("Non-string message content is not supported.");
|
|
101
101
|
}
|
|
102
|
-
const usedTokensWithMemory =
|
|
102
|
+
const usedTokensWithMemory = usedTokens + (await this.tokenCounter(memoryMessage.content));
|
|
103
103
|
const historicalMessages = [];
|
|
104
104
|
for (const message of previousMessages.slice(-10).reverse()) {
|
|
105
105
|
if (typeof message.content !== "string") {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { VectorStoreRetrieverInterface } from "@langchain/core/vectorstores";
|
|
2
2
|
import { BaseChatPromptTemplate } from "../../prompts/chat.js";
|
|
3
|
+
import { SerializedBasePromptTemplate } from "../../prompts/serde.js";
|
|
3
4
|
import { BaseMessage, PartialValues } from "../../schema/index.js";
|
|
4
5
|
import { ObjectTool } from "./schema.js";
|
|
5
|
-
import { SerializedBasePromptTemplate } from "../../prompts/serde.js";
|
|
6
6
|
/**
|
|
7
7
|
* Interface for the input parameters of the AutoGPTPrompt class.
|
|
8
8
|
*/
|
|
@@ -96,7 +96,7 @@ export class AutoGPTPrompt extends BaseChatPromptTemplate {
|
|
|
96
96
|
if (typeof memoryMessage.content !== "string") {
|
|
97
97
|
throw new Error("Non-string message content is not supported.");
|
|
98
98
|
}
|
|
99
|
-
const usedTokensWithMemory =
|
|
99
|
+
const usedTokensWithMemory = usedTokens + (await this.tokenCounter(memoryMessage.content));
|
|
100
100
|
const historicalMessages = [];
|
|
101
101
|
for (const message of previousMessages.slice(-10).reverse()) {
|
|
102
102
|
if (typeof message.content !== "string") {
|
package/dist/load/import_map.cjs
CHANGED
|
@@ -24,9 +24,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
exports.runnables__remote = exports.runnables = exports.evaluation = exports.experimental__masking = exports.experimental__chains__violation_of_expectations = exports.experimental__chat_models__ollama_functions = exports.experimental__chat_models__bittensor = void 0;
|
|
27
|
+
exports.document_loaders__base = exports.document = exports.memory = exports.text_splitter = exports.vectorstores__xata = exports.vectorstores__vectara = exports.vectorstores__prisma = exports.vectorstores__memory = exports.vectorstores__base = exports.prompts = exports.llms__fake = exports.llms__yandex = exports.llms__fireworks = exports.llms__ollama = exports.llms__cloudflare_workersai = exports.llms__aleph_alpha = exports.llms__ai21 = exports.llms__openai = exports.llms__base = exports.embeddings__voyage = exports.embeddings__minimax = exports.embeddings__openai = exports.embeddings__ollama = exports.embeddings__fake = exports.embeddings__cache_backed = exports.embeddings__base = exports.chains__retrieval = exports.chains__openai_functions = exports.chains__history_aware_retriever = exports.chains__combine_documents__reduce = exports.chains__combine_documents = exports.chains = exports.tools__google_places = exports.tools__retriever = exports.tools__render = exports.tools__connery = exports.tools = exports.base_language = exports.agents__openai__output_parser = exports.agents__xml__output_parser = exports.agents__react__output_parser = exports.agents__format_scratchpad__log_to_message = exports.agents__format_scratchpad__xml = exports.agents__format_scratchpad__log = exports.agents__format_scratchpad__openai_tools = exports.agents__format_scratchpad = exports.agents__toolkits__connery = exports.agents__toolkits = exports.agents = exports.load__serializable = void 0;
|
|
28
|
+
exports.experimental__openai_assistant = exports.experimental__autogpt = exports.util__time = exports.util__math = exports.util__document = exports.storage__in_memory = exports.storage__encoder_backed = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__embeddings_filter = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__tavily_search_api = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = exports.retrievers__chaindesk = exports.retrievers__remote = exports.output_parsers = exports.callbacks = exports.schema__storage = exports.schema__runnable = exports.schema__retriever = exports.schema__query_constructor = exports.schema__prompt_template = exports.schema__output_parser = exports.schema__document = exports.schema = exports.chat_models__fake = exports.chat_models__yandex = exports.chat_models__minimax = exports.chat_models__ollama = exports.chat_models__baiduwenxin = exports.chat_models__fireworks = exports.chat_models__cloudflare_workersai = exports.chat_models__anthropic = exports.chat_models__openai = exports.chat_models__base = exports.document_transformers__openai_functions = exports.document_loaders__web__sort_xyz_blockchain = exports.document_loaders__web__serpapi = exports.document_loaders__web__searchapi = void 0;
|
|
29
|
+
exports.runnables__remote = exports.runnables = exports.evaluation = exports.experimental__masking = exports.experimental__chains__violation_of_expectations = exports.experimental__chat_models__ollama_functions = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__openai_files = void 0;
|
|
30
30
|
exports.load__serializable = __importStar(require("../load/serializable.cjs"));
|
|
31
31
|
exports.agents = __importStar(require("../agents/index.cjs"));
|
|
32
32
|
exports.agents__toolkits = __importStar(require("../agents/toolkits/index.cjs"));
|
|
@@ -43,10 +43,14 @@ exports.base_language = __importStar(require("../base_language/index.cjs"));
|
|
|
43
43
|
exports.tools = __importStar(require("../tools/index.cjs"));
|
|
44
44
|
exports.tools__connery = __importStar(require("../tools/connery.cjs"));
|
|
45
45
|
exports.tools__render = __importStar(require("../tools/render.cjs"));
|
|
46
|
+
exports.tools__retriever = __importStar(require("../tools/retriever.cjs"));
|
|
46
47
|
exports.tools__google_places = __importStar(require("../tools/google_places.cjs"));
|
|
47
48
|
exports.chains = __importStar(require("../chains/index.cjs"));
|
|
49
|
+
exports.chains__combine_documents = __importStar(require("../chains/combine_documents/index.cjs"));
|
|
48
50
|
exports.chains__combine_documents__reduce = __importStar(require("../chains/combine_documents/reduce.cjs"));
|
|
51
|
+
exports.chains__history_aware_retriever = __importStar(require("../chains/history_aware_retriever.cjs"));
|
|
49
52
|
exports.chains__openai_functions = __importStar(require("../chains/openai_functions/index.cjs"));
|
|
53
|
+
exports.chains__retrieval = __importStar(require("../chains/retrieval.cjs"));
|
|
50
54
|
exports.embeddings__base = __importStar(require("../embeddings/base.cjs"));
|
|
51
55
|
exports.embeddings__cache_backed = __importStar(require("../embeddings/cache_backed.cjs"));
|
|
52
56
|
exports.embeddings__fake = __importStar(require("../embeddings/fake.cjs"));
|
|
@@ -14,10 +14,14 @@ export * as base_language from "../base_language/index.js";
|
|
|
14
14
|
export * as tools from "../tools/index.js";
|
|
15
15
|
export * as tools__connery from "../tools/connery.js";
|
|
16
16
|
export * as tools__render from "../tools/render.js";
|
|
17
|
+
export * as tools__retriever from "../tools/retriever.js";
|
|
17
18
|
export * as tools__google_places from "../tools/google_places.js";
|
|
18
19
|
export * as chains from "../chains/index.js";
|
|
20
|
+
export * as chains__combine_documents from "../chains/combine_documents/index.js";
|
|
19
21
|
export * as chains__combine_documents__reduce from "../chains/combine_documents/reduce.js";
|
|
22
|
+
export * as chains__history_aware_retriever from "../chains/history_aware_retriever.js";
|
|
20
23
|
export * as chains__openai_functions from "../chains/openai_functions/index.js";
|
|
24
|
+
export * as chains__retrieval from "../chains/retrieval.js";
|
|
21
25
|
export * as embeddings__base from "../embeddings/base.js";
|
|
22
26
|
export * as embeddings__cache_backed from "../embeddings/cache_backed.js";
|
|
23
27
|
export * as embeddings__fake from "../embeddings/fake.js";
|
package/dist/load/import_map.js
CHANGED
|
@@ -15,10 +15,14 @@ export * as base_language from "../base_language/index.js";
|
|
|
15
15
|
export * as tools from "../tools/index.js";
|
|
16
16
|
export * as tools__connery from "../tools/connery.js";
|
|
17
17
|
export * as tools__render from "../tools/render.js";
|
|
18
|
+
export * as tools__retriever from "../tools/retriever.js";
|
|
18
19
|
export * as tools__google_places from "../tools/google_places.js";
|
|
19
20
|
export * as chains from "../chains/index.js";
|
|
21
|
+
export * as chains__combine_documents from "../chains/combine_documents/index.js";
|
|
20
22
|
export * as chains__combine_documents__reduce from "../chains/combine_documents/reduce.js";
|
|
23
|
+
export * as chains__history_aware_retriever from "../chains/history_aware_retriever.js";
|
|
21
24
|
export * as chains__openai_functions from "../chains/openai_functions/index.js";
|
|
25
|
+
export * as chains__retrieval from "../chains/retrieval.js";
|
|
22
26
|
export * as embeddings__base from "../embeddings/base.js";
|
|
23
27
|
export * as embeddings__cache_backed from "../embeddings/cache_backed.js";
|
|
24
28
|
export * as embeddings__fake from "../embeddings/fake.js";
|
|
@@ -1,81 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Adapted from https://github.com/KillianLucas/open-interpreter/blob/main/interpreter/utils/parse_partial_json.py
|
|
3
|
-
// MIT License
|
|
4
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
3
|
exports.parsePartialJson = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (typeof s === "undefined") {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
// Attempt to parse the string as-is.
|
|
12
|
-
try {
|
|
13
|
-
return JSON.parse(s);
|
|
14
|
-
}
|
|
15
|
-
catch (error) {
|
|
16
|
-
// Pass
|
|
17
|
-
}
|
|
18
|
-
// Initialize variables.
|
|
19
|
-
let new_s = "";
|
|
20
|
-
const stack = [];
|
|
21
|
-
let isInsideString = false;
|
|
22
|
-
let escaped = false;
|
|
23
|
-
// Process each character in the string one at a time.
|
|
24
|
-
for (let char of s) {
|
|
25
|
-
if (isInsideString) {
|
|
26
|
-
if (char === '"' && !escaped) {
|
|
27
|
-
isInsideString = false;
|
|
28
|
-
}
|
|
29
|
-
else if (char === "\n" && !escaped) {
|
|
30
|
-
char = "\\n"; // Replace the newline character with the escape sequence.
|
|
31
|
-
}
|
|
32
|
-
else if (char === "\\") {
|
|
33
|
-
escaped = !escaped;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
escaped = false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
if (char === '"') {
|
|
41
|
-
isInsideString = true;
|
|
42
|
-
escaped = false;
|
|
43
|
-
}
|
|
44
|
-
else if (char === "{") {
|
|
45
|
-
stack.push("}");
|
|
46
|
-
}
|
|
47
|
-
else if (char === "[") {
|
|
48
|
-
stack.push("]");
|
|
49
|
-
}
|
|
50
|
-
else if (char === "}" || char === "]") {
|
|
51
|
-
if (stack && stack[stack.length - 1] === char) {
|
|
52
|
-
stack.pop();
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// Mismatched closing character; the input is malformed.
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
// Append the processed character to the new string.
|
|
61
|
-
new_s += char;
|
|
62
|
-
}
|
|
63
|
-
// If we're still inside a string at the end of processing,
|
|
64
|
-
// we need to close the string.
|
|
65
|
-
if (isInsideString) {
|
|
66
|
-
new_s += '"';
|
|
67
|
-
}
|
|
68
|
-
// Close any remaining open structures in the reverse order that they were opened.
|
|
69
|
-
for (let i = stack.length - 1; i >= 0; i -= 1) {
|
|
70
|
-
new_s += stack[i];
|
|
71
|
-
}
|
|
72
|
-
// Attempt to parse the modified string as JSON.
|
|
73
|
-
try {
|
|
74
|
-
return JSON.parse(new_s);
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
// If we still can't parse the string as JSON, return null to indicate failure.
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.parsePartialJson = parsePartialJson;
|
|
4
|
+
var output_parsers_1 = require("@langchain/core/output_parsers");
|
|
5
|
+
Object.defineProperty(exports, "parsePartialJson", { enumerable: true, get: function () { return output_parsers_1.parsePartialJson; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { parsePartialJson } from "@langchain/core/output_parsers";
|
|
@@ -1,77 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// MIT License
|
|
3
|
-
export function parsePartialJson(s) {
|
|
4
|
-
// If the input is undefined, return null to indicate failure.
|
|
5
|
-
if (typeof s === "undefined") {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
// Attempt to parse the string as-is.
|
|
9
|
-
try {
|
|
10
|
-
return JSON.parse(s);
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
// Pass
|
|
14
|
-
}
|
|
15
|
-
// Initialize variables.
|
|
16
|
-
let new_s = "";
|
|
17
|
-
const stack = [];
|
|
18
|
-
let isInsideString = false;
|
|
19
|
-
let escaped = false;
|
|
20
|
-
// Process each character in the string one at a time.
|
|
21
|
-
for (let char of s) {
|
|
22
|
-
if (isInsideString) {
|
|
23
|
-
if (char === '"' && !escaped) {
|
|
24
|
-
isInsideString = false;
|
|
25
|
-
}
|
|
26
|
-
else if (char === "\n" && !escaped) {
|
|
27
|
-
char = "\\n"; // Replace the newline character with the escape sequence.
|
|
28
|
-
}
|
|
29
|
-
else if (char === "\\") {
|
|
30
|
-
escaped = !escaped;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
escaped = false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
if (char === '"') {
|
|
38
|
-
isInsideString = true;
|
|
39
|
-
escaped = false;
|
|
40
|
-
}
|
|
41
|
-
else if (char === "{") {
|
|
42
|
-
stack.push("}");
|
|
43
|
-
}
|
|
44
|
-
else if (char === "[") {
|
|
45
|
-
stack.push("]");
|
|
46
|
-
}
|
|
47
|
-
else if (char === "}" || char === "]") {
|
|
48
|
-
if (stack && stack[stack.length - 1] === char) {
|
|
49
|
-
stack.pop();
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
// Mismatched closing character; the input is malformed.
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
// Append the processed character to the new string.
|
|
58
|
-
new_s += char;
|
|
59
|
-
}
|
|
60
|
-
// If we're still inside a string at the end of processing,
|
|
61
|
-
// we need to close the string.
|
|
62
|
-
if (isInsideString) {
|
|
63
|
-
new_s += '"';
|
|
64
|
-
}
|
|
65
|
-
// Close any remaining open structures in the reverse order that they were opened.
|
|
66
|
-
for (let i = stack.length - 1; i >= 0; i -= 1) {
|
|
67
|
-
new_s += stack[i];
|
|
68
|
-
}
|
|
69
|
-
// Attempt to parse the modified string as JSON.
|
|
70
|
-
try {
|
|
71
|
-
return JSON.parse(new_s);
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
// If we still can't parse the string as JSON, return null to indicate failure.
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
1
|
+
export { parsePartialJson } from "@langchain/core/output_parsers";
|
|
@@ -40,7 +40,7 @@ export declare class JsonOutputFunctionsParser extends BaseCumulativeTransformOu
|
|
|
40
40
|
constructor(config?: {
|
|
41
41
|
argsOnly?: boolean;
|
|
42
42
|
} & BaseCumulativeTransformOutputParserInput);
|
|
43
|
-
protected _diff(prev:
|
|
43
|
+
protected _diff(prev: unknown | undefined, next: unknown): JSONPatchOperation[] | undefined;
|
|
44
44
|
parsePartialResult(generations: ChatGeneration[]): Promise<object | undefined>;
|
|
45
45
|
/**
|
|
46
46
|
* Parses the output and returns a JSON object. If `argsOnly` is true,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MultiVectorRetriever = void 0;
|
|
4
4
|
const retrievers_1 = require("@langchain/core/retrievers");
|
|
5
|
+
const encoder_backed_js_1 = require("../storage/encoder_backed.cjs");
|
|
5
6
|
/**
|
|
6
7
|
* A retriever that retrieves documents from a vector store and a document
|
|
7
8
|
* store. It uses the vector store to find relevant documents based on a
|
|
@@ -10,7 +11,7 @@ const retrievers_1 = require("@langchain/core/retrievers");
|
|
|
10
11
|
* ```typescript
|
|
11
12
|
* const retriever = new MultiVectorRetriever({
|
|
12
13
|
* vectorstore: new FaissStore(),
|
|
13
|
-
*
|
|
14
|
+
* byteStore: new InMemoryStore<Unit8Array>(),
|
|
14
15
|
* idKey: "doc_id",
|
|
15
16
|
* childK: 20,
|
|
16
17
|
* parentK: 5,
|
|
@@ -63,7 +64,15 @@ class MultiVectorRetriever extends retrievers_1.BaseRetriever {
|
|
|
63
64
|
value: void 0
|
|
64
65
|
});
|
|
65
66
|
this.vectorstore = args.vectorstore;
|
|
66
|
-
|
|
67
|
+
if (args.byteStore) {
|
|
68
|
+
this.docstore = (0, encoder_backed_js_1.createDocumentStoreFromByteStore)(args.byteStore);
|
|
69
|
+
}
|
|
70
|
+
else if (args.docstore) {
|
|
71
|
+
this.docstore = args.docstore;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw new Error("byteStore and docstore are undefined. Please provide at least one.");
|
|
75
|
+
}
|
|
67
76
|
this.idKey = args.idKey ?? "doc_id";
|
|
68
77
|
this.childK = args.childK;
|
|
69
78
|
this.parentK = args.parentK;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { BaseRetriever, type BaseRetrieverInput } from "@langchain/core/retrievers";
|
|
2
2
|
import type { VectorStoreInterface } from "@langchain/core/vectorstores";
|
|
3
|
-
import { BaseStoreInterface } from "../schema/storage.js";
|
|
3
|
+
import { BaseStore, BaseStoreInterface } from "../schema/storage.js";
|
|
4
4
|
import { Document } from "../document.js";
|
|
5
5
|
/**
|
|
6
6
|
* Arguments for the MultiVectorRetriever class.
|
|
7
7
|
*/
|
|
8
8
|
export interface MultiVectorRetrieverInput extends BaseRetrieverInput {
|
|
9
9
|
vectorstore: VectorStoreInterface;
|
|
10
|
-
|
|
10
|
+
/** @deprecated Prefer `byteStore`. */
|
|
11
|
+
docstore?: BaseStoreInterface<string, Document>;
|
|
12
|
+
byteStore?: BaseStore<string, Uint8Array>;
|
|
11
13
|
idKey?: string;
|
|
12
14
|
childK?: number;
|
|
13
15
|
parentK?: number;
|
|
@@ -20,7 +22,7 @@ export interface MultiVectorRetrieverInput extends BaseRetrieverInput {
|
|
|
20
22
|
* ```typescript
|
|
21
23
|
* const retriever = new MultiVectorRetriever({
|
|
22
24
|
* vectorstore: new FaissStore(),
|
|
23
|
-
*
|
|
25
|
+
* byteStore: new InMemoryStore<Unit8Array>(),
|
|
24
26
|
* idKey: "doc_id",
|
|
25
27
|
* childK: 20,
|
|
26
28
|
* parentK: 5,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseRetriever, } from "@langchain/core/retrievers";
|
|
2
|
+
import { createDocumentStoreFromByteStore } from "../storage/encoder_backed.js";
|
|
2
3
|
/**
|
|
3
4
|
* A retriever that retrieves documents from a vector store and a document
|
|
4
5
|
* store. It uses the vector store to find relevant documents based on a
|
|
@@ -7,7 +8,7 @@ import { BaseRetriever, } from "@langchain/core/retrievers";
|
|
|
7
8
|
* ```typescript
|
|
8
9
|
* const retriever = new MultiVectorRetriever({
|
|
9
10
|
* vectorstore: new FaissStore(),
|
|
10
|
-
*
|
|
11
|
+
* byteStore: new InMemoryStore<Unit8Array>(),
|
|
11
12
|
* idKey: "doc_id",
|
|
12
13
|
* childK: 20,
|
|
13
14
|
* parentK: 5,
|
|
@@ -60,7 +61,15 @@ export class MultiVectorRetriever extends BaseRetriever {
|
|
|
60
61
|
value: void 0
|
|
61
62
|
});
|
|
62
63
|
this.vectorstore = args.vectorstore;
|
|
63
|
-
|
|
64
|
+
if (args.byteStore) {
|
|
65
|
+
this.docstore = createDocumentStoreFromByteStore(args.byteStore);
|
|
66
|
+
}
|
|
67
|
+
else if (args.docstore) {
|
|
68
|
+
this.docstore = args.docstore;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
throw new Error("byteStore and docstore are undefined. Please provide at least one.");
|
|
72
|
+
}
|
|
64
73
|
this.idKey = args.idKey ?? "doc_id";
|
|
65
74
|
this.childK = args.childK;
|
|
66
75
|
this.parentK = args.parentK;
|
|
@@ -39,7 +39,7 @@ const multi_vector_js_1 = require("./multi_vector.cjs");
|
|
|
39
39
|
* ```typescript
|
|
40
40
|
* const retriever = new ParentDocumentRetriever({
|
|
41
41
|
* vectorstore: new MemoryVectorStore(new OpenAIEmbeddings()),
|
|
42
|
-
*
|
|
42
|
+
* byteStore: new InMemoryStore<Uint8Array>(),
|
|
43
43
|
* parentSplitter: new RecursiveCharacterTextSplitter({
|
|
44
44
|
* chunkOverlap: 0,
|
|
45
45
|
* chunkSize: 500,
|
|
@@ -112,7 +112,6 @@ class ParentDocumentRetriever extends multi_vector_js_1.MultiVectorRetriever {
|
|
|
112
112
|
value: void 0
|
|
113
113
|
});
|
|
114
114
|
this.vectorstore = fields.vectorstore;
|
|
115
|
-
this.docstore = fields.docstore;
|
|
116
115
|
this.childSplitter = fields.childSplitter;
|
|
117
116
|
this.parentSplitter = fields.parentSplitter;
|
|
118
117
|
this.idKey = fields.idKey ?? this.idKey;
|
|
@@ -27,7 +27,7 @@ export type ParentDocumentRetrieverFields = MultiVectorRetrieverInput & {
|
|
|
27
27
|
* ```typescript
|
|
28
28
|
* const retriever = new ParentDocumentRetriever({
|
|
29
29
|
* vectorstore: new MemoryVectorStore(new OpenAIEmbeddings()),
|
|
30
|
-
*
|
|
30
|
+
* byteStore: new InMemoryStore<Uint8Array>(),
|
|
31
31
|
* parentSplitter: new RecursiveCharacterTextSplitter({
|
|
32
32
|
* chunkOverlap: 0,
|
|
33
33
|
* chunkSize: 500,
|
|
@@ -13,7 +13,7 @@ import { MultiVectorRetriever, } from "./multi_vector.js";
|
|
|
13
13
|
* ```typescript
|
|
14
14
|
* const retriever = new ParentDocumentRetriever({
|
|
15
15
|
* vectorstore: new MemoryVectorStore(new OpenAIEmbeddings()),
|
|
16
|
-
*
|
|
16
|
+
* byteStore: new InMemoryStore<Uint8Array>(),
|
|
17
17
|
* parentSplitter: new RecursiveCharacterTextSplitter({
|
|
18
18
|
* chunkOverlap: 0,
|
|
19
19
|
* chunkSize: 500,
|
|
@@ -86,7 +86,6 @@ export class ParentDocumentRetriever extends MultiVectorRetriever {
|
|
|
86
86
|
value: void 0
|
|
87
87
|
});
|
|
88
88
|
this.vectorstore = fields.vectorstore;
|
|
89
|
-
this.docstore = fields.docstore;
|
|
90
89
|
this.childSplitter = fields.childSplitter;
|
|
91
90
|
this.parentSplitter = fields.parentSplitter;
|
|
92
91
|
this.idKey = fields.idKey ?? this.idKey;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChatGPTPluginRetriever = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const documents_1 = require("@langchain/core/documents");
|
|
5
|
+
const remote_1 = require("@langchain/community/retrievers/remote");
|
|
6
6
|
/**
|
|
7
|
+
* @deprecated ChatGPT Plugins have been deprecated in favor of GPTs.
|
|
7
8
|
* Class that connects ChatGPT to third-party applications via plugins. It
|
|
8
9
|
* extends the RemoteRetriever class and implements the
|
|
9
10
|
* ChatGPTPluginRetrieverParams interface.
|
|
@@ -18,7 +19,7 @@ const base_js_1 = require("./base.cjs");
|
|
|
18
19
|
* const docs = await retriever.getRelevantDocuments("hello world");
|
|
19
20
|
* ```
|
|
20
21
|
*/
|
|
21
|
-
class ChatGPTPluginRetriever extends
|
|
22
|
+
class ChatGPTPluginRetriever extends remote_1.RemoteRetriever {
|
|
22
23
|
constructor({ topK = 4, filter, ...rest }) {
|
|
23
24
|
super(rest);
|
|
24
25
|
Object.defineProperty(this, "lc_namespace", {
|
|
@@ -73,7 +74,7 @@ class ChatGPTPluginRetriever extends base_js_1.RemoteRetriever {
|
|
|
73
74
|
}
|
|
74
75
|
return results.map(
|
|
75
76
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
-
(result) => new
|
|
77
|
+
(result) => new documents_1.Document({
|
|
77
78
|
pageContent: result.text,
|
|
78
79
|
metadata: result.metadata,
|
|
79
80
|
}));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Document } from "
|
|
2
|
-
import { RemoteRetriever, RemoteRetrieverParams, RemoteRetrieverValues } from "
|
|
1
|
+
import { Document } from "@langchain/core/documents";
|
|
2
|
+
import { RemoteRetriever, RemoteRetrieverParams, RemoteRetrieverValues } from "@langchain/community/retrievers/remote";
|
|
3
3
|
/**
|
|
4
|
+
* @deprecated
|
|
4
5
|
* Interface for the filter parameters used when querying the
|
|
5
6
|
* ChatGPTRetrievalPlugin server.
|
|
6
7
|
*/
|
|
@@ -12,6 +13,7 @@ export interface ChatGPTPluginRetrieverFilter {
|
|
|
12
13
|
start_date?: string;
|
|
13
14
|
end_date?: string;
|
|
14
15
|
}
|
|
16
|
+
/** @deprecated */
|
|
15
17
|
export interface ChatGPTPluginRetrieverParams extends RemoteRetrieverParams {
|
|
16
18
|
/**
|
|
17
19
|
* The number of results to request from the ChatGPTRetrievalPlugin server
|
|
@@ -23,6 +25,7 @@ export interface ChatGPTPluginRetrieverParams extends RemoteRetrieverParams {
|
|
|
23
25
|
filter?: ChatGPTPluginRetrieverFilter;
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
28
|
+
* @deprecated ChatGPT Plugins have been deprecated in favor of GPTs.
|
|
26
29
|
* Class that connects ChatGPT to third-party applications via plugins. It
|
|
27
30
|
* extends the RemoteRetriever class and implements the
|
|
28
31
|
* ChatGPTPluginRetrieverParams interface.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Document } from "
|
|
2
|
-
import { RemoteRetriever, } from "
|
|
1
|
+
import { Document } from "@langchain/core/documents";
|
|
2
|
+
import { RemoteRetriever, } from "@langchain/community/retrievers/remote";
|
|
3
3
|
/**
|
|
4
|
+
* @deprecated ChatGPT Plugins have been deprecated in favor of GPTs.
|
|
4
5
|
* Class that connects ChatGPT to third-party applications via plugins. It
|
|
5
6
|
* extends the RemoteRetriever class and implements the
|
|
6
7
|
* ChatGPTPluginRetrieverParams interface.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RemoteLangChainRetriever = exports.ChatGPTPluginRetriever = exports.RemoteRetriever = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "RemoteRetriever", { enumerable: true, get: function () { return
|
|
4
|
+
var remote_1 = require("@langchain/community/retrievers/remote");
|
|
5
|
+
Object.defineProperty(exports, "RemoteRetriever", { enumerable: true, get: function () { return remote_1.RemoteRetriever; } });
|
|
6
6
|
var chatgpt_plugin_js_1 = require("./chatgpt-plugin.cjs");
|
|
7
7
|
Object.defineProperty(exports, "ChatGPTPluginRetriever", { enumerable: true, get: function () { return chatgpt_plugin_js_1.ChatGPTPluginRetriever; } });
|
|
8
8
|
var remote_retriever_js_1 = require("./remote-retriever.cjs");
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { RemoteRetriever, type RemoteRetrieverParams, type RemoteRetrieverAuth, type RemoteRetrieverValues, } from "
|
|
1
|
+
export { RemoteRetriever, type RemoteRetrieverParams, type RemoteRetrieverAuth, type RemoteRetrieverValues, } from "@langchain/community/retrievers/remote";
|
|
2
2
|
export { ChatGPTPluginRetriever, type ChatGPTPluginRetrieverFilter, type ChatGPTPluginRetrieverParams, } from "./chatgpt-plugin.js";
|
|
3
3
|
export { RemoteLangChainRetriever, type RemoteLangChainRetrieverParams, } from "./remote-retriever.js";
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RemoteLangChainRetriever = void 0;
|
|
4
|
+
const remote_1 = require("@langchain/community/retrievers/remote");
|
|
4
5
|
const document_js_1 = require("../../document.cjs");
|
|
5
|
-
const base_js_1 = require("./base.cjs");
|
|
6
6
|
/**
|
|
7
|
+
* @deprecated Use RemoteRetriever instead.
|
|
7
8
|
* Specific implementation of the `RemoteRetriever` class designed to
|
|
8
9
|
* retrieve documents from a remote source using a JSON-based API. It
|
|
9
10
|
* implements the `RemoteLangChainRetrieverParams` interface which defines
|
|
10
11
|
* the keys used to interact with the JSON API.
|
|
11
12
|
*/
|
|
12
|
-
class RemoteLangChainRetriever extends
|
|
13
|
+
class RemoteLangChainRetriever extends remote_1.RemoteRetriever {
|
|
13
14
|
constructor({ inputKey = "message", responseKey = "response", pageContentKey = "page_content", metadataKey = "metadata", ...rest }) {
|
|
14
15
|
super(rest);
|
|
15
16
|
Object.defineProperty(this, "lc_namespace", {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { RemoteRetriever, RemoteRetrieverParams, RemoteRetrieverValues } from "@langchain/community/retrievers/remote";
|
|
1
2
|
import { Document } from "../../document.js";
|
|
2
|
-
|
|
3
|
+
/** @deprecated */
|
|
3
4
|
export interface RemoteLangChainRetrieverParams extends RemoteRetrieverParams {
|
|
4
5
|
/**
|
|
5
6
|
* The key in the JSON body to put the query in
|
|
@@ -19,6 +20,7 @@ export interface RemoteLangChainRetrieverParams extends RemoteRetrieverParams {
|
|
|
19
20
|
metadataKey?: string;
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
23
|
+
* @deprecated Use RemoteRetriever instead.
|
|
22
24
|
* Specific implementation of the `RemoteRetriever` class designed to
|
|
23
25
|
* retrieve documents from a remote source using a JSON-based API. It
|
|
24
26
|
* implements the `RemoteLangChainRetrieverParams` interface which defines
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { RemoteRetriever, } from "@langchain/community/retrievers/remote";
|
|
1
2
|
import { Document } from "../../document.js";
|
|
2
|
-
import { RemoteRetriever, } from "./base.js";
|
|
3
3
|
/**
|
|
4
|
+
* @deprecated Use RemoteRetriever instead.
|
|
4
5
|
* Specific implementation of the `RemoteRetriever` class designed to
|
|
5
6
|
* retrieve documents from a remote source using a JSON-based API. It
|
|
6
7
|
* implements the `RemoteLangChainRetrieverParams` interface which defines
|