langchain 0.0.212 → 0.0.213
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/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 +78 -2
- package/dist/agents/{openai → openai_functions}/index.d.ts +75 -3
- package/dist/agents/{openai → openai_functions}/index.js +76 -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 +81 -0
- package/dist/agents/openai_tools/index.d.ts +80 -0
- package/dist/agents/openai_tools/index.js +77 -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 +75 -0
- package/dist/agents/react/index.d.ts +60 -0
- package/dist/agents/react/index.js +71 -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 +85 -1
- package/dist/agents/structured_chat/index.d.ts +71 -0
- package/dist/agents/structured_chat/index.js +83 -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 +75 -1
- package/dist/agents/xml/index.d.ts +65 -0
- package/dist/agents/xml/index.js +73 -0
- 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/retrieval.cjs +60 -0
- package/dist/chains/retrieval.d.ts +65 -0
- package/dist/chains/retrieval.js +56 -0
- 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/tools/retriever.cjs +17 -0
- package/dist/tools/retriever.d.ts +10 -0
- package/dist/tools/retriever.js +13 -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/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,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRetrievalChain = void 0;
|
|
4
|
+
const runnables_1 = require("@langchain/core/runnables");
|
|
5
|
+
function isBaseRetriever(x) {
|
|
6
|
+
return (!!x &&
|
|
7
|
+
typeof x.getRelevantDocuments === "function");
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create a retrieval chain that retrieves documents and then passes them on.
|
|
11
|
+
* @param {CreateRetrievalChainParams} params A params object
|
|
12
|
+
* containing a retriever and a combineDocsChain.
|
|
13
|
+
* @returns An LCEL Runnable which returns a an object
|
|
14
|
+
* containing at least `context` and `answer` keys.
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // yarn add langchain @langchain/openai
|
|
18
|
+
*
|
|
19
|
+
* import { ChatOpenAI } from "@langchain/openai";
|
|
20
|
+
* import { pull } from "langchain/hub";
|
|
21
|
+
* import { createRetrievalChain } from "langchain/chains/retrieval";
|
|
22
|
+
* import { createStuffDocumentsChain } from "langchain/chains/combine_documents";
|
|
23
|
+
*
|
|
24
|
+
* const retrievalQAChatPrompt = await pull("langchain-ai/retrieval-qa-chat");
|
|
25
|
+
* const llm = new ChatOpenAI({});
|
|
26
|
+
* const retriever = ...
|
|
27
|
+
* const combineDocsChain = await createStuffDocumentsChain(...);
|
|
28
|
+
* const retrievalChain = await createRetrievalChain({
|
|
29
|
+
* retriever,
|
|
30
|
+
* combineDocsChain,
|
|
31
|
+
* });
|
|
32
|
+
* const response = await chain.invoke({ input: "..." });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
async function createRetrievalChain({ retriever, combineDocsChain, }) {
|
|
36
|
+
let retrieveDocumentsChain;
|
|
37
|
+
if (isBaseRetriever(retriever)) {
|
|
38
|
+
retrieveDocumentsChain = runnables_1.RunnableSequence.from([
|
|
39
|
+
(input) => input.input,
|
|
40
|
+
retriever,
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// TODO: Fix typing by adding withConfig to core RunnableInterface
|
|
45
|
+
retrieveDocumentsChain = retriever;
|
|
46
|
+
}
|
|
47
|
+
const retrievalChain = runnables_1.RunnableSequence.from([
|
|
48
|
+
runnables_1.RunnablePassthrough.assign({
|
|
49
|
+
context: retrieveDocumentsChain.withConfig({
|
|
50
|
+
runName: "retrieve_documents",
|
|
51
|
+
}),
|
|
52
|
+
chat_history: (input) => input.chat_history ?? [],
|
|
53
|
+
}),
|
|
54
|
+
runnables_1.RunnablePassthrough.assign({
|
|
55
|
+
answer: combineDocsChain,
|
|
56
|
+
}),
|
|
57
|
+
]).withConfig({ runName: "retrieval_chain" });
|
|
58
|
+
return retrievalChain;
|
|
59
|
+
}
|
|
60
|
+
exports.createRetrievalChain = createRetrievalChain;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { BaseRetrieverInterface } from "@langchain/core/retrievers";
|
|
2
|
+
import { type RunnableInterface } from "@langchain/core/runnables";
|
|
3
|
+
import type { BaseMessage } from "@langchain/core/messages";
|
|
4
|
+
import type { DocumentInterface } from "@langchain/core/documents";
|
|
5
|
+
/**
|
|
6
|
+
* Parameters for the createRetrievalChain method.
|
|
7
|
+
*/
|
|
8
|
+
export type CreateRetrievalChainParams<RunOutput> = {
|
|
9
|
+
/**
|
|
10
|
+
* Retriever-like object that returns list of documents. Should
|
|
11
|
+
* either be a subclass of BaseRetriever or a Runnable that returns
|
|
12
|
+
* a list of documents. If a subclass of BaseRetriever, then it
|
|
13
|
+
* is expected that an `input` key be passed in - this is what
|
|
14
|
+
* is will be used to pass into the retriever. If this is NOT a
|
|
15
|
+
* subclass of BaseRetriever, then all the inputs will be passed
|
|
16
|
+
* into this runnable, meaning that runnable should take a object
|
|
17
|
+
* as input.
|
|
18
|
+
*/
|
|
19
|
+
retriever: BaseRetrieverInterface | RunnableInterface<Record<string, any>, DocumentInterface[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Runnable that takes inputs and produces a string output.
|
|
22
|
+
* The inputs to this will be any original inputs to this chain, a new
|
|
23
|
+
* context key with the retrieved documents, and chat_history (if not present
|
|
24
|
+
* in the inputs) with a value of `[]` (to easily enable conversational
|
|
25
|
+
* retrieval).
|
|
26
|
+
*/
|
|
27
|
+
combineDocsChain: RunnableInterface<Record<string, any>, RunOutput>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Create a retrieval chain that retrieves documents and then passes them on.
|
|
31
|
+
* @param {CreateRetrievalChainParams} params A params object
|
|
32
|
+
* containing a retriever and a combineDocsChain.
|
|
33
|
+
* @returns An LCEL Runnable which returns a an object
|
|
34
|
+
* containing at least `context` and `answer` keys.
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // yarn add langchain @langchain/openai
|
|
38
|
+
*
|
|
39
|
+
* import { ChatOpenAI } from "@langchain/openai";
|
|
40
|
+
* import { pull } from "langchain/hub";
|
|
41
|
+
* import { createRetrievalChain } from "langchain/chains/retrieval";
|
|
42
|
+
* import { createStuffDocumentsChain } from "langchain/chains/combine_documents";
|
|
43
|
+
*
|
|
44
|
+
* const retrievalQAChatPrompt = await pull("langchain-ai/retrieval-qa-chat");
|
|
45
|
+
* const llm = new ChatOpenAI({});
|
|
46
|
+
* const retriever = ...
|
|
47
|
+
* const combineDocsChain = await createStuffDocumentsChain(...);
|
|
48
|
+
* const retrievalChain = await createRetrievalChain({
|
|
49
|
+
* retriever,
|
|
50
|
+
* combineDocsChain,
|
|
51
|
+
* });
|
|
52
|
+
* const response = await chain.invoke({ input: "..." });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function createRetrievalChain<RunOutput>({ retriever, combineDocsChain, }: CreateRetrievalChainParams<RunOutput>): Promise<RunnableInterface<{
|
|
56
|
+
input: string;
|
|
57
|
+
chat_history?: BaseMessage[] | string;
|
|
58
|
+
} & {
|
|
59
|
+
[key: string]: unknown;
|
|
60
|
+
}, {
|
|
61
|
+
context: string;
|
|
62
|
+
answer: RunOutput;
|
|
63
|
+
} & {
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
}>>;
|
|
@@ -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
|
+
}
|
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,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRetrieverTool = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const dynamic_1 = require("@langchain/community/tools/dynamic");
|
|
6
|
+
const document_js_1 = require("../util/document.cjs");
|
|
7
|
+
function createRetrieverTool(retriever, input) {
|
|
8
|
+
const func = async ({ query }, runManager) => {
|
|
9
|
+
const docs = await retriever.getRelevantDocuments(query, runManager?.getChild("retriever"));
|
|
10
|
+
return (0, document_js_1.formatDocumentsAsString)(docs);
|
|
11
|
+
};
|
|
12
|
+
const schema = zod_1.z.object({
|
|
13
|
+
query: zod_1.z.string().describe("query to look up in retriever"),
|
|
14
|
+
});
|
|
15
|
+
return new dynamic_1.DynamicStructuredTool({ ...input, func, schema });
|
|
16
|
+
}
|
|
17
|
+
exports.createRetrieverTool = createRetrieverTool;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BaseRetrieverInterface } from "@langchain/core/retrievers";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { DynamicStructuredTool, type DynamicStructuredToolInput } from "@langchain/community/tools/dynamic";
|
|
4
|
+
export declare function createRetrieverTool(retriever: BaseRetrieverInterface, input: Omit<DynamicStructuredToolInput, "func" | "schema">): DynamicStructuredTool<z.ZodObject<{
|
|
5
|
+
query: z.ZodString;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
query: string;
|
|
8
|
+
}, {
|
|
9
|
+
query: string;
|
|
10
|
+
}>>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DynamicStructuredTool, } from "@langchain/community/tools/dynamic";
|
|
3
|
+
import { formatDocumentsAsString } from "../util/document.js";
|
|
4
|
+
export function createRetrieverTool(retriever, input) {
|
|
5
|
+
const func = async ({ query }, runManager) => {
|
|
6
|
+
const docs = await retriever.getRelevantDocuments(query, runManager?.getChild("retriever"));
|
|
7
|
+
return formatDocumentsAsString(docs);
|
|
8
|
+
};
|
|
9
|
+
const schema = z.object({
|
|
10
|
+
query: z.string().describe("query to look up in retriever"),
|
|
11
|
+
});
|
|
12
|
+
return new DynamicStructuredTool({ ...input, func, schema });
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.213",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -79,6 +79,9 @@
|
|
|
79
79
|
"tools/render.cjs",
|
|
80
80
|
"tools/render.js",
|
|
81
81
|
"tools/render.d.ts",
|
|
82
|
+
"tools/retriever.cjs",
|
|
83
|
+
"tools/retriever.js",
|
|
84
|
+
"tools/retriever.d.ts",
|
|
82
85
|
"tools/sql.cjs",
|
|
83
86
|
"tools/sql.js",
|
|
84
87
|
"tools/sql.d.ts",
|
|
@@ -97,9 +100,15 @@
|
|
|
97
100
|
"chains.cjs",
|
|
98
101
|
"chains.js",
|
|
99
102
|
"chains.d.ts",
|
|
103
|
+
"chains/combine_documents.cjs",
|
|
104
|
+
"chains/combine_documents.js",
|
|
105
|
+
"chains/combine_documents.d.ts",
|
|
100
106
|
"chains/combine_documents/reduce.cjs",
|
|
101
107
|
"chains/combine_documents/reduce.js",
|
|
102
108
|
"chains/combine_documents/reduce.d.ts",
|
|
109
|
+
"chains/history_aware_retriever.cjs",
|
|
110
|
+
"chains/history_aware_retriever.js",
|
|
111
|
+
"chains/history_aware_retriever.d.ts",
|
|
103
112
|
"chains/load.cjs",
|
|
104
113
|
"chains/load.js",
|
|
105
114
|
"chains/load.d.ts",
|
|
@@ -112,6 +121,9 @@
|
|
|
112
121
|
"chains/query_constructor/ir.cjs",
|
|
113
122
|
"chains/query_constructor/ir.js",
|
|
114
123
|
"chains/query_constructor/ir.d.ts",
|
|
124
|
+
"chains/retrieval.cjs",
|
|
125
|
+
"chains/retrieval.js",
|
|
126
|
+
"chains/retrieval.d.ts",
|
|
115
127
|
"chains/sql_db.cjs",
|
|
116
128
|
"chains/sql_db.js",
|
|
117
129
|
"chains/sql_db.d.ts",
|
|
@@ -1178,9 +1190,9 @@
|
|
|
1178
1190
|
},
|
|
1179
1191
|
"dependencies": {
|
|
1180
1192
|
"@anthropic-ai/sdk": "^0.9.1",
|
|
1181
|
-
"@langchain/community": "~0.0.
|
|
1182
|
-
"@langchain/core": "~0.1.
|
|
1183
|
-
"@langchain/openai": "~0.0.
|
|
1193
|
+
"@langchain/community": "~0.0.12",
|
|
1194
|
+
"@langchain/core": "~0.1.5",
|
|
1195
|
+
"@langchain/openai": "~0.0.9",
|
|
1184
1196
|
"binary-extensions": "^2.2.0",
|
|
1185
1197
|
"expr-eval": "^2.0.2",
|
|
1186
1198
|
"js-tiktoken": "^1.0.7",
|
|
@@ -1329,6 +1341,11 @@
|
|
|
1329
1341
|
"import": "./tools/render.js",
|
|
1330
1342
|
"require": "./tools/render.cjs"
|
|
1331
1343
|
},
|
|
1344
|
+
"./tools/retriever": {
|
|
1345
|
+
"types": "./tools/retriever.d.ts",
|
|
1346
|
+
"import": "./tools/retriever.js",
|
|
1347
|
+
"require": "./tools/retriever.cjs"
|
|
1348
|
+
},
|
|
1332
1349
|
"./tools/sql": {
|
|
1333
1350
|
"types": "./tools/sql.d.ts",
|
|
1334
1351
|
"import": "./tools/sql.js",
|
|
@@ -1359,11 +1376,21 @@
|
|
|
1359
1376
|
"import": "./chains.js",
|
|
1360
1377
|
"require": "./chains.cjs"
|
|
1361
1378
|
},
|
|
1379
|
+
"./chains/combine_documents": {
|
|
1380
|
+
"types": "./chains/combine_documents.d.ts",
|
|
1381
|
+
"import": "./chains/combine_documents.js",
|
|
1382
|
+
"require": "./chains/combine_documents.cjs"
|
|
1383
|
+
},
|
|
1362
1384
|
"./chains/combine_documents/reduce": {
|
|
1363
1385
|
"types": "./chains/combine_documents/reduce.d.ts",
|
|
1364
1386
|
"import": "./chains/combine_documents/reduce.js",
|
|
1365
1387
|
"require": "./chains/combine_documents/reduce.cjs"
|
|
1366
1388
|
},
|
|
1389
|
+
"./chains/history_aware_retriever": {
|
|
1390
|
+
"types": "./chains/history_aware_retriever.d.ts",
|
|
1391
|
+
"import": "./chains/history_aware_retriever.js",
|
|
1392
|
+
"require": "./chains/history_aware_retriever.cjs"
|
|
1393
|
+
},
|
|
1367
1394
|
"./chains/load": {
|
|
1368
1395
|
"types": "./chains/load.d.ts",
|
|
1369
1396
|
"import": "./chains/load.js",
|
|
@@ -1384,6 +1411,11 @@
|
|
|
1384
1411
|
"import": "./chains/query_constructor/ir.js",
|
|
1385
1412
|
"require": "./chains/query_constructor/ir.cjs"
|
|
1386
1413
|
},
|
|
1414
|
+
"./chains/retrieval": {
|
|
1415
|
+
"types": "./chains/retrieval.d.ts",
|
|
1416
|
+
"import": "./chains/retrieval.js",
|
|
1417
|
+
"require": "./chains/retrieval.cjs"
|
|
1418
|
+
},
|
|
1387
1419
|
"./chains/sql_db": {
|
|
1388
1420
|
"types": "./chains/sql_db.d.ts",
|
|
1389
1421
|
"import": "./chains/sql_db.js",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/tools/retriever.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/tools/retriever.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/tools/retriever.js'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|