langchain 0.2.14 → 0.2.16

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.
Files changed (35) hide show
  1. package/dist/agents/chat/index.cjs +1 -1
  2. package/dist/agents/chat/index.d.ts +1 -1
  3. package/dist/agents/chat/index.js +1 -1
  4. package/dist/agents/chat_convo/index.cjs +1 -1
  5. package/dist/agents/chat_convo/index.d.ts +1 -1
  6. package/dist/agents/chat_convo/index.js +1 -1
  7. package/dist/agents/mrkl/index.cjs +1 -1
  8. package/dist/agents/mrkl/index.d.ts +1 -1
  9. package/dist/agents/mrkl/index.js +1 -1
  10. package/dist/agents/openai_functions/index.cjs +1 -1
  11. package/dist/agents/openai_functions/index.d.ts +1 -1
  12. package/dist/agents/openai_functions/index.js +1 -1
  13. package/dist/agents/structured_chat/index.cjs +1 -1
  14. package/dist/agents/structured_chat/index.d.ts +1 -1
  15. package/dist/agents/structured_chat/index.js +1 -1
  16. package/dist/agents/tool_calling/index.cjs +14 -3
  17. package/dist/agents/tool_calling/index.d.ts +2 -3
  18. package/dist/agents/tool_calling/index.js +14 -3
  19. package/dist/agents/xml/index.cjs +1 -1
  20. package/dist/agents/xml/index.d.ts +1 -1
  21. package/dist/agents/xml/index.js +1 -1
  22. package/dist/chains/load.cjs +1 -1
  23. package/dist/chains/load.d.ts +1 -1
  24. package/dist/chains/load.js +1 -1
  25. package/dist/chains/openai_functions/structured_output.cjs +2 -2
  26. package/dist/chains/openai_functions/structured_output.d.ts +2 -2
  27. package/dist/chains/openai_functions/structured_output.js +2 -2
  28. package/dist/chains/retrieval_qa.cjs +1 -1
  29. package/dist/chains/retrieval_qa.d.ts +1 -1
  30. package/dist/chains/retrieval_qa.js +1 -1
  31. package/dist/chains/serde.d.ts +12 -12
  32. package/dist/retrievers/self_query/functional.d.ts +1 -1
  33. package/dist/retrievers/self_query/index.cjs +10 -2
  34. package/dist/retrievers/self_query/index.js +10 -2
  35. package/package.json +1 -1
@@ -11,7 +11,7 @@ const DEFAULT_HUMAN_MESSAGE_TEMPLATE = "{input}\n\n{agent_scratchpad}";
11
11
  * Agent for the MRKL chain.
12
12
  * @augments Agent
13
13
  *
14
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
14
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
15
15
  */
16
16
  class ChatAgent extends agent_js_1.Agent {
17
17
  static lc_name() {
@@ -33,7 +33,7 @@ export type ChatAgentInput = Optional<AgentInput, "outputParser">;
33
33
  * Agent for the MRKL chain.
34
34
  * @augments Agent
35
35
  *
36
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
36
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
37
37
  */
38
38
  export declare class ChatAgent extends Agent {
39
39
  static lc_name(): string;
@@ -8,7 +8,7 @@ const DEFAULT_HUMAN_MESSAGE_TEMPLATE = "{input}\n\n{agent_scratchpad}";
8
8
  * Agent for the MRKL chain.
9
9
  * @augments Agent
10
10
  *
11
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
11
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
12
12
  */
13
13
  export class ChatAgent extends Agent {
14
14
  static lc_name() {
@@ -11,7 +11,7 @@ const prompt_js_1 = require("./prompt.cjs");
11
11
  * Agent for the MRKL chain.
12
12
  * @augments Agent
13
13
  *
14
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
14
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
15
15
  */
16
16
  class ChatConversationalAgent extends agent_js_1.Agent {
17
17
  static lc_name() {
@@ -30,7 +30,7 @@ export type ChatConversationalAgentInput = Optional<AgentInput, "outputParser">;
30
30
  * Agent for the MRKL chain.
31
31
  * @augments Agent
32
32
  *
33
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
33
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
34
34
  */
35
35
  export declare class ChatConversationalAgent extends Agent {
36
36
  static lc_name(): string;
@@ -8,7 +8,7 @@ import { PREFIX_END, DEFAULT_PREFIX, DEFAULT_SUFFIX, TEMPLATE_TOOL_RESPONSE, } f
8
8
  * Agent for the MRKL chain.
9
9
  * @augments Agent
10
10
  *
11
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
11
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
12
12
  */
13
13
  export class ChatConversationalAgent extends Agent {
14
14
  static lc_name() {
@@ -32,7 +32,7 @@ const prompt_js_1 = require("./prompt.cjs");
32
32
  * });
33
33
  * ```
34
34
  *
35
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createReactAgent.html | createReactAgent method instead}.
35
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createReactAgent.html | createReactAgent method instead}.
36
36
  */
37
37
  class ZeroShotAgent extends agent_js_1.Agent {
38
38
  static lc_name() {
@@ -46,7 +46,7 @@ export type ZeroShotAgentInput = Optional<AgentInput, "outputParser">;
46
46
  * });
47
47
  * ```
48
48
  *
49
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createReactAgent.html | createReactAgent method instead}.
49
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createReactAgent.html | createReactAgent method instead}.
50
50
  */
51
51
  export declare class ZeroShotAgent extends Agent {
52
52
  static lc_name(): string;
@@ -29,7 +29,7 @@ import { FORMAT_INSTRUCTIONS, PREFIX, SUFFIX } from "./prompt.js";
29
29
  * });
30
30
  * ```
31
31
  *
32
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createReactAgent.html | createReactAgent method instead}.
32
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createReactAgent.html | createReactAgent method instead}.
33
33
  */
34
34
  export class ZeroShotAgent extends Agent {
35
35
  static lc_name() {
@@ -35,7 +35,7 @@ exports._formatIntermediateSteps = _formatIntermediateSteps;
35
35
  * extends the Agent class and provides additional functionality specific
36
36
  * to the OpenAIAgent type.
37
37
  *
38
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createOpenAIFunctionsAgent.html | createOpenAIFunctionsAgent method instead}.
38
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createOpenAIFunctionsAgent.html | createOpenAIFunctionsAgent method instead}.
39
39
  */
40
40
  class OpenAIAgent extends agent_js_1.Agent {
41
41
  static lc_name() {
@@ -29,7 +29,7 @@ export interface OpenAIAgentCreatePromptArgs {
29
29
  * extends the Agent class and provides additional functionality specific
30
30
  * to the OpenAIAgent type.
31
31
  *
32
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createOpenAIFunctionsAgent.html | createOpenAIFunctionsAgent method instead}.
32
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createOpenAIFunctionsAgent.html | createOpenAIFunctionsAgent method instead}.
33
33
  */
34
34
  export declare class OpenAIAgent extends Agent {
35
35
  static lc_name(): string;
@@ -31,7 +31,7 @@ export function _formatIntermediateSteps(intermediateSteps) {
31
31
  * extends the Agent class and provides additional functionality specific
32
32
  * to the OpenAIAgent type.
33
33
  *
34
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createOpenAIFunctionsAgent.html | createOpenAIFunctionsAgent method instead}.
34
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createOpenAIFunctionsAgent.html | createOpenAIFunctionsAgent method instead}.
35
35
  */
36
36
  export class OpenAIAgent extends Agent {
37
37
  static lc_name() {
@@ -15,7 +15,7 @@ const log_js_1 = require("../format_scratchpad/log.cjs");
15
15
  /**
16
16
  * Agent that interoperates with Structured Tools using React logic.
17
17
  * @augments Agent
18
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
18
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
19
19
  */
20
20
  class StructuredChatAgent extends agent_js_1.Agent {
21
21
  static lc_name() {
@@ -31,7 +31,7 @@ export type StructuredChatAgentInput = Optional<AgentInput, "outputParser">;
31
31
  /**
32
32
  * Agent that interoperates with Structured Tools using React logic.
33
33
  * @augments Agent
34
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
34
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
35
35
  */
36
36
  export declare class StructuredChatAgent extends Agent {
37
37
  static lc_name(): string;
@@ -12,7 +12,7 @@ import { formatLogToString } from "../format_scratchpad/log.js";
12
12
  /**
13
13
  * Agent that interoperates with Structured Tools using React logic.
14
14
  * @augments Agent
15
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
15
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createStructuredChatAgent.html | createStructuredChatAgent method instead}.
16
16
  */
17
17
  export class StructuredChatAgent extends Agent {
18
18
  static lc_name() {
@@ -5,6 +5,11 @@ const runnables_1 = require("@langchain/core/runnables");
5
5
  const agent_js_1 = require("../agent.cjs");
6
6
  const output_parser_js_1 = require("./output_parser.cjs");
7
7
  const tool_calling_js_1 = require("../format_scratchpad/tool_calling.cjs");
8
+ function _isBaseChatModel(x) {
9
+ const model = x;
10
+ return (typeof model._modelType === "function" &&
11
+ model._modelType() === "base_chat_model");
12
+ }
8
13
  /**
9
14
  * Create an agent that uses tools.
10
15
  * @param params Params required to create the agent. Includes an LLM, tools, and prompt.
@@ -62,10 +67,16 @@ function createToolCallingAgent({ llm, tools, prompt, streamRunnable, }) {
62
67
  `Found ${JSON.stringify(prompt.inputVariables)} instead.`,
63
68
  ].join("\n"));
64
69
  }
65
- if (llm.bindTools === undefined) {
66
- throw new Error(`This agent requires that the "bind_tools()" method be implemented on the input model.`);
70
+ let modelWithTools;
71
+ if (_isBaseChatModel(llm)) {
72
+ if (llm.bindTools === undefined) {
73
+ throw new Error(`This agent requires that the "bind_tools()" method be implemented on the input model.`);
74
+ }
75
+ modelWithTools = llm.bindTools(tools);
76
+ }
77
+ else {
78
+ modelWithTools = llm;
67
79
  }
68
- const modelWithTools = llm.bindTools(tools);
69
80
  const agent = agent_js_1.AgentRunnableSequence.fromRunnables([
70
81
  runnables_1.RunnablePassthrough.assign({
71
82
  agent_scratchpad: (input) => (0, tool_calling_js_1.formatToToolMessages)(input.steps),
@@ -1,7 +1,6 @@
1
- import { BaseChatModel } from "@langchain/core/language_models/chat_models";
2
1
  import { ChatPromptTemplate } from "@langchain/core/prompts";
3
2
  import { StructuredToolInterface } from "@langchain/core/tools";
4
- import { ToolDefinition } from "@langchain/core/language_models/base";
3
+ import { LanguageModelLike, ToolDefinition } from "@langchain/core/language_models/base";
5
4
  import { AgentRunnableSequence } from "../agent.js";
6
5
  import { ToolsAgentStep } from "./output_parser.js";
7
6
  /**
@@ -13,7 +12,7 @@ export type CreateToolCallingAgentParams = {
13
12
  * so must either be an OpenAI model that supports that or a wrapper of
14
13
  * a different model that adds in equivalent support.
15
14
  */
16
- llm: BaseChatModel;
15
+ llm: LanguageModelLike;
17
16
  /** Tools this agent has access to. */
18
17
  tools: StructuredToolInterface[] | ToolDefinition[];
19
18
  /** The prompt to use, must have an input key of `agent_scratchpad`. */
@@ -2,6 +2,11 @@ import { RunnablePassthrough } from "@langchain/core/runnables";
2
2
  import { AgentRunnableSequence } from "../agent.js";
3
3
  import { ToolCallingAgentOutputParser, } from "./output_parser.js";
4
4
  import { formatToToolMessages } from "../format_scratchpad/tool_calling.js";
5
+ function _isBaseChatModel(x) {
6
+ const model = x;
7
+ return (typeof model._modelType === "function" &&
8
+ model._modelType() === "base_chat_model");
9
+ }
5
10
  /**
6
11
  * Create an agent that uses tools.
7
12
  * @param params Params required to create the agent. Includes an LLM, tools, and prompt.
@@ -59,10 +64,16 @@ export function createToolCallingAgent({ llm, tools, prompt, streamRunnable, })
59
64
  `Found ${JSON.stringify(prompt.inputVariables)} instead.`,
60
65
  ].join("\n"));
61
66
  }
62
- if (llm.bindTools === undefined) {
63
- throw new Error(`This agent requires that the "bind_tools()" method be implemented on the input model.`);
67
+ let modelWithTools;
68
+ if (_isBaseChatModel(llm)) {
69
+ if (llm.bindTools === undefined) {
70
+ throw new Error(`This agent requires that the "bind_tools()" method be implemented on the input model.`);
71
+ }
72
+ modelWithTools = llm.bindTools(tools);
73
+ }
74
+ else {
75
+ modelWithTools = llm;
64
76
  }
65
- const modelWithTools = llm.bindTools(tools);
66
77
  const agent = AgentRunnableSequence.fromRunnables([
67
78
  RunnablePassthrough.assign({
68
79
  agent_scratchpad: (input) => formatToToolMessages(input.steps),
@@ -12,7 +12,7 @@ const xml_js_1 = require("../format_scratchpad/xml.cjs");
12
12
  /**
13
13
  * Class that represents an agent that uses XML tags.
14
14
  *
15
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createXmlAgent.html | createXmlAgent method instead}.
15
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createXmlAgent.html | createXmlAgent method instead}.
16
16
  */
17
17
  class XMLAgent extends agent_js_1.BaseSingleActionAgent {
18
18
  static lc_name() {
@@ -18,7 +18,7 @@ export interface XMLAgentInput {
18
18
  /**
19
19
  * Class that represents an agent that uses XML tags.
20
20
  *
21
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createXmlAgent.html | createXmlAgent method instead}.
21
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createXmlAgent.html | createXmlAgent method instead}.
22
22
  */
23
23
  export declare class XMLAgent extends BaseSingleActionAgent implements XMLAgentInput {
24
24
  static lc_name(): string;
@@ -9,7 +9,7 @@ import { formatXml } from "../format_scratchpad/xml.js";
9
9
  /**
10
10
  * Class that represents an agent that uses XML tags.
11
11
  *
12
- * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain_agents.createXmlAgent.html | createXmlAgent method instead}.
12
+ * @deprecated Use the {@link https://v02.api.js.langchain.com/functions/langchain.agents.createXmlAgent.html | createXmlAgent method instead}.
13
13
  */
14
14
  export class XMLAgent extends BaseSingleActionAgent {
15
15
  static lc_name() {
@@ -27,7 +27,7 @@ const loadChainFromFile = async (file, path, values = {}) => {
27
27
  * const chain = await loadChain("/path/to/chain.json");
28
28
  * ```
29
29
  *
30
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | load method}.
30
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | load method}.
31
31
  */
32
32
  const loadChain = async (uri, values = {}) => {
33
33
  const hubResult = await (0, hub_js_1.loadFromHub)(uri, loadChainFromFile, "chains", new Set(["json", "yaml"]), values);
@@ -18,6 +18,6 @@ import { LoadValues } from "../util/load.js";
18
18
  * const chain = await loadChain("/path/to/chain.json");
19
19
  * ```
20
20
  *
21
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | load method}.
21
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | load method}.
22
22
  */
23
23
  export declare const loadChain: (uri: string, values?: LoadValues) => Promise<BaseChain>;
@@ -24,7 +24,7 @@ const loadChainFromFile = async (file, path, values = {}) => {
24
24
  * const chain = await loadChain("/path/to/chain.json");
25
25
  * ```
26
26
  *
27
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | load method}.
27
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | load method}.
28
28
  */
29
29
  export const loadChain = async (uri, values = {}) => {
30
30
  const hubResult = await loadFromHub(uri, loadChainFromFile, "chains", new Set(["json", "yaml"]), values);
@@ -102,7 +102,7 @@ class FunctionCallStructuredOutputParser extends output_parsers_1.BaseLLMOutputP
102
102
  }
103
103
  exports.FunctionCallStructuredOutputParser = FunctionCallStructuredOutputParser;
104
104
  /**
105
- * @deprecated Use {@link https://v02.api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead
105
+ * @deprecated Use {@link https://v02.api.js.langchain.com/functions/langchain.chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead
106
106
  * Create a chain that returns output matching a JSON Schema.
107
107
  * @param input Object that includes all LLMChainInput fields except "outputParser"
108
108
  * as well as an additional required "outputSchema" JSON Schema object.
@@ -138,7 +138,7 @@ function createStructuredOutputChain(input) {
138
138
  });
139
139
  }
140
140
  exports.createStructuredOutputChain = createStructuredOutputChain;
141
- /** @deprecated Use {@link https://v02.api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
141
+ /** @deprecated Use {@link https://v02.api.js.langchain.com/functions/langchain.chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
142
142
  function createStructuredOutputChainFromZod(zodSchema, input) {
143
143
  return createStructuredOutputChain({
144
144
  ...input,
@@ -49,12 +49,12 @@ export declare class FunctionCallStructuredOutputParser<T extends z.AnyZodObject
49
49
  parseResult(generations: ChatGeneration[]): Promise<any>;
50
50
  }
51
51
  /**
52
- * @deprecated Use {@link https://v02.api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead
52
+ * @deprecated Use {@link https://v02.api.js.langchain.com/functions/langchain.chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead
53
53
  * Create a chain that returns output matching a JSON Schema.
54
54
  * @param input Object that includes all LLMChainInput fields except "outputParser"
55
55
  * as well as an additional required "outputSchema" JSON Schema object.
56
56
  * @returns OpenAPIChain
57
57
  */
58
58
  export declare function createStructuredOutputChain<T extends z.AnyZodObject = z.AnyZodObject>(input: StructuredOutputChainInput<T>): LLMChain<any, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").BaseMessageChunk> | ChatOpenAI<BaseFunctionCallOptions>>;
59
- /** @deprecated Use {@link https://v02.api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
59
+ /** @deprecated Use {@link https://v02.api.js.langchain.com/functions/langchain.chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
60
60
  export declare function createStructuredOutputChainFromZod<T extends z.AnyZodObject>(zodSchema: T, input: Omit<StructuredOutputChainInput<T>, "outputSchema">): LLMChain<any, BaseChatModel<BaseFunctionCallOptions, import("@langchain/core/messages").BaseMessageChunk> | ChatOpenAI<BaseFunctionCallOptions>>;
@@ -98,7 +98,7 @@ export class FunctionCallStructuredOutputParser extends BaseLLMOutputParser {
98
98
  }
99
99
  }
100
100
  /**
101
- * @deprecated Use {@link https://v02.api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead
101
+ * @deprecated Use {@link https://v02.api.js.langchain.com/functions/langchain.chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead
102
102
  * Create a chain that returns output matching a JSON Schema.
103
103
  * @param input Object that includes all LLMChainInput fields except "outputParser"
104
104
  * as well as an additional required "outputSchema" JSON Schema object.
@@ -133,7 +133,7 @@ export function createStructuredOutputChain(input) {
133
133
  ...rest,
134
134
  });
135
135
  }
136
- /** @deprecated Use {@link https://v02.api.js.langchain.com/functions/langchain_chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
136
+ /** @deprecated Use {@link https://v02.api.js.langchain.com/functions/langchain.chains_openai_functions.createStructuredOutputRunnable.html | createStructuredOutputRunnable} instead */
137
137
  export function createStructuredOutputChainFromZod(zodSchema, input) {
138
138
  return createStructuredOutputChain({
139
139
  ...input,
@@ -23,7 +23,7 @@ const load_js_1 = require("./question_answering/load.cjs");
23
23
  * documents,
24
24
  * embeddings
25
25
  * );
26
- * const prompt = ChatPromptTemplate.fromTemplate(`Answer the user's question: {input}`);
26
+ * const prompt = ChatPromptTemplate.fromTemplate(`Answer the user's question: {input} based on the following context {context}`);
27
27
  *
28
28
  * const combineDocsChain = await createStuffDocumentsChain({
29
29
  * llm,
@@ -35,7 +35,7 @@ export interface RetrievalQAChainInput extends Omit<ChainInputs, "memory"> {
35
35
  * documents,
36
36
  * embeddings
37
37
  * );
38
- * const prompt = ChatPromptTemplate.fromTemplate(`Answer the user's question: {input}`);
38
+ * const prompt = ChatPromptTemplate.fromTemplate(`Answer the user's question: {input} based on the following context {context}`);
39
39
  *
40
40
  * const combineDocsChain = await createStuffDocumentsChain({
41
41
  * llm,
@@ -20,7 +20,7 @@ import { loadQAStuffChain, } from "./question_answering/load.js";
20
20
  * documents,
21
21
  * embeddings
22
22
  * );
23
- * const prompt = ChatPromptTemplate.fromTemplate(`Answer the user's question: {input}`);
23
+ * const prompt = ChatPromptTemplate.fromTemplate(`Answer the user's question: {input} based on the following context {context}`);
24
24
  *
25
25
  * const combineDocsChain = await createStuffDocumentsChain({
26
26
  * llm,
@@ -4,7 +4,7 @@ import { SerializedBasePromptTemplate } from "@langchain/core/prompts";
4
4
  * Represents the serialized form of an LLMChain. It includes properties
5
5
  * such as `_type`, `llm`, and `prompt`.
6
6
  *
7
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | serialization methods}.
7
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | serialization methods}.
8
8
  */
9
9
  export type SerializedLLMChain = {
10
10
  _type: "llm_chain";
@@ -16,7 +16,7 @@ export type SerializedLLMChain = {
16
16
  * properties such as `_type`, `input_variables`, `output_variables`, and
17
17
  * `chains`.
18
18
  *
19
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | serialization methods}.
19
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | serialization methods}.
20
20
  */
21
21
  export type SerializedSequentialChain = {
22
22
  _type: "sequential_chain";
@@ -28,7 +28,7 @@ export type SerializedSequentialChain = {
28
28
  * Represents the serialized form of a SimpleSequentialChain. It includes
29
29
  * properties such as `_type` and `chains`.
30
30
  *
31
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | serialization methods}.
31
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | serialization methods}.
32
32
  */
33
33
  export type SerializedSimpleSequentialChain = {
34
34
  _type: "simple_sequential_chain";
@@ -38,7 +38,7 @@ export type SerializedSimpleSequentialChain = {
38
38
  * Represents the serialized form of a VectorDBQAChain. It includes
39
39
  * properties such as `_type`, `k`, and `combine_documents_chain`.
40
40
  *
41
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | serialization methods}.
41
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | serialization methods}.
42
42
  */
43
43
  export type SerializedVectorDBQAChain = {
44
44
  _type: "vector_db_qa";
@@ -50,7 +50,7 @@ export type SerializedVectorDBQAChain = {
50
50
  * such as `_type`, `api_request_chain`, `api_answer_chain`, and
51
51
  * `api_docs`.
52
52
  *
53
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | serialization methods}.
53
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | serialization methods}.
54
54
  */
55
55
  export type SerializedAPIChain = {
56
56
  _type: "api_chain";
@@ -62,7 +62,7 @@ export type SerializedAPIChain = {
62
62
  * Represents the serialized form of a StuffDocumentsChain. It includes
63
63
  * properties such as `_type` and `llm_chain`.
64
64
  *
65
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | serialization methods}.
65
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | serialization methods}.
66
66
  */
67
67
  export type SerializedStuffDocumentsChain = {
68
68
  _type: "stuff_documents_chain";
@@ -73,7 +73,7 @@ export type SerializedStuffDocumentsChain = {
73
73
  * properties such as `_type`, `k`, `combine_documents_chain`, and
74
74
  * `question_generator`.
75
75
  *
76
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | serialization methods}.
76
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | serialization methods}.
77
77
  */
78
78
  export type SerializedChatVectorDBQAChain = {
79
79
  _type: "chat-vector-db";
@@ -86,7 +86,7 @@ export type SerializedChatVectorDBQAChain = {
86
86
  * includes properties such as `_type`, `llm_chain`, and
87
87
  * `combine_document_chain`.
88
88
  *
89
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | serialization methods}.
89
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | serialization methods}.
90
90
  */
91
91
  export type SerializedMapReduceDocumentsChain = {
92
92
  _type: "map_reduce_documents_chain";
@@ -97,7 +97,7 @@ export type SerializedMapReduceDocumentsChain = {
97
97
  * Represents the serialized form of a RefineDocumentsChain. It includes
98
98
  * properties such as `_type`, `llm_chain`, and `refine_llm_chain`.
99
99
  *
100
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | serialization methods}.
100
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | serialization methods}.
101
101
  */
102
102
  export type SerializedRefineDocumentsChain = {
103
103
  _type: "refine_documents_chain";
@@ -108,7 +108,7 @@ export type SerializedRefineDocumentsChain = {
108
108
  * Represents the serialized form of an AnalyzeDocumentChain. It includes
109
109
  * properties such as `_type` and `combine_document_chain`.
110
110
  *
111
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | serialization methods}.
111
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | serialization methods}.
112
112
  */
113
113
  export type SerializedAnalyzeDocumentChain = {
114
114
  _type: "analyze_document_chain";
@@ -119,7 +119,7 @@ export type SerializedAnalyzeDocumentChain = {
119
119
  * includes properties such as `_type`, `critiqueRequest`,
120
120
  * `revisionRequest`, and `name`.
121
121
  *
122
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | serialization methods}.
122
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | serialization methods}.
123
123
  */
124
124
  export type SerializedConstitutionalPrinciple = {
125
125
  _type: "constitutional_principle";
@@ -145,6 +145,6 @@ export type SerializedConstitutionalChain = {
145
145
  * Represents the serialized form of a BaseChain. It can be one of the
146
146
  * above serialized chain types.
147
147
  *
148
- * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain_load.load.html | serialization methods}.
148
+ * @deprecated Use newer {@link https://v02.api.js.langchain.com/functions/langchain.load.load.html | serialization methods}.
149
149
  */
150
150
  export type SerializedBaseChain = SerializedLLMChain | SerializedSequentialChain | SerializedSimpleSequentialChain | SerializedVectorDBQAChain | SerializedAPIChain | SerializedStuffDocumentsChain | SerializedChatVectorDBQAChain | SerializedMapReduceDocumentsChain | SerializedAnalyzeDocumentChain | SerializedRefineDocumentsChain | SerializedConstitutionalChain;
@@ -1 +1 @@
1
- export { FunctionFilter, FunctionalTranslator, } from "@langchain/core/structured_query";
1
+ export { type FunctionFilter, FunctionalTranslator, } from "@langchain/core/structured_query";
@@ -78,7 +78,10 @@ class SelfQueryRetriever extends retrievers_1.BaseRetriever {
78
78
  this.structuredQueryTranslator = options.structuredQueryTranslator;
79
79
  }
80
80
  async _getRelevantDocuments(query, runManager) {
81
- const generatedStructuredQuery = await this.queryConstructor.invoke({ query }, runManager?.getChild("query_constructor"));
81
+ const generatedStructuredQuery = await this.queryConstructor.invoke({ query }, {
82
+ callbacks: runManager?.getChild("query_constructor"),
83
+ runName: "query_constructor",
84
+ });
82
85
  const nextArg = this.structuredQueryTranslator.visitStructuredQuery(generatedStructuredQuery);
83
86
  const filter = this.structuredQueryTranslator.mergeFilters(this.searchParams?.filter, nextArg.filter, this.searchParams?.mergeFiltersOperator, this.searchParams?.forceDefaultFilter);
84
87
  const generatedQuery = generatedStructuredQuery.query;
@@ -86,7 +89,12 @@ class SelfQueryRetriever extends retrievers_1.BaseRetriever {
86
89
  if (!this.useOriginalQuery && generatedQuery && generatedQuery.length > 0) {
87
90
  myQuery = generatedQuery;
88
91
  }
89
- return this.vectorStore.similaritySearch(myQuery, this.searchParams?.k, filter, runManager?.getChild("vectorstore"));
92
+ return this.vectorStore
93
+ .asRetriever({
94
+ k: this.searchParams?.k,
95
+ filter,
96
+ })
97
+ .invoke(myQuery, { callbacks: runManager?.getChild("retriever") });
90
98
  }
91
99
  /**
92
100
  * Static method to create a new SelfQueryRetriever instance from a
@@ -73,7 +73,10 @@ export class SelfQueryRetriever extends BaseRetriever {
73
73
  this.structuredQueryTranslator = options.structuredQueryTranslator;
74
74
  }
75
75
  async _getRelevantDocuments(query, runManager) {
76
- const generatedStructuredQuery = await this.queryConstructor.invoke({ query }, runManager?.getChild("query_constructor"));
76
+ const generatedStructuredQuery = await this.queryConstructor.invoke({ query }, {
77
+ callbacks: runManager?.getChild("query_constructor"),
78
+ runName: "query_constructor",
79
+ });
77
80
  const nextArg = this.structuredQueryTranslator.visitStructuredQuery(generatedStructuredQuery);
78
81
  const filter = this.structuredQueryTranslator.mergeFilters(this.searchParams?.filter, nextArg.filter, this.searchParams?.mergeFiltersOperator, this.searchParams?.forceDefaultFilter);
79
82
  const generatedQuery = generatedStructuredQuery.query;
@@ -81,7 +84,12 @@ export class SelfQueryRetriever extends BaseRetriever {
81
84
  if (!this.useOriginalQuery && generatedQuery && generatedQuery.length > 0) {
82
85
  myQuery = generatedQuery;
83
86
  }
84
- return this.vectorStore.similaritySearch(myQuery, this.searchParams?.k, filter, runManager?.getChild("vectorstore"));
87
+ return this.vectorStore
88
+ .asRetriever({
89
+ k: this.searchParams?.k,
90
+ filter,
91
+ })
92
+ .invoke(myQuery, { callbacks: runManager?.getChild("retriever") });
85
93
  }
86
94
  /**
87
95
  * Static method to create a new SelfQueryRetriever instance from a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {