@langchain/classic 1.0.10 → 1.0.11
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/CHANGELOG.md +6 -0
- package/dist/agents/chat/outputParser.d.cts +2 -2
- package/dist/agents/chat/outputParser.d.cts.map +1 -1
- package/dist/agents/mrkl/outputParser.d.ts +1 -1
- package/dist/agents/mrkl/outputParser.d.ts.map +1 -1
- package/dist/agents/openai_tools/index.d.cts +2 -2
- package/dist/agents/openai_tools/index.d.cts.map +1 -1
- package/dist/agents/openai_tools/index.d.ts +2 -2
- package/dist/agents/openai_tools/index.d.ts.map +1 -1
- package/dist/agents/react/index.d.ts +2 -2
- package/dist/agents/react/index.d.ts.map +1 -1
- package/dist/agents/structured_chat/index.d.ts +2 -2
- package/dist/agents/structured_chat/index.d.ts.map +1 -1
- package/dist/agents/tool_calling/index.d.cts +2 -2
- package/dist/agents/tool_calling/index.d.cts.map +1 -1
- package/dist/agents/tool_calling/index.d.ts +2 -2
- package/dist/agents/tool_calling/index.d.ts.map +1 -1
- package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +2 -2
- package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts.map +1 -1
- package/dist/evaluation/comparison/pairwise.d.ts +3 -3
- package/dist/evaluation/comparison/pairwise.d.ts.map +1 -1
- package/dist/evaluation/criteria/criteria.d.ts +3 -3
- package/dist/evaluation/criteria/criteria.d.ts.map +1 -1
- package/dist/experimental/autogpt/prompt.d.ts +2 -2
- package/dist/experimental/autogpt/prompt.d.ts.map +1 -1
- package/dist/experimental/prompts/custom_format.d.ts.map +1 -1
- package/dist/experimental/prompts/handlebars.d.ts.map +1 -1
- package/dist/util/sql_utils.cjs +5 -4
- package/dist/util/sql_utils.cjs.map +1 -1
- package/dist/util/sql_utils.js +5 -4
- package/dist/util/sql_utils.js.map +1 -1
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @langchain/classic
|
|
2
2
|
|
|
3
|
+
## 1.0.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#9844](https://github.com/langchain-ai/langchainjs/pull/9844) [`a496cc0`](https://github.com/langchain-ai/langchainjs/commit/a496cc09d2b4d28a8eb0c4b96bd3555ab1cc47dc) Thanks [@VoVaVc](https://github.com/VoVaVc)! - Add support for Aurora Postgres DataSource
|
|
8
|
+
|
|
3
9
|
## 1.0.10
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -51,12 +51,12 @@ declare class ChatAgentOutputParser extends AgentActionOutputParser {
|
|
|
51
51
|
* @returns An object that satisfies the AgentFinish interface or an object with the tool, toolInput, and log.
|
|
52
52
|
*/
|
|
53
53
|
parse(text: string): Promise<{
|
|
54
|
-
tool?: undefined;
|
|
55
|
-
toolInput?: undefined;
|
|
56
54
|
returnValues: {
|
|
57
55
|
output: string;
|
|
58
56
|
};
|
|
59
57
|
log: string;
|
|
58
|
+
tool?: undefined;
|
|
59
|
+
toolInput?: undefined;
|
|
60
60
|
} | {
|
|
61
61
|
returnValues?: undefined;
|
|
62
62
|
tool: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outputParser.d.cts","names":["AgentActionOutputParser","FINAL_ANSWER_ACTION","ChatAgentOutputParser","Promise"],"sources":["../../../src/agents/chat/outputParser.d.ts"],"sourcesContent":["import { AgentActionOutputParser } from \"../types.js\";\nexport declare const FINAL_ANSWER_ACTION = \"Final Answer:\";\n/**\n * A class that extends the AgentActionOutputParser to parse the output of\n * the ChatAgent in LangChain. It checks if the output text contains the\n * final answer action or a JSON response, and parses it accordingly.\n * @example\n * ```typescript\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\n * \"ai\",\n * `{PREFIX}\n * {FORMAT_INSTRUCTIONS}\n * {SUFFIX}`,\n * ],\n * [\"human\", \"Question: {input}\"],\n * ]);\n * const runnableAgent = RunnableSequence.from([\n * {\n * input: (i: { input: string; steps: AgentStep[] }) => i.input,\n * agent_scratchpad: (i: { input: string; steps: AgentStep[] }) =>\n * formatLogToString(i.steps),\n * },\n * prompt,\n * new OpenAI({ temperature: 0 }),\n * new ChatAgentOutputParser(),\n * ]);\n *\n * const executor = AgentExecutor.fromAgentAndTools({\n * agent: runnableAgent,\n * tools: [new SerpAPI(), new Calculator()],\n * });\n *\n * const result = await executor.invoke({\n * input:\n * \"Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?\",\n * });\n * ```\n */\nexport declare class ChatAgentOutputParser extends AgentActionOutputParser {\n lc_namespace: string[];\n /**\n * Parses the output text from the MRKL chain into an agent action or\n * agent finish. If the text contains the final answer action or does not\n * contain an action, it returns an AgentFinish with the output and log.\n * If the text contains a JSON response, it returns the tool, toolInput,\n * and log.\n * @param text The output text from the MRKL chain.\n * @returns An object that satisfies the AgentFinish interface or an object with the tool, toolInput, and log.\n */\n parse(text: string): Promise<{\n
|
|
1
|
+
{"version":3,"file":"outputParser.d.cts","names":["AgentActionOutputParser","FINAL_ANSWER_ACTION","ChatAgentOutputParser","Promise"],"sources":["../../../src/agents/chat/outputParser.d.ts"],"sourcesContent":["import { AgentActionOutputParser } from \"../types.js\";\nexport declare const FINAL_ANSWER_ACTION = \"Final Answer:\";\n/**\n * A class that extends the AgentActionOutputParser to parse the output of\n * the ChatAgent in LangChain. It checks if the output text contains the\n * final answer action or a JSON response, and parses it accordingly.\n * @example\n * ```typescript\n * const prompt = ChatPromptTemplate.fromMessages([\n * [\n * \"ai\",\n * `{PREFIX}\n * {FORMAT_INSTRUCTIONS}\n * {SUFFIX}`,\n * ],\n * [\"human\", \"Question: {input}\"],\n * ]);\n * const runnableAgent = RunnableSequence.from([\n * {\n * input: (i: { input: string; steps: AgentStep[] }) => i.input,\n * agent_scratchpad: (i: { input: string; steps: AgentStep[] }) =>\n * formatLogToString(i.steps),\n * },\n * prompt,\n * new OpenAI({ temperature: 0 }),\n * new ChatAgentOutputParser(),\n * ]);\n *\n * const executor = AgentExecutor.fromAgentAndTools({\n * agent: runnableAgent,\n * tools: [new SerpAPI(), new Calculator()],\n * });\n *\n * const result = await executor.invoke({\n * input:\n * \"Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?\",\n * });\n * ```\n */\nexport declare class ChatAgentOutputParser extends AgentActionOutputParser {\n lc_namespace: string[];\n /**\n * Parses the output text from the MRKL chain into an agent action or\n * agent finish. If the text contains the final answer action or does not\n * contain an action, it returns an AgentFinish with the output and log.\n * If the text contains a JSON response, it returns the tool, toolInput,\n * and log.\n * @param text The output text from the MRKL chain.\n * @returns An object that satisfies the AgentFinish interface or an object with the tool, toolInput, and log.\n */\n parse(text: string): Promise<{\n returnValues: {\n output: string;\n };\n log: string;\n tool?: undefined;\n toolInput?: undefined;\n } | {\n returnValues?: undefined;\n tool: any;\n toolInput: any;\n log: string;\n }>;\n /**\n * Returns the format instructions used in the output parser for the\n * ChatAgent class.\n * @returns The format instructions as a string.\n */\n getFormatInstructions(): string;\n}\n//# sourceMappingURL=outputParser.d.ts.map"],"mappings":";;;;;AAuCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAqBE,qBAAAA,SAA8BF,uBAAuB;;;;;;;;;;;uBAWjDG"}
|
|
@@ -25,10 +25,10 @@ declare class ZeroShotAgentOutputParser extends AgentActionOutputParser {
|
|
|
25
25
|
tool?: undefined;
|
|
26
26
|
toolInput?: undefined;
|
|
27
27
|
} | {
|
|
28
|
+
returnValues?: undefined;
|
|
28
29
|
tool: string;
|
|
29
30
|
toolInput: string;
|
|
30
31
|
log: string;
|
|
31
|
-
returnValues?: undefined;
|
|
32
32
|
}>;
|
|
33
33
|
/**
|
|
34
34
|
* Returns the format instructions for parsing the output of an agent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outputParser.d.ts","names":["OutputParserArgs","AgentActionOutputParser","FINAL_ANSWER_ACTION","ZeroShotAgentOutputParser","Promise"],"sources":["../../../src/agents/mrkl/outputParser.d.ts"],"sourcesContent":["import { OutputParserArgs } from \"../agent.js\";\nimport { AgentActionOutputParser } from \"../types.js\";\nexport declare const FINAL_ANSWER_ACTION = \"Final Answer:\";\n/**\n * A class that extends `AgentActionOutputParser` to provide a custom\n * implementation for parsing the output of a ZeroShotAgent action.\n */\nexport declare class ZeroShotAgentOutputParser extends AgentActionOutputParser {\n lc_namespace: string[];\n finishToolName: string;\n constructor(fields?: OutputParserArgs);\n /**\n * Parses the text output of an agent action, extracting the tool, tool\n * input, and output.\n * @param text The text output of an agent action.\n * @returns An object containing the tool, tool input, and output extracted from the text, along with the original text as a log.\n */\n parse(text: string): Promise<{\n returnValues: {\n output: string;\n };\n log: string;\n tool?: undefined;\n toolInput?: undefined;\n } | {\n tool: string;\n toolInput: string;\n log: string;\n
|
|
1
|
+
{"version":3,"file":"outputParser.d.ts","names":["OutputParserArgs","AgentActionOutputParser","FINAL_ANSWER_ACTION","ZeroShotAgentOutputParser","Promise"],"sources":["../../../src/agents/mrkl/outputParser.d.ts"],"sourcesContent":["import { OutputParserArgs } from \"../agent.js\";\nimport { AgentActionOutputParser } from \"../types.js\";\nexport declare const FINAL_ANSWER_ACTION = \"Final Answer:\";\n/**\n * A class that extends `AgentActionOutputParser` to provide a custom\n * implementation for parsing the output of a ZeroShotAgent action.\n */\nexport declare class ZeroShotAgentOutputParser extends AgentActionOutputParser {\n lc_namespace: string[];\n finishToolName: string;\n constructor(fields?: OutputParserArgs);\n /**\n * Parses the text output of an agent action, extracting the tool, tool\n * input, and output.\n * @param text The text output of an agent action.\n * @returns An object containing the tool, tool input, and output extracted from the text, along with the original text as a log.\n */\n parse(text: string): Promise<{\n returnValues: {\n output: string;\n };\n log: string;\n tool?: undefined;\n toolInput?: undefined;\n } | {\n returnValues?: undefined;\n tool: string;\n toolInput: string;\n log: string;\n }>;\n /**\n * Returns the format instructions for parsing the output of an agent\n * action in the style of the ZeroShotAgent.\n * @returns The format instructions for parsing the output.\n */\n getFormatInstructions(): string;\n}\n//# sourceMappingURL=outputParser.d.ts.map"],"mappings":";;;;;;AAOA;;;AAAuDC,cAAlCE,yBAAAA,SAAkCF,uBAAAA,CAAAA;EAAuB,YAAA,EAAA,MAAA,EAAA;;uBAGrDD;;;;;;;uBAOAI"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ToolsAgentStep } from "../tool_calling/output_parser.cjs";
|
|
2
2
|
import { AgentRunnableSequence } from "../agent.cjs";
|
|
3
3
|
import { OpenAIToolsAgentOutputParser } from "./output_parser.cjs";
|
|
4
|
-
import * as
|
|
4
|
+
import * as _langchain_core_agents3 from "@langchain/core/agents";
|
|
5
5
|
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
|
6
6
|
import { ToolDefinition } from "@langchain/core/language_models/base";
|
|
7
7
|
import { StructuredToolInterface } from "@langchain/core/tools";
|
|
@@ -94,7 +94,7 @@ declare function createOpenAIToolsAgent({
|
|
|
94
94
|
streamRunnable
|
|
95
95
|
}: CreateOpenAIToolsAgentParams): Promise<AgentRunnableSequence<{
|
|
96
96
|
steps: ToolsAgentStep[];
|
|
97
|
-
},
|
|
97
|
+
}, _langchain_core_agents3.AgentFinish | _langchain_core_agents3.AgentAction[]>>;
|
|
98
98
|
//#endregion
|
|
99
99
|
export { CreateOpenAIToolsAgentParams, createOpenAIToolsAgent };
|
|
100
100
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":["StructuredToolInterface","BaseChatModel","BaseChatModelCallOptions","ChatPromptTemplate","OpenAIClient","ToolDefinition","OpenAIToolsAgentOutputParser","ToolsAgentStep","AgentRunnableSequence","CreateOpenAIToolsAgentParams","ChatCompletionTool","createOpenAIToolsAgent","llm","tools","prompt","streamRunnable","
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":["StructuredToolInterface","BaseChatModel","BaseChatModelCallOptions","ChatPromptTemplate","OpenAIClient","ToolDefinition","OpenAIToolsAgentOutputParser","ToolsAgentStep","AgentRunnableSequence","CreateOpenAIToolsAgentParams","ChatCompletionTool","createOpenAIToolsAgent","llm","tools","prompt","streamRunnable","_langchain_core_agents3","AgentFinish","AgentAction","Promise"],"sources":["../../../src/agents/openai_tools/index.d.ts"],"sourcesContent":["import type { StructuredToolInterface } from \"@langchain/core/tools\";\nimport type { BaseChatModel, BaseChatModelCallOptions } from \"@langchain/core/language_models/chat_models\";\nimport { ChatPromptTemplate } from \"@langchain/core/prompts\";\nimport { OpenAIClient } from \"@langchain/openai\";\nimport { ToolDefinition } from \"@langchain/core/language_models/base\";\nimport { OpenAIToolsAgentOutputParser, type ToolsAgentStep } from \"./output_parser.js\";\nimport { AgentRunnableSequence } from \"../agent.js\";\nexport { OpenAIToolsAgentOutputParser, type ToolsAgentStep };\n/**\n * Params used by the createOpenAIToolsAgent function.\n */\nexport type CreateOpenAIToolsAgentParams = {\n /**\n * LLM to use as the agent. Should work with OpenAI tool calling,\n * so must either be an OpenAI model that supports that or a wrapper of\n * a different model that adds in equivalent support.\n */\n llm: BaseChatModel<BaseChatModelCallOptions & {\n tools?: StructuredToolInterface[] | OpenAIClient.ChatCompletionTool[] | any[];\n }>;\n /** Tools this agent has access to. */\n tools: StructuredToolInterface[] | ToolDefinition[];\n /** The prompt to use, must have an input key of `agent_scratchpad`. */\n prompt: ChatPromptTemplate;\n /**\n * Whether to invoke the underlying model in streaming mode,\n * allowing streaming of intermediate steps. Defaults to true.\n */\n streamRunnable?: boolean;\n};\n/**\n * Create an agent that uses OpenAI-style tool calling.\n * @param params Params required to create the agent. Includes an LLM, tools, and prompt.\n * @returns A runnable sequence representing an agent. It takes as input all the same input\n * variables as the prompt passed in does. It returns as output either an\n * AgentAction or AgentFinish.\n *\n * @example\n * ```typescript\n * import { AgentExecutor, createOpenAIToolsAgent } from \"langchain/agents\";\n * import { pull } from \"langchain/hub\";\n * import type { ChatPromptTemplate } from \"@langchain/core/prompts\";\n * import { AIMessage, HumanMessage } from \"@langchain/core/messages\";\n *\n * import { ChatOpenAI } from \"@langchain/openai\";\n *\n * // Define the tools the agent will have access to.\n * const tools = [...];\n *\n * // Get the prompt to use - you can modify this!\n * // If you want to see the prompt in full, you can at:\n * // https://smith.langchain.com/hub/hwchase17/openai-tools-agent\n * const prompt = await pull<ChatPromptTemplate>(\n * \"hwchase17/openai-tools-agent\"\n * );\n *\n * const llm = new ChatOpenAI({\n * temperature: 0,\n * model: \"gpt-3.5-turbo-1106\",\n * });\n *\n * const agent = await createOpenAIToolsAgent({\n * llm,\n * tools,\n * prompt,\n * });\n *\n * const agentExecutor = new AgentExecutor({\n * agent,\n * tools,\n * });\n *\n * const result = await agentExecutor.invoke({\n * input: \"what is LangChain?\",\n * });\n *\n * // With chat history\n * const result2 = await agentExecutor.invoke({\n * input: \"what's my name?\",\n * chat_history: [\n * new HumanMessage(\"hi! my name is cob\"),\n * new AIMessage(\"Hello Cob! How can I assist you today?\"),\n * ],\n * });\n * ```\n */\nexport declare function createOpenAIToolsAgent({ llm, tools, prompt, streamRunnable }: CreateOpenAIToolsAgentParams): Promise<AgentRunnableSequence<{\n steps: ToolsAgentStep[];\n}, import(\"@langchain/core/agents\").AgentFinish | import(\"@langchain/core/agents\").AgentAction[]>>;\n//# sourceMappingURL=index.d.ts.map"],"mappings":";;;;;;;;;;;;;;AAWYS,KAAAA,4BAAAA,GAA4B;EAMjBP;;;;;EAIgBG,GAAAA,EAJ9BJ,aAI8BI,CAJhBH,wBAIgBG,GAAAA;IAE3BF,KAAAA,CAAAA,EALIH,uBAKJG,EAAAA,GALgCC,YAAAA,CAAaM,kBAK7CP,EAAAA,GAAAA,GAAAA,EAAAA;EAAkB,CAAA,CAAA;EA+DNQ;EAAyBC,KAAAA,EAjEtCZ,uBAiEsCY,EAAAA,GAjEVP,cAiEUO,EAAAA;EAAKC;EAAOC,MAAAA,EA/DjDX,kBA+DiDW;EAAQC;;;;EAEtBC,cAAAA,CAAAA,EAAAA,OAAoCE;CAF2CV;;AAAD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAArGG,sBAAAA;;;;;GAA+DF,+BAA+BU,QAAQX;SACnHD;GAAcS,uBAAAA,CACWC,WAAAA,GAAWD,uBAAAA,CAAoCE,WAAAA"}
|
|
@@ -6,7 +6,7 @@ import { StructuredToolInterface } from "@langchain/core/tools";
|
|
|
6
6
|
import { ToolDefinition } from "@langchain/core/language_models/base";
|
|
7
7
|
import { OpenAIClient } from "@langchain/openai";
|
|
8
8
|
import { BaseChatModel, BaseChatModelCallOptions } from "@langchain/core/language_models/chat_models";
|
|
9
|
-
import * as
|
|
9
|
+
import * as _langchain_core_agents1 from "@langchain/core/agents";
|
|
10
10
|
|
|
11
11
|
//#region src/agents/openai_tools/index.d.ts
|
|
12
12
|
/**
|
|
@@ -94,7 +94,7 @@ declare function createOpenAIToolsAgent({
|
|
|
94
94
|
streamRunnable
|
|
95
95
|
}: CreateOpenAIToolsAgentParams): Promise<AgentRunnableSequence<{
|
|
96
96
|
steps: ToolsAgentStep[];
|
|
97
|
-
},
|
|
97
|
+
}, _langchain_core_agents1.AgentFinish | _langchain_core_agents1.AgentAction[]>>;
|
|
98
98
|
//#endregion
|
|
99
99
|
export { CreateOpenAIToolsAgentParams, createOpenAIToolsAgent };
|
|
100
100
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["StructuredToolInterface","BaseChatModel","BaseChatModelCallOptions","ChatPromptTemplate","OpenAIClient","ToolDefinition","OpenAIToolsAgentOutputParser","ToolsAgentStep","AgentRunnableSequence","CreateOpenAIToolsAgentParams","ChatCompletionTool","createOpenAIToolsAgent","llm","tools","prompt","streamRunnable","
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["StructuredToolInterface","BaseChatModel","BaseChatModelCallOptions","ChatPromptTemplate","OpenAIClient","ToolDefinition","OpenAIToolsAgentOutputParser","ToolsAgentStep","AgentRunnableSequence","CreateOpenAIToolsAgentParams","ChatCompletionTool","createOpenAIToolsAgent","llm","tools","prompt","streamRunnable","_langchain_core_agents1","AgentFinish","AgentAction","Promise"],"sources":["../../../src/agents/openai_tools/index.d.ts"],"sourcesContent":["import type { StructuredToolInterface } from \"@langchain/core/tools\";\nimport type { BaseChatModel, BaseChatModelCallOptions } from \"@langchain/core/language_models/chat_models\";\nimport { ChatPromptTemplate } from \"@langchain/core/prompts\";\nimport { OpenAIClient } from \"@langchain/openai\";\nimport { ToolDefinition } from \"@langchain/core/language_models/base\";\nimport { OpenAIToolsAgentOutputParser, type ToolsAgentStep } from \"./output_parser.js\";\nimport { AgentRunnableSequence } from \"../agent.js\";\nexport { OpenAIToolsAgentOutputParser, type ToolsAgentStep };\n/**\n * Params used by the createOpenAIToolsAgent function.\n */\nexport type CreateOpenAIToolsAgentParams = {\n /**\n * LLM to use as the agent. Should work with OpenAI tool calling,\n * so must either be an OpenAI model that supports that or a wrapper of\n * a different model that adds in equivalent support.\n */\n llm: BaseChatModel<BaseChatModelCallOptions & {\n tools?: StructuredToolInterface[] | OpenAIClient.ChatCompletionTool[] | any[];\n }>;\n /** Tools this agent has access to. */\n tools: StructuredToolInterface[] | ToolDefinition[];\n /** The prompt to use, must have an input key of `agent_scratchpad`. */\n prompt: ChatPromptTemplate;\n /**\n * Whether to invoke the underlying model in streaming mode,\n * allowing streaming of intermediate steps. Defaults to true.\n */\n streamRunnable?: boolean;\n};\n/**\n * Create an agent that uses OpenAI-style tool calling.\n * @param params Params required to create the agent. Includes an LLM, tools, and prompt.\n * @returns A runnable sequence representing an agent. It takes as input all the same input\n * variables as the prompt passed in does. It returns as output either an\n * AgentAction or AgentFinish.\n *\n * @example\n * ```typescript\n * import { AgentExecutor, createOpenAIToolsAgent } from \"langchain/agents\";\n * import { pull } from \"langchain/hub\";\n * import type { ChatPromptTemplate } from \"@langchain/core/prompts\";\n * import { AIMessage, HumanMessage } from \"@langchain/core/messages\";\n *\n * import { ChatOpenAI } from \"@langchain/openai\";\n *\n * // Define the tools the agent will have access to.\n * const tools = [...];\n *\n * // Get the prompt to use - you can modify this!\n * // If you want to see the prompt in full, you can at:\n * // https://smith.langchain.com/hub/hwchase17/openai-tools-agent\n * const prompt = await pull<ChatPromptTemplate>(\n * \"hwchase17/openai-tools-agent\"\n * );\n *\n * const llm = new ChatOpenAI({\n * temperature: 0,\n * model: \"gpt-3.5-turbo-1106\",\n * });\n *\n * const agent = await createOpenAIToolsAgent({\n * llm,\n * tools,\n * prompt,\n * });\n *\n * const agentExecutor = new AgentExecutor({\n * agent,\n * tools,\n * });\n *\n * const result = await agentExecutor.invoke({\n * input: \"what is LangChain?\",\n * });\n *\n * // With chat history\n * const result2 = await agentExecutor.invoke({\n * input: \"what's my name?\",\n * chat_history: [\n * new HumanMessage(\"hi! my name is cob\"),\n * new AIMessage(\"Hello Cob! How can I assist you today?\"),\n * ],\n * });\n * ```\n */\nexport declare function createOpenAIToolsAgent({ llm, tools, prompt, streamRunnable }: CreateOpenAIToolsAgentParams): Promise<AgentRunnableSequence<{\n steps: ToolsAgentStep[];\n}, import(\"@langchain/core/agents\").AgentFinish | import(\"@langchain/core/agents\").AgentAction[]>>;\n//# sourceMappingURL=index.d.ts.map"],"mappings":";;;;;;;;;;;;;;AAWYS,KAAAA,4BAAAA,GAA4B;EAMjBP;;;;;EAIgBG,GAAAA,EAJ9BJ,aAI8BI,CAJhBH,wBAIgBG,GAAAA;IAE3BF,KAAAA,CAAAA,EALIH,uBAKJG,EAAAA,GALgCC,YAAAA,CAAaM,kBAK7CP,EAAAA,GAAAA,GAAAA,EAAAA;EAAkB,CAAA,CAAA;EA+DNQ;EAAyBC,KAAAA,EAjEtCZ,uBAiEsCY,EAAAA,GAjEVP,cAiEUO,EAAAA;EAAKC;EAAOC,MAAAA,EA/DjDX,kBA+DiDW;EAAQC;;;;EAEtBC,cAAAA,CAAAA,EAAAA,OAAoCE;CAF2CV;;AAAD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAArGG,sBAAAA;;;;;GAA+DF,+BAA+BU,QAAQX;SACnHD;GAAcS,uBAAAA,CACWC,WAAAA,GAAWD,uBAAAA,CAAoCE,WAAAA"}
|
|
@@ -2,7 +2,7 @@ import { AgentRunnableSequence } from "../agent.js";
|
|
|
2
2
|
import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
3
3
|
import { ToolInterface } from "@langchain/core/tools";
|
|
4
4
|
import { BaseLanguageModelInterface } from "@langchain/core/language_models/base";
|
|
5
|
-
import * as
|
|
5
|
+
import * as _langchain_core_agents5 from "@langchain/core/agents";
|
|
6
6
|
import { AgentStep } from "@langchain/core/agents";
|
|
7
7
|
|
|
8
8
|
//#region src/agents/react/index.d.ts
|
|
@@ -75,7 +75,7 @@ declare function createReactAgent({
|
|
|
75
75
|
streamRunnable
|
|
76
76
|
}: CreateReactAgentParams): Promise<AgentRunnableSequence<{
|
|
77
77
|
steps: AgentStep[];
|
|
78
|
-
},
|
|
78
|
+
}, _langchain_core_agents5.AgentAction | _langchain_core_agents5.AgentFinish>>;
|
|
79
79
|
//#endregion
|
|
80
80
|
export { CreateReactAgentParams, createReactAgent };
|
|
81
81
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["ToolInterface","BasePromptTemplate","BaseLanguageModelInterface","AgentStep","AgentRunnableSequence","CreateReactAgentParams","createReactAgent","llm","tools","prompt","streamRunnable","
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["ToolInterface","BasePromptTemplate","BaseLanguageModelInterface","AgentStep","AgentRunnableSequence","CreateReactAgentParams","createReactAgent","llm","tools","prompt","streamRunnable","_langchain_core_agents5","AgentAction","AgentFinish","Promise"],"sources":["../../../src/agents/react/index.d.ts"],"sourcesContent":["import type { ToolInterface } from \"@langchain/core/tools\";\nimport { BasePromptTemplate } from \"@langchain/core/prompts\";\nimport type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { AgentStep } from \"@langchain/core/agents\";\nimport { AgentRunnableSequence } from \"../agent.js\";\n/**\n * Params used by the createXmlAgent function.\n */\nexport type CreateReactAgentParams = {\n /** LLM to use for the agent. */\n llm: BaseLanguageModelInterface;\n /** Tools this agent has access to. */\n tools: ToolInterface[];\n /**\n * The prompt to use. Must have input keys for\n * `tools`, `tool_names`, and `agent_scratchpad`.\n */\n prompt: BasePromptTemplate;\n /**\n * Whether to invoke the underlying model in streaming mode,\n * allowing streaming of intermediate steps. Defaults to true.\n */\n streamRunnable?: boolean;\n};\n/**\n * Create an agent that uses ReAct prompting.\n * @param params Params required to create the agent. Includes an LLM, tools, and prompt.\n * @returns A runnable sequence representing an agent. It takes as input all the same input\n * variables as the prompt passed in does. It returns as output either an\n * AgentAction or AgentFinish.\n *\n * @example\n * ```typescript\n * import { AgentExecutor, createReactAgent } from \"langchain/agents\";\n * import { pull } from \"langchain/hub\";\n * import type { PromptTemplate } from \"@langchain/core/prompts\";\n *\n * import { OpenAI } from \"@langchain/openai\";\n *\n * // Define the tools the agent will have access to.\n * const tools = [...];\n *\n * // Get the prompt to use - you can modify this!\n * // If you want to see the prompt in full, you can at:\n * // https://smith.langchain.com/hub/hwchase17/react\n * const prompt = await pull<PromptTemplate>(\"hwchase17/react\");\n *\n * const llm = new OpenAI({\n * temperature: 0,\n * });\n *\n * const agent = await createReactAgent({\n * llm,\n * tools,\n * prompt,\n * });\n *\n * const agentExecutor = new AgentExecutor({\n * agent,\n * tools,\n * });\n *\n * const result = await agentExecutor.invoke({\n * input: \"what is LangChain?\",\n * });\n * ```\n */\nexport declare function createReactAgent({ llm, tools, prompt, streamRunnable }: CreateReactAgentParams): Promise<AgentRunnableSequence<{\n steps: AgentStep[];\n}, import(\"@langchain/core/agents\").AgentAction | import(\"@langchain/core/agents\").AgentFinish>>;\n//# sourceMappingURL=index.d.ts.map"],"mappings":";;;;;;;;;;;AAQYK,KAAAA,sBAAAA,GAAsB;EAEzBH;EAEEF,GAAAA,EAFFE,0BAEEF;EAKCC;EAAkB,KAAA,EALnBD,aAKmB,EAAA;EAkDNM;;;;EAAuCI,MAAAA,EAlDnDT,kBAkDmDS;EAAkBL;;;;EAAiCD,cAAAA,CAAAA,EAAAA,OAAAA;CAARU;AAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAzFR,gBAAAA;;;;;GAAyDD,yBAAyBS,QAAQV;SACvGD;GAASQ,uBAAAA,CACgBC,WAAAA,GAAWD,uBAAAA,CAAoCE"}
|
|
@@ -5,7 +5,7 @@ import { StructuredChatOutputParserWithRetries } from "./outputParser.js";
|
|
|
5
5
|
import { BaseMessagePromptTemplate, BasePromptTemplate, ChatPromptTemplate } from "@langchain/core/prompts";
|
|
6
6
|
import { StructuredToolInterface } from "@langchain/core/tools";
|
|
7
7
|
import { BaseLanguageModelInterface, ToolDefinition } from "@langchain/core/language_models/base";
|
|
8
|
-
import * as
|
|
8
|
+
import * as _langchain_core_agents0 from "@langchain/core/agents";
|
|
9
9
|
import { AgentStep } from "@langchain/core/agents";
|
|
10
10
|
|
|
11
11
|
//#region src/agents/structured_chat/index.d.ts
|
|
@@ -176,7 +176,7 @@ declare function createStructuredChatAgent({
|
|
|
176
176
|
streamRunnable
|
|
177
177
|
}: CreateStructuredChatAgentParams): Promise<AgentRunnableSequence<{
|
|
178
178
|
steps: AgentStep[];
|
|
179
|
-
},
|
|
179
|
+
}, _langchain_core_agents0.AgentAction | _langchain_core_agents0.AgentFinish>>;
|
|
180
180
|
//#endregion
|
|
181
181
|
export { CreateStructuredChatAgentParams, StructuredChatAgent, StructuredChatAgentInput, StructuredChatCreatePromptArgs, createStructuredChatAgent };
|
|
182
182
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["StructuredToolInterface","BaseLanguageModelInterface","ToolDefinition","BasePromptTemplate","BaseMessagePromptTemplate","ChatPromptTemplate","AgentStep","Optional","Agent","AgentArgs","AgentRunnableSequence","OutputParserArgs","AgentInput","StructuredChatOutputParserWithRetries","StructuredChatCreatePromptArgs","StructuredChatAgentInput","StructuredChatAgent","Promise","CreateStructuredChatAgentParams","createStructuredChatAgent","llm","tools","prompt","streamRunnable","
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["StructuredToolInterface","BaseLanguageModelInterface","ToolDefinition","BasePromptTemplate","BaseMessagePromptTemplate","ChatPromptTemplate","AgentStep","Optional","Agent","AgentArgs","AgentRunnableSequence","OutputParserArgs","AgentInput","StructuredChatOutputParserWithRetries","StructuredChatCreatePromptArgs","StructuredChatAgentInput","StructuredChatAgent","Promise","CreateStructuredChatAgentParams","createStructuredChatAgent","llm","tools","prompt","streamRunnable","_langchain_core_agents0","AgentAction","AgentFinish"],"sources":["../../../src/agents/structured_chat/index.d.ts"],"sourcesContent":["import type { StructuredToolInterface } from \"@langchain/core/tools\";\nimport { type BaseLanguageModelInterface, type ToolDefinition } from \"@langchain/core/language_models/base\";\nimport type { BasePromptTemplate } from \"@langchain/core/prompts\";\nimport { BaseMessagePromptTemplate, ChatPromptTemplate } from \"@langchain/core/prompts\";\nimport { AgentStep } from \"@langchain/core/agents\";\nimport { Optional } from \"../../types/type-utils.js\";\nimport { Agent, AgentArgs, AgentRunnableSequence, OutputParserArgs } from \"../agent.js\";\nimport { AgentInput } from \"../types.js\";\nimport { StructuredChatOutputParserWithRetries } from \"./outputParser.js\";\n/**\n * Interface for arguments used to create a prompt for a\n * StructuredChatAgent.\n */\nexport interface StructuredChatCreatePromptArgs {\n /** String to put after the list of tools. */\n suffix?: string;\n /** String to put before the list of tools. */\n prefix?: string;\n /** String to use directly as the human message template. */\n humanMessageTemplate?: string;\n /** List of input variables the final prompt will expect. */\n inputVariables?: string[];\n /** List of historical prompts from memory. */\n memoryPrompts?: BaseMessagePromptTemplate[];\n}\n/**\n * Type for input data for creating a StructuredChatAgent, with the\n * 'outputParser' property made optional.\n */\nexport type StructuredChatAgentInput = Optional<AgentInput, \"outputParser\">;\n/**\n * Agent that interoperates with Structured Tools using React logic.\n * @augments Agent\n */\nexport declare class StructuredChatAgent extends Agent {\n static lc_name(): string;\n lc_namespace: string[];\n constructor(input: StructuredChatAgentInput);\n _agentType(): \"structured-chat-zero-shot-react-description\";\n observationPrefix(): string;\n llmPrefix(): string;\n _stop(): string[];\n /**\n * Validates that all provided tools have a description. Throws an error\n * if any tool lacks a description.\n * @param tools Array of StructuredTool instances to validate.\n */\n static validateTools(tools: StructuredToolInterface[]): void;\n /**\n * Returns a default output parser for the StructuredChatAgent. If an LLM\n * is provided, it creates an output parser with retry logic from the LLM.\n * @param fields Optional fields to customize the output parser. Can include an LLM and a list of tool names.\n * @returns An instance of StructuredChatOutputParserWithRetries.\n */\n static getDefaultOutputParser(fields?: OutputParserArgs & {\n toolNames: string[];\n }): StructuredChatOutputParserWithRetries;\n /**\n * Constructs the agent's scratchpad from a list of steps. If the agent's\n * scratchpad is not empty, it prepends a message indicating that the\n * agent has not seen any previous work.\n * @param steps Array of AgentStep instances to construct the scratchpad from.\n * @returns A Promise that resolves to a string representing the agent's scratchpad.\n */\n constructScratchPad(steps: AgentStep[]): Promise<string>;\n /**\n * Creates a string representation of the schemas of the provided tools.\n * @param tools Array of StructuredTool instances to create the schemas string from.\n * @returns A string representing the schemas of the provided tools.\n */\n static createToolSchemasString(tools: StructuredToolInterface[]): string;\n /**\n * Create prompt in the style of the agent.\n *\n * @param tools - List of tools the agent will have access to, used to format the prompt.\n * @param args - Arguments to create the prompt with.\n * @param args.suffix - String to put after the list of tools.\n * @param args.prefix - String to put before the list of tools.\n * @param args.inputVariables List of input variables the final prompt will expect.\n * @param args.memoryPrompts List of historical prompts from memory.\n */\n static createPrompt(tools: StructuredToolInterface[], args?: StructuredChatCreatePromptArgs): ChatPromptTemplate<any, any>;\n /**\n * Creates a StructuredChatAgent from an LLM and a list of tools.\n * Validates the tools, creates a prompt, and sets up an LLM chain for the\n * agent.\n * @param llm BaseLanguageModel instance to create the agent from.\n * @param tools Array of StructuredTool instances to create the agent from.\n * @param args Optional arguments to customize the creation of the agent. Can include arguments for creating the prompt and AgentArgs.\n * @returns A new instance of StructuredChatAgent.\n */\n static fromLLMAndTools(llm: BaseLanguageModelInterface, tools: StructuredToolInterface[], args?: StructuredChatCreatePromptArgs & AgentArgs): StructuredChatAgent;\n}\n/**\n * Params used by the createStructuredChatAgent function.\n */\nexport type CreateStructuredChatAgentParams = {\n /** LLM to use as the agent. */\n llm: BaseLanguageModelInterface;\n /** Tools this agent has access to. */\n tools: (StructuredToolInterface | ToolDefinition)[];\n /**\n * The prompt to use. Must have input keys for\n * `tools`, `tool_names`, and `agent_scratchpad`.\n */\n prompt: BasePromptTemplate;\n /**\n * Whether to invoke the underlying model in streaming mode,\n * allowing streaming of intermediate steps. Defaults to true.\n */\n streamRunnable?: boolean;\n};\n/**\n * Create an agent aimed at supporting tools with multiple inputs.\n * @param params Params required to create the agent. Includes an LLM, tools, and prompt.\n * @returns A runnable sequence representing an agent. It takes as input all the same input\n * variables as the prompt passed in does. It returns as output either an\n * AgentAction or AgentFinish.\n *\n * @example\n * ```typescript\n * import { AgentExecutor, createStructuredChatAgent } from \"langchain/agents\";\n * import { pull } from \"langchain/hub\";\n * import type { ChatPromptTemplate } from \"@langchain/core/prompts\";\n * import { AIMessage, HumanMessage } from \"@langchain/core/messages\";\n *\n * import { ChatOpenAI } from \"@langchain/openai\";\n *\n * // Define the tools the agent will have access to.\n * const tools = [...];\n *\n * // Get the prompt to use - you can modify this!\n * // If you want to see the prompt in full, you can at:\n * // https://smith.langchain.com/hub/hwchase17/structured-chat-agent\n * const prompt = await pull<ChatPromptTemplate>(\n * \"hwchase17/structured-chat-agent\"\n * );\n *\n * const llm = new ChatOpenAI({\n * temperature: 0,\n * model: \"gpt-3.5-turbo-1106\",\n * });\n *\n * const agent = await createStructuredChatAgent({\n * llm,\n * tools,\n * prompt,\n * });\n *\n * const agentExecutor = new AgentExecutor({\n * agent,\n * tools,\n * });\n *\n * const result = await agentExecutor.invoke({\n * input: \"what is LangChain?\",\n * });\n *\n * // With chat history\n * const result2 = await agentExecutor.invoke({\n * input: \"what's my name?\",\n * chat_history: [\n * new HumanMessage(\"hi! my name is cob\"),\n * new AIMessage(\"Hello Cob! How can I assist you today?\"),\n * ],\n * });\n * ```\n */\nexport declare function createStructuredChatAgent({ llm, tools, prompt, streamRunnable }: CreateStructuredChatAgentParams): Promise<AgentRunnableSequence<{\n steps: AgentStep[];\n}, import(\"@langchain/core/agents\").AgentAction | import(\"@langchain/core/agents\").AgentFinish>>;\n//# sourceMappingURL=index.d.ts.map"],"mappings":";;;;;;;;;;;;;;AAaA;AAgBA;AAKqBgB,UArBJF,8BAAAA,CAqBuB;EAGjBC;EAUSf,MAAAA,CAAAA,EAAAA,MAAAA;EAOWW;EAEnCE,MAAAA,CAAAA,EAAAA,MAAAA;EAQuBP;EAAcW,oBAAAA,CAAAA,EAAAA,MAAAA;EAMHjB;EAWXA,cAAAA,CAAAA,EAAAA,MAAAA,EAAAA;EAAkCc;EAAiCT,aAAAA,CAAAA,EA1D9ED,yBA0D8EC,EAAAA;;;;;;AA/CjDG,KALrCO,wBAAAA,GAA2BR,QAKUC,CALDI,UAKCJ,EAAAA,cAAAA,CAAAA;AAAK;AA8DtD;;;AAIsCN,cAlEjBc,mBAAAA,SAA4BR,KAAAA,CAkEXN;EAK1BC,OAAAA,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAkB,YAAA,EAAA,MAAA,EAAA;EA+DNgB,WAAAA,CAAAA,KAAAA,EAnIDJ,wBAmI0B;EAAGK,UAAAA,CAAAA,CAAAA,EAAAA,6CAAAA;EAAKC,iBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAOC,SAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAQC,KAAAA,CAAAA,CAAAA,EAAAA,MAAAA,EAAAA;EAAkBL;;;;;EAAkCD,OAAAA,aAAAA,CAAAA,KAAAA,EAzH5FjB,uBAyH4FiB,EAAAA,CAAAA,EAAAA,IAAAA;EAAO;;;;;;yCAlHxFN;;MAEnCE;;;;;;;;6BAQuBP,cAAcW;;;;;;wCAMHjB;;;;;;;;;;;6BAWXA,kCAAkCc,iCAAiCT;;;;;;;;;;8BAUlEJ,mCAAmCD,kCAAkCc,iCAAiCL,YAAYO;;;;;KAKtIE,+BAAAA;;OAEHjB;;UAEGD,0BAA0BE;;;;;UAK1BC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+DYgB,yBAAAA;;;;;GAAkED,kCAAkCD,QAAQP;SACzHJ;GAASkB,uBAAAA,CACgBC,WAAAA,GAAWD,uBAAAA,CAAoCE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ToolsAgentStep } from "./output_parser.cjs";
|
|
2
2
|
import { AgentRunnableSequence } from "../agent.cjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _langchain_core_agents1 from "@langchain/core/agents";
|
|
4
4
|
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
|
5
5
|
import { LanguageModelLike, ToolDefinition } from "@langchain/core/language_models/base";
|
|
6
6
|
import { StructuredToolInterface } from "@langchain/core/tools";
|
|
@@ -83,7 +83,7 @@ declare function createToolCallingAgent({
|
|
|
83
83
|
streamRunnable
|
|
84
84
|
}: CreateToolCallingAgentParams): AgentRunnableSequence<{
|
|
85
85
|
steps: ToolsAgentStep[];
|
|
86
|
-
},
|
|
86
|
+
}, _langchain_core_agents1.AgentFinish | _langchain_core_agents1.AgentAction[]>;
|
|
87
87
|
//#endregion
|
|
88
88
|
export { CreateToolCallingAgentParams, createToolCallingAgent };
|
|
89
89
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":["ChatPromptTemplate","StructuredToolInterface","LanguageModelLike","ToolDefinition","AgentRunnableSequence","ToolsAgentStep","CreateToolCallingAgentParams","createToolCallingAgent","llm","tools","prompt","streamRunnable","
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":["ChatPromptTemplate","StructuredToolInterface","LanguageModelLike","ToolDefinition","AgentRunnableSequence","ToolsAgentStep","CreateToolCallingAgentParams","createToolCallingAgent","llm","tools","prompt","streamRunnable","_langchain_core_agents1","AgentFinish","AgentAction"],"sources":["../../../src/agents/tool_calling/index.d.ts"],"sourcesContent":["import { ChatPromptTemplate } from \"@langchain/core/prompts\";\nimport { StructuredToolInterface } from \"@langchain/core/tools\";\nimport { LanguageModelLike, ToolDefinition } from \"@langchain/core/language_models/base\";\nimport { AgentRunnableSequence } from \"../agent.js\";\nimport { ToolsAgentStep } from \"./output_parser.js\";\n/**\n * Params used by the createOpenAIToolsAgent function.\n */\nexport type CreateToolCallingAgentParams = {\n /**\n * LLM to use as the agent. Should work with OpenAI tool calling,\n * so must either be an OpenAI model that supports that or a wrapper of\n * a different model that adds in equivalent support.\n */\n llm: LanguageModelLike;\n /** Tools this agent has access to. */\n tools: StructuredToolInterface[] | ToolDefinition[];\n /** The prompt to use, must have an input key of `agent_scratchpad`. */\n prompt: ChatPromptTemplate;\n /**\n * Whether to invoke the underlying model in streaming mode,\n * allowing streaming of intermediate steps. Defaults to true.\n */\n streamRunnable?: boolean;\n};\n/**\n * Create an agent that uses tools.\n * @param params Params required to create the agent. Includes an LLM, tools, and prompt.\n * @returns A runnable sequence representing an agent. It takes as input all the same input\n * variables as the prompt passed in does. It returns as output either an\n * AgentAction or AgentFinish.\n * @example\n * ```typescript\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { ChatPromptTemplate, MessagesPlaceholder } from \"@langchain/core/prompts\";\n * import { AgentExecutor, createToolCallingAgent } from \"langchain/agents\";\n *\n * const prompt = ChatPromptTemplate.fromMessages(\n * [\n * [\"system\", \"You are a helpful assistant\"],\n * [\"placeholder\", \"{chat_history}\"],\n * [\"human\", \"{input}\"],\n * [\"placeholder\", \"{agent_scratchpad}\"],\n * ]\n * );\n *\n *\n * const llm = new ChatAnthropic({\n * modelName: \"claude-3-opus-20240229\",\n * temperature: 0,\n * });\n *\n * // Define the tools the agent will have access to.\n * const tools = [...];\n *\n * const agent = createToolCallingAgent({ llm, tools, prompt });\n *\n * const agentExecutor = new AgentExecutor({ agent, tools });\n *\n * const result = await agentExecutor.invoke({input: \"what is LangChain?\"});\n *\n * // Using with chat history\n * import { AIMessage, HumanMessage } from \"@langchain/core/messages\";\n *\n * const result2 = await agentExecutor.invoke(\n * {\n * input: \"what's my name?\",\n * chat_history: [\n * new HumanMessage({content: \"hi! my name is bob\"}),\n * new AIMessage({content: \"Hello Bob! How can I assist you today?\"}),\n * ],\n * }\n * );\n * ```\n */\nexport declare function createToolCallingAgent({ llm, tools, prompt, streamRunnable }: CreateToolCallingAgentParams): AgentRunnableSequence<{\n steps: ToolsAgentStep[];\n}, import(\"@langchain/core/agents\").AgentFinish | import(\"@langchain/core/agents\").AgentAction[]>;\n//# sourceMappingURL=index.d.ts.map"],"mappings":";;;;;;;;;;;AAQYM,KAAAA,4BAAAA,GAA4B;EAM/BJ;;;;AAIqB;EAyDNK,GAAAA,EA7DfL,iBA6DeK;EAAyBC;EAAKC,KAAAA,EA3D3CR,uBA2D2CQ,EAAAA,GA3DfN,cA2DeM,EAAAA;EAAOC;EAAQC,MAAAA,EAzDzDX,kBAyDyDW;EAAkBL;;;;EAA+BF,cAAAA,CAAAA,EAAAA,OAAAA;AAAqB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAnHG,sBAAAA;;;;;GAA+DD,+BAA+BF;SAC3GC;GAAcO,uBAAAA,CACWC,WAAAA,GAAWD,uBAAAA,CAAoCE,WAAAA"}
|
|
@@ -3,7 +3,7 @@ import { AgentRunnableSequence } from "../agent.js";
|
|
|
3
3
|
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
|
4
4
|
import { StructuredToolInterface } from "@langchain/core/tools";
|
|
5
5
|
import { LanguageModelLike, ToolDefinition } from "@langchain/core/language_models/base";
|
|
6
|
-
import * as
|
|
6
|
+
import * as _langchain_core_agents3 from "@langchain/core/agents";
|
|
7
7
|
|
|
8
8
|
//#region src/agents/tool_calling/index.d.ts
|
|
9
9
|
/**
|
|
@@ -83,7 +83,7 @@ declare function createToolCallingAgent({
|
|
|
83
83
|
streamRunnable
|
|
84
84
|
}: CreateToolCallingAgentParams): AgentRunnableSequence<{
|
|
85
85
|
steps: ToolsAgentStep[];
|
|
86
|
-
},
|
|
86
|
+
}, _langchain_core_agents3.AgentFinish | _langchain_core_agents3.AgentAction[]>;
|
|
87
87
|
//#endregion
|
|
88
88
|
export { CreateToolCallingAgentParams, createToolCallingAgent };
|
|
89
89
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["ChatPromptTemplate","StructuredToolInterface","LanguageModelLike","ToolDefinition","AgentRunnableSequence","ToolsAgentStep","CreateToolCallingAgentParams","createToolCallingAgent","llm","tools","prompt","streamRunnable","
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["ChatPromptTemplate","StructuredToolInterface","LanguageModelLike","ToolDefinition","AgentRunnableSequence","ToolsAgentStep","CreateToolCallingAgentParams","createToolCallingAgent","llm","tools","prompt","streamRunnable","_langchain_core_agents3","AgentFinish","AgentAction"],"sources":["../../../src/agents/tool_calling/index.d.ts"],"sourcesContent":["import { ChatPromptTemplate } from \"@langchain/core/prompts\";\nimport { StructuredToolInterface } from \"@langchain/core/tools\";\nimport { LanguageModelLike, ToolDefinition } from \"@langchain/core/language_models/base\";\nimport { AgentRunnableSequence } from \"../agent.js\";\nimport { ToolsAgentStep } from \"./output_parser.js\";\n/**\n * Params used by the createOpenAIToolsAgent function.\n */\nexport type CreateToolCallingAgentParams = {\n /**\n * LLM to use as the agent. Should work with OpenAI tool calling,\n * so must either be an OpenAI model that supports that or a wrapper of\n * a different model that adds in equivalent support.\n */\n llm: LanguageModelLike;\n /** Tools this agent has access to. */\n tools: StructuredToolInterface[] | ToolDefinition[];\n /** The prompt to use, must have an input key of `agent_scratchpad`. */\n prompt: ChatPromptTemplate;\n /**\n * Whether to invoke the underlying model in streaming mode,\n * allowing streaming of intermediate steps. Defaults to true.\n */\n streamRunnable?: boolean;\n};\n/**\n * Create an agent that uses tools.\n * @param params Params required to create the agent. Includes an LLM, tools, and prompt.\n * @returns A runnable sequence representing an agent. It takes as input all the same input\n * variables as the prompt passed in does. It returns as output either an\n * AgentAction or AgentFinish.\n * @example\n * ```typescript\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n * import { ChatPromptTemplate, MessagesPlaceholder } from \"@langchain/core/prompts\";\n * import { AgentExecutor, createToolCallingAgent } from \"langchain/agents\";\n *\n * const prompt = ChatPromptTemplate.fromMessages(\n * [\n * [\"system\", \"You are a helpful assistant\"],\n * [\"placeholder\", \"{chat_history}\"],\n * [\"human\", \"{input}\"],\n * [\"placeholder\", \"{agent_scratchpad}\"],\n * ]\n * );\n *\n *\n * const llm = new ChatAnthropic({\n * modelName: \"claude-3-opus-20240229\",\n * temperature: 0,\n * });\n *\n * // Define the tools the agent will have access to.\n * const tools = [...];\n *\n * const agent = createToolCallingAgent({ llm, tools, prompt });\n *\n * const agentExecutor = new AgentExecutor({ agent, tools });\n *\n * const result = await agentExecutor.invoke({input: \"what is LangChain?\"});\n *\n * // Using with chat history\n * import { AIMessage, HumanMessage } from \"@langchain/core/messages\";\n *\n * const result2 = await agentExecutor.invoke(\n * {\n * input: \"what's my name?\",\n * chat_history: [\n * new HumanMessage({content: \"hi! my name is bob\"}),\n * new AIMessage({content: \"Hello Bob! How can I assist you today?\"}),\n * ],\n * }\n * );\n * ```\n */\nexport declare function createToolCallingAgent({ llm, tools, prompt, streamRunnable }: CreateToolCallingAgentParams): AgentRunnableSequence<{\n steps: ToolsAgentStep[];\n}, import(\"@langchain/core/agents\").AgentFinish | import(\"@langchain/core/agents\").AgentAction[]>;\n//# sourceMappingURL=index.d.ts.map"],"mappings":";;;;;;;;;;;AAQYM,KAAAA,4BAAAA,GAA4B;EAM/BJ;;;;AAIqB;EAyDNK,GAAAA,EA7DfL,iBA6DeK;EAAyBC;EAAKC,KAAAA,EA3D3CR,uBA2D2CQ,EAAAA,GA3DfN,cA2DeM,EAAAA;EAAOC;EAAQC,MAAAA,EAzDzDX,kBAyDyDW;EAAkBL;;;;EAA+BF,cAAAA,CAAAA,EAAAA,OAAAA;AAAqB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAnHG,sBAAAA;;;;;GAA+DD,+BAA+BF;SAC3GC;GAAcO,uBAAAA,CACWC,WAAAA,GAAWD,uBAAAA,CAAoCE,WAAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseChatMemory, BaseChatMemoryInput } from "../../../memory/chat_memory.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _langchain_core_messages2 from "@langchain/core/messages";
|
|
3
3
|
import { InputValues, MemoryVariables, OutputValues } from "@langchain/core/memory";
|
|
4
4
|
import { ChatOpenAI } from "@langchain/openai";
|
|
5
5
|
|
|
@@ -37,7 +37,7 @@ declare class OpenAIAgentTokenBufferMemory extends BaseChatMemory {
|
|
|
37
37
|
* Retrieves the messages from the chat history.
|
|
38
38
|
* @returns Promise that resolves with the messages from the chat history.
|
|
39
39
|
*/
|
|
40
|
-
getMessages(): Promise<
|
|
40
|
+
getMessages(): Promise<_langchain_core_messages2.BaseMessage<_langchain_core_messages2.MessageStructure<_langchain_core_messages2.MessageToolSet>, _langchain_core_messages2.MessageType>[]>;
|
|
41
41
|
/**
|
|
42
42
|
* Loads memory variables from the input values.
|
|
43
43
|
* @param _values Input values.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token_buffer_memory.d.ts","names":["ChatOpenAI","InputValues","MemoryVariables","OutputValues","BaseChatMemory","BaseChatMemoryInput","OpenAIAgentTokenBufferMemoryFields","OpenAIAgentTokenBufferMemory","
|
|
1
|
+
{"version":3,"file":"token_buffer_memory.d.ts","names":["ChatOpenAI","InputValues","MemoryVariables","OutputValues","BaseChatMemory","BaseChatMemoryInput","OpenAIAgentTokenBufferMemoryFields","OpenAIAgentTokenBufferMemory","_langchain_core_messages2","MessageToolSet","MessageStructure","MessageType","BaseMessage","Promise"],"sources":["../../../../src/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts"],"sourcesContent":["import { ChatOpenAI } from \"@langchain/openai\";\nimport { InputValues, MemoryVariables, OutputValues } from \"@langchain/core/memory\";\nimport { BaseChatMemory, BaseChatMemoryInput } from \"../../../memory/chat_memory.js\";\n/**\n * Type definition for the fields required to initialize an instance of\n * OpenAIAgentTokenBufferMemory.\n */\nexport type OpenAIAgentTokenBufferMemoryFields = BaseChatMemoryInput & {\n llm: ChatOpenAI;\n humanPrefix?: string;\n aiPrefix?: string;\n memoryKey?: string;\n maxTokenLimit?: number;\n returnMessages?: boolean;\n outputKey?: string;\n intermediateStepsKey?: string;\n};\n/**\n * Memory used to save agent output and intermediate steps.\n */\nexport declare class OpenAIAgentTokenBufferMemory extends BaseChatMemory {\n humanPrefix: string;\n aiPrefix: string;\n llm: ChatOpenAI;\n memoryKey: string;\n maxTokenLimit: number;\n returnMessages: boolean;\n outputKey: string;\n intermediateStepsKey: string;\n constructor(fields: OpenAIAgentTokenBufferMemoryFields);\n get memoryKeys(): string[];\n /**\n * Retrieves the messages from the chat history.\n * @returns Promise that resolves with the messages from the chat history.\n */\n getMessages(): Promise<import(\"@langchain/core/messages\").BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[]>;\n /**\n * Loads memory variables from the input values.\n * @param _values Input values.\n * @returns Promise that resolves with the loaded memory variables.\n */\n loadMemoryVariables(_values: InputValues): Promise<MemoryVariables>;\n /**\n * Saves the context of the chat, including user input, AI output, and\n * intermediate steps. Prunes the chat history if the total token count\n * exceeds the maximum limit.\n * @param inputValues Input values.\n * @param outputValues Output values.\n * @returns Promise that resolves when the context has been saved.\n */\n saveContext(inputValues: InputValues, outputValues: OutputValues): Promise<void>;\n}\n//# sourceMappingURL=token_buffer_memory.d.ts.map"],"mappings":";;;;;;;;;;AAOA;AAaqBO,KAbTD,kCAAAA,GAAqCD,mBAaA,GAAA;EAGxCL,GAAAA,EAfAA,UAeAA;EAMeM,WAAAA,CAAAA,EAAAA,MAAAA;EAAkCE,QAAAA,CAAAA,EAAAA,MAAAA;EAMqHA,SAAAA,CAAAA,EAAAA,MAAAA;EAAlDA,aAAAA,CAAAA,EAAAA,MAAAA;EAAmGA,cAAAA,CAAAA,EAAAA,OAAlKI;EAA3CC,SAAAA,CAAAA,EAAAA,MAAAA;EAMcZ,oBAAAA,CAAAA,EAAAA,MAAAA;CAAsBC;;;;AASgBW,cA9BlDN,4BAAAA,SAAqCH,cAAAA,CA8BaS;EA9BbT,WAAAA,EAAAA,MAAAA;EAAc,QAAA,EAAA,MAAA;OAG/DJ;;;;;;sBAMeM;;;;;;iBAMLO,QAA6ML,yBAAAA,CAAlKI,YAAiHJ,yBAAAA,CAAlEE,iBANnDF,yBAAAA,CAMuGC,cAAAA,GAApCD,yBAAAA,CAAwFG,WAAAA;;;;;;+BAMpLV,cAAcY,QAAQX;;;;;;;;;2BAS1BD,2BAA2BE,eAAeU"}
|
|
@@ -6,7 +6,7 @@ import { ChatGeneration, Generation } from "@langchain/core/outputs";
|
|
|
6
6
|
import { BaseCallbackConfig, Callbacks } from "@langchain/core/callbacks/manager";
|
|
7
7
|
import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
|
|
8
8
|
import { ChainValues } from "@langchain/core/utils/types";
|
|
9
|
-
import * as
|
|
9
|
+
import * as _langchain_core_prompt_values4 from "@langchain/core/prompt_values";
|
|
10
10
|
|
|
11
11
|
//#region src/evaluation/comparison/pairwise.d.ts
|
|
12
12
|
/**
|
|
@@ -30,7 +30,7 @@ declare class PairwiseStringEvalChain extends LLMPairwiseStringEvaluator {
|
|
|
30
30
|
skipReferenceWarning: string;
|
|
31
31
|
outputParser: PairwiseStringResultOutputParser;
|
|
32
32
|
static resolvePairwiseCriteria(criteria?: CriteriaLike): Record<string, string>;
|
|
33
|
-
static resolvePairwisePrompt(prompt?: BasePromptTemplate): BasePromptTemplate<any,
|
|
33
|
+
static resolvePairwisePrompt(prompt?: BasePromptTemplate): BasePromptTemplate<any, _langchain_core_prompt_values4.BasePromptValueInterface, any>;
|
|
34
34
|
/**
|
|
35
35
|
* Create a new instance of the PairwiseStringEvalChain.
|
|
36
36
|
* @param llm
|
|
@@ -49,7 +49,7 @@ declare class PairwiseStringEvalChain extends LLMPairwiseStringEvaluator {
|
|
|
49
49
|
declare class LabeledPairwiseStringEvalChain extends PairwiseStringEvalChain {
|
|
50
50
|
static lc_name(): string;
|
|
51
51
|
requiresReference: boolean;
|
|
52
|
-
static resolvePairwisePrompt(prompt?: BasePromptTemplate): BasePromptTemplate<any,
|
|
52
|
+
static resolvePairwisePrompt(prompt?: BasePromptTemplate): BasePromptTemplate<any, _langchain_core_prompt_values4.BasePromptValueInterface, any>;
|
|
53
53
|
}
|
|
54
54
|
//#endregion
|
|
55
55
|
export { LabeledPairwiseStringEvalChain, PairwiseStringEvalChain, PairwiseStringResultOutputParser };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pairwise.d.ts","names":["BaseLanguageModelInterface","BaseLLMOutputParser","ChainValues","ChatGeneration","Generation","BasePromptTemplate","Callbacks","BaseCallbackConfig","EvalOutputType","LLMEvalChainInput","LLMPairwiseStringEvaluator","LLMPairwiseStringEvaluatorArgs","ExtractLLMCallOptions","CriteriaLike","PairwiseStringResultOutputParser","Promise","PairwiseStringEvalChain","Record","
|
|
1
|
+
{"version":3,"file":"pairwise.d.ts","names":["BaseLanguageModelInterface","BaseLLMOutputParser","ChainValues","ChatGeneration","Generation","BasePromptTemplate","Callbacks","BaseCallbackConfig","EvalOutputType","LLMEvalChainInput","LLMPairwiseStringEvaluator","LLMPairwiseStringEvaluatorArgs","ExtractLLMCallOptions","CriteriaLike","PairwiseStringResultOutputParser","Promise","PairwiseStringEvalChain","Record","_langchain_core_prompt_values4","BasePromptValueInterface","Omit","Partial","LabeledPairwiseStringEvalChain"],"sources":["../../../src/evaluation/comparison/pairwise.d.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { BaseLLMOutputParser } from \"@langchain/core/output_parsers\";\nimport { ChainValues } from \"@langchain/core/utils/types\";\nimport { ChatGeneration, Generation } from \"@langchain/core/outputs\";\nimport { BasePromptTemplate } from \"@langchain/core/prompts\";\nimport { Callbacks, BaseCallbackConfig } from \"@langchain/core/callbacks/manager\";\nimport { EvalOutputType, LLMEvalChainInput, LLMPairwiseStringEvaluator, LLMPairwiseStringEvaluatorArgs, type ExtractLLMCallOptions } from \"../base.js\";\nimport { CriteriaLike } from \"../criteria/criteria.js\";\n/**\n * A parser for the output of the PairwiseStringEvalChain.\n */\nexport declare class PairwiseStringResultOutputParser extends BaseLLMOutputParser<EvalOutputType> {\n static lc_name(): string;\n lc_namespace: string[];\n parseResult(generations: Generation[] | ChatGeneration[], _callbacks: Callbacks | undefined): Promise<EvalOutputType>;\n}\n/**\n * A chain for comparing two outputs, such as the outputs\n * of two models, prompts, or outputs of a single model on similar inputs.\n */\nexport declare class PairwiseStringEvalChain extends LLMPairwiseStringEvaluator {\n static lc_name(): string;\n criterionName?: string;\n evaluationName?: string;\n requiresInput: boolean;\n requiresReference: boolean;\n skipReferenceWarning: string;\n outputParser: PairwiseStringResultOutputParser;\n static resolvePairwiseCriteria(criteria?: CriteriaLike): Record<string, string>;\n static resolvePairwisePrompt(prompt?: BasePromptTemplate): BasePromptTemplate<any, import(\"@langchain/core/prompt_values\").BasePromptValueInterface, any>;\n /**\n * Create a new instance of the PairwiseStringEvalChain.\n * @param llm\n * @param criteria The criteria to use for evaluation.\n * @param chainOptions Options to pass to the chain.\n */\n static fromLLM(llm: BaseLanguageModelInterface, criteria?: CriteriaLike, chainOptions?: Partial<Omit<LLMEvalChainInput, \"llm\">>): Promise<PairwiseStringEvalChain>;\n _prepareOutput(result: ChainValues): any;\n _evaluateStringPairs(args: LLMPairwiseStringEvaluatorArgs, callOptions: ExtractLLMCallOptions<this[\"llm\"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;\n}\n/**\n * A chain for comparing two outputs, such as the outputs\n * of two models, prompts, or outputs of a single model on similar inputs,\n * with labeled preferences.\n */\nexport declare class LabeledPairwiseStringEvalChain extends PairwiseStringEvalChain {\n static lc_name(): string;\n requiresReference: boolean;\n static resolvePairwisePrompt(prompt?: BasePromptTemplate): BasePromptTemplate<any, import(\"@langchain/core/prompt_values\").BasePromptValueInterface, any>;\n}\n//# sourceMappingURL=pairwise.d.ts.map"],"mappings":";;;;;;;;;;;;;;AAWqBc,cAAAA,gCAAAA,SAAyCb,mBAAT,CAA6BO,cAA7B,CAAA,CAAA;EAA6BA,OAAAA,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAGrDJ,YAAAA,EAAAA,MAAAA,EAAAA;EAAeD,WAAAA,CAAAA,WAAAA,EAAfC,UAAeD,EAAAA,GAAAA,cAAAA,EAAAA,EAAAA,UAAAA,EAA8BG,SAA9BH,GAAAA,SAAAA,CAAAA,EAAsDY,OAAtDZ,CAA8DK,cAA9DL,CAAAA;;;;;AAHqC;AAS5Da,cAAAA,uBAAAA,SAAgCN,0BAAAA,CAAT;EAO1BI,OAAAA,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAC4BD,aAAAA,CAAAA,EAAAA,MAAAA;EAAeI,cAAAA,CAAAA,EAAAA,MAAAA;EACnBZ,aAAAA,EAAAA,OAAAA;EAAkBa,iBAAAA,EAAAA,OAAAA;EAAGb,oBAAAA,EAAAA,MAAAA;EAOvCL,YAAAA,EATNc,gCASMd;EAAuCa,OAAAA,uBAAAA,CAAAA,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BaseLLMOutputParser } from "@langchain/core/output_parsers";
|
|
8
8
|
import { ChainValues } from "@langchain/core/utils/types";
|
|
9
|
-
import * as
|
|
9
|
+
import * as _langchain_core_prompt_values1 from "@langchain/core/prompt_values";
|
|
10
10
|
|
|
11
11
|
//#region src/evaluation/criteria/criteria.d.ts
|
|
12
12
|
/**
|
|
@@ -50,7 +50,7 @@ declare class CriteriaEvalChain extends LLMStringEvaluator {
|
|
|
50
50
|
* Resolve the prompt to use for the evaluation.
|
|
51
51
|
* @param prompt
|
|
52
52
|
*/
|
|
53
|
-
static resolvePrompt(prompt?: BasePromptTemplate): BasePromptTemplate<any,
|
|
53
|
+
static resolvePrompt(prompt?: BasePromptTemplate): BasePromptTemplate<any, _langchain_core_prompt_values1.BasePromptValueInterface, any>;
|
|
54
54
|
/**
|
|
55
55
|
* Create a new instance of the CriteriaEvalChain.
|
|
56
56
|
* @param llm
|
|
@@ -76,7 +76,7 @@ declare class CriteriaEvalChain extends LLMStringEvaluator {
|
|
|
76
76
|
declare class LabeledCriteriaEvalChain extends CriteriaEvalChain {
|
|
77
77
|
static lc_name(): string;
|
|
78
78
|
requiresReference: boolean;
|
|
79
|
-
static resolvePrompt(prompt?: BasePromptTemplate): BasePromptTemplate<any,
|
|
79
|
+
static resolvePrompt(prompt?: BasePromptTemplate): BasePromptTemplate<any, _langchain_core_prompt_values1.BasePromptValueInterface, any>;
|
|
80
80
|
}
|
|
81
81
|
//#endregion
|
|
82
82
|
export { Criteria, CriteriaEvalChain, CriteriaEvalInput, CriteriaLike, CriteriaResultOutputParser, LabeledCriteriaEvalChain };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"criteria.d.ts","names":["BaseLanguageModelInterface","BaseLLMOutputParser","ChainValues","ChatGeneration","Generation","BasePromptTemplate","Callbacks","BaseCallbackConfig","EvalOutputType","LLMEvalChainInput","LLMStringEvaluator","StringEvaluatorArgs","ExtractLLMCallOptions","ConstitutionalPrinciple","Criteria","CriteriaLike","CriteriaResultOutputParser","Promise","CriteriaEvalInput","CriteriaEvalChain","Record","
|
|
1
|
+
{"version":3,"file":"criteria.d.ts","names":["BaseLanguageModelInterface","BaseLLMOutputParser","ChainValues","ChatGeneration","Generation","BasePromptTemplate","Callbacks","BaseCallbackConfig","EvalOutputType","LLMEvalChainInput","LLMStringEvaluator","StringEvaluatorArgs","ExtractLLMCallOptions","ConstitutionalPrinciple","Criteria","CriteriaLike","CriteriaResultOutputParser","Promise","CriteriaEvalInput","CriteriaEvalChain","Record","_langchain_core_prompt_values1","BasePromptValueInterface","Omit","Partial","input","prediction","reference","LabeledCriteriaEvalChain"],"sources":["../../../src/evaluation/criteria/criteria.d.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { BaseLLMOutputParser } from \"@langchain/core/output_parsers\";\nimport { ChainValues } from \"@langchain/core/utils/types\";\nimport { ChatGeneration, Generation } from \"@langchain/core/outputs\";\nimport { BasePromptTemplate } from \"@langchain/core/prompts\";\nimport { Callbacks, BaseCallbackConfig } from \"@langchain/core/callbacks/manager\";\nimport { EvalOutputType, LLMEvalChainInput, LLMStringEvaluator, StringEvaluatorArgs, type ExtractLLMCallOptions } from \"../base.js\";\nimport { ConstitutionalPrinciple } from \"../../chains/constitutional_ai/constitutional_principle.js\";\n/**\n * A Criteria to evaluate.\n */\nexport type Criteria = \"conciseness\" | \"relevance\" | \"correctness\" | \"coherence\" | \"harmfulness\" | \"maliciousness\" | \"helpfulness\" | \"controversiality\" | \"misogyny\" | \"criminality\" | \"insensitivity\" | \"depth\" | \"creativity\" | \"detail\";\nexport type CriteriaLike = {\n [key: string]: string;\n} | Criteria | ConstitutionalPrinciple;\n/**\n * A parser for the output of the CriteriaEvalChain.\n */\nexport declare class CriteriaResultOutputParser extends BaseLLMOutputParser<EvalOutputType> {\n lc_namespace: string[];\n parseResult(generations: Generation[] | ChatGeneration[], _callbacks: Callbacks | undefined): Promise<EvalOutputType>;\n}\nexport interface CriteriaEvalInput {\n input?: string;\n output: string;\n reference?: string;\n}\nexport declare class CriteriaEvalChain extends LLMStringEvaluator {\n static lc_name(): string;\n criterionName?: string;\n evaluationName?: string;\n requiresInput: boolean;\n requiresReference: boolean;\n skipReferenceWarning: string;\n outputParser: BaseLLMOutputParser<EvalOutputType>;\n /**\n * Resolve the criteria to evaluate.\n * @param criteria The criteria to evaluate the runs against. It can be:\n * - a mapping of a criterion name to its description\n * - a single criterion name present in one of the default criteria\n * - a single `ConstitutionalPrinciple` instance\n *\n * @return A dictionary mapping criterion names to descriptions.\n */\n static resolveCriteria(criteria?: CriteriaLike): Record<string, string>;\n /**\n * Resolve the prompt to use for the evaluation.\n * @param prompt\n */\n static resolvePrompt(prompt?: BasePromptTemplate): BasePromptTemplate<any, import(\"@langchain/core/prompt_values\").BasePromptValueInterface, any>;\n /**\n * Create a new instance of the CriteriaEvalChain.\n * @param llm\n * @param criteria\n * @param chainOptions Options to pass to the constructor of the LLMChain.\n */\n static fromLLM(llm: BaseLanguageModelInterface, criteria?: CriteriaLike, chainOptions?: Partial<Omit<LLMEvalChainInput, \"llm\">>): Promise<CriteriaEvalChain>;\n getEvalInput({ input, prediction, reference }: StringEvaluatorArgs): CriteriaEvalInput;\n /**\n * Prepare the output of the evaluation.\n * @param result\n */\n _prepareOutput(result: ChainValues): any;\n _evaluateStrings(args: StringEvaluatorArgs & ExtractLLMCallOptions<this[\"llm\"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;\n}\n/**\n * Criteria evaluation chain that requires references.\n */\nexport declare class LabeledCriteriaEvalChain extends CriteriaEvalChain {\n static lc_name(): string;\n requiresReference: boolean;\n static resolvePrompt(prompt?: BasePromptTemplate): BasePromptTemplate<any, import(\"@langchain/core/prompt_values\").BasePromptValueInterface, any>;\n}\n//# sourceMappingURL=criteria.d.ts.map"],"mappings":";;;;;;;;;;;;;;AAWYc,KAAAA,QAAAA,GAAQ,aAAA,GAAA,WAAA,GAAA,aAAA,GAAA,WAAA,GAAA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A,EAdxEZ,kBAcwEY,CAAAA,GAAAA,EAd3EI,8BAAAA,CAAmEC,wBAAAA,EAcQL,GAAAA,CAAAA;EApChFP;AAAkB;AAyCjE;;;;EAAsDS,OAAAA,OAAAA,CAAAA,GAAAA,EAZ9BnB,0BAY8BmB,EAAAA,QAAAA,CAAAA,EAZSJ,YAYTI,EAAAA,YAAAA,CAAAA,EAZsCK,OAYtCL,CAZ8CI,IAY9CJ,CAZmDV,iBAYnDU,EAAAA,KAAAA,CAAAA,CAAAA,CAAAA,EAZgFF,OAYhFE,CAZwFA,iBAYxFA,CAAAA;EAAiB,YAAA,CAAA;IAAA,KAAA;IAAA,UAAA;IAAA;EAAA,CAAA,EAXpBR,mBAWoB,CAAA,EAXEO,iBAWF;;;;;yBAN5ChB;yBACAS,sBAAsBC,6CAA6CN,YAAYC,qBAAqBU,QAAQf;;;;;cAKlH0B,wBAAAA,SAAiCT,iBAAAA;;;gCAGpBd,qBAAqBA,wBAAHgB,8BAAAA,CAAmEC,wBAAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ObjectTool } from "./schema.js";
|
|
2
2
|
import { BaseChatPromptTemplate, SerializedBasePromptTemplate } from "@langchain/core/prompts";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _langchain_core_messages0 from "@langchain/core/messages";
|
|
4
4
|
import { BaseMessage } from "@langchain/core/messages";
|
|
5
5
|
import { PartialValues } from "@langchain/core/utils/types";
|
|
6
6
|
import { VectorStoreRetrieverInterface } from "@langchain/core/vectorstores";
|
|
@@ -54,7 +54,7 @@ declare class AutoGPTPrompt extends BaseChatPromptTemplate implements AutoGPTPro
|
|
|
54
54
|
memory: VectorStoreRetrieverInterface;
|
|
55
55
|
messages: BaseMessage[];
|
|
56
56
|
user_input: string;
|
|
57
|
-
}): Promise<BaseMessage<
|
|
57
|
+
}): Promise<BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[]>;
|
|
58
58
|
/**
|
|
59
59
|
* This method is not implemented in the AutoGPTPrompt class and will
|
|
60
60
|
* throw an error if called.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.d.ts","names":["VectorStoreRetrieverInterface","BaseChatPromptTemplate","SerializedBasePromptTemplate","BaseMessage","PartialValues","ObjectTool","AutoGPTPromptInput","Promise","AutoGPTPrompt","goals","memory","previousMessages","user_input","
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","names":["VectorStoreRetrieverInterface","BaseChatPromptTemplate","SerializedBasePromptTemplate","BaseMessage","PartialValues","ObjectTool","AutoGPTPromptInput","Promise","AutoGPTPrompt","goals","memory","previousMessages","user_input","_langchain_core_messages0","MessageToolSet","MessageStructure","MessageType"],"sources":["../../../src/experimental/autogpt/prompt.d.ts"],"sourcesContent":["import type { VectorStoreRetrieverInterface } from \"@langchain/core/vectorstores\";\nimport { BaseChatPromptTemplate, SerializedBasePromptTemplate } from \"@langchain/core/prompts\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { PartialValues } from \"@langchain/core/utils/types\";\nimport { ObjectTool } from \"./schema.js\";\n/**\n * Interface for the input parameters of the AutoGPTPrompt class.\n */\nexport interface AutoGPTPromptInput {\n aiName: string;\n aiRole: string;\n tools: ObjectTool[];\n tokenCounter: (text: string) => Promise<number>;\n sendTokenLimit?: number;\n}\n/**\n * Class used to generate prompts for the AutoGPT model. It takes into\n * account the AI's name, role, tools, token counter, and send token\n * limit. The class also handles the formatting of messages and the\n * construction of the full prompt.\n */\nexport declare class AutoGPTPrompt extends BaseChatPromptTemplate implements AutoGPTPromptInput {\n aiName: string;\n aiRole: string;\n tools: ObjectTool[];\n tokenCounter: (text: string) => Promise<number>;\n sendTokenLimit: number;\n constructor(fields: AutoGPTPromptInput);\n _getPromptType(): \"autogpt\";\n /**\n * Constructs the full prompt based on the provided goals.\n * @param goals An array of goals.\n * @returns The full prompt as a string.\n */\n constructFullPrompt(goals: string[]): string;\n /**\n * Formats the messages based on the provided parameters.\n * @param goals An array of goals.\n * @param memory A VectorStoreRetriever instance.\n * @param messages An array of previous messages.\n * @param user_input The user's input.\n * @returns An array of formatted messages.\n */\n formatMessages({ goals, memory, messages: previousMessages, user_input }: {\n goals: string[];\n memory: VectorStoreRetrieverInterface;\n messages: BaseMessage[];\n user_input: string;\n }): Promise<BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[]>;\n /**\n * This method is not implemented in the AutoGPTPrompt class and will\n * throw an error if called.\n * @param _values Partial values.\n * @returns Throws an error.\n */\n partial(_values: PartialValues): Promise<BaseChatPromptTemplate>;\n serialize(): SerializedBasePromptTemplate;\n}\n//# sourceMappingURL=prompt.d.ts.map"],"mappings":";;;;;;;;;;;AAQiBM,UAAAA,kBAAAA,CAAkB;EAadE,MAAAA,EAAAA,MAAAA;EAGVH,MAAAA,EAAAA,MAAAA;EACyBE,KAAAA,EAdzBF,UAcyBE,EAAAA;EAEZD,YAAAA,EAAAA,CAAAA,IAAAA,EAAAA,MAAAA,EAAAA,GAfYC,OAeZD,CAAAA,MAAAA,CAAAA;EAgBHG,cAAAA,CAAAA,EAAAA,MAAAA;;;;;;;;AAK0DI,cA3B1DL,aAAAA,SAAsBP,sBAAAA,YAAkCK,kBA2B0FU,CAAAA;EAAvJb,MAAAA,EAAAA,MAAAA;EAARI,MAAAA,EAAAA,MAAAA;EAOaH,KAAAA,EA/BVC,UA+BUD,EAAAA;EAAwBH,YAAAA,EAAAA,CAAAA,IAAAA,EAAAA,MAAAA,EAAAA,GA9BTM,OA8BSN,CAAAA,MAAAA,CAAAA;EAARM,cAAAA,EAAAA,MAAAA;EACpBL,WAAAA,CAAAA,MAAAA,EA7BOI,kBA6BPJ;EAnC0BD,cAAAA,CAAAA,CAAAA,EAAAA,SAAAA;EAAkCK;AAAkB;;;;;;;;;;;;;;;;cAsBjDK;;;;YAE9BX;cACEG;;MAEVI,QAAQJ,YAAiHU,yBAAAA,CAAlEE,iBAFlCF,yBAAAA,CAEsFC,cAAAA,GAApCD,yBAAAA,CAAwFG,WAAAA;;;;;;;mBAOlJZ,gBAAgBG,QAAQN;eAC5BC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom_format.d.ts","names":["InputValues","ParsedFStringNode","PromptTemplate","PromptTemplateInput","TypedPromptInputValues","CustomFormatPromptTemplateInput","RunInput","Omit","CustomFormatPromptTemplate","PartialVariableName","Record","customParser","Symbol","Promise"],"sources":["../../../src/experimental/prompts/custom_format.d.ts"],"sourcesContent":["import type { InputValues } from \"@langchain/core/utils/types\";\nimport { type ParsedFStringNode, PromptTemplate, type PromptTemplateInput, TypedPromptInputValues } from \"@langchain/core/prompts\";\nexport type CustomFormatPromptTemplateInput<RunInput extends InputValues> = Omit<PromptTemplateInput<RunInput, string>, \"templateFormat\"> & {\n customParser: (template: string) => ParsedFStringNode[];\n templateValidator?: (template: string, inputVariables: string[]) => boolean;\n renderer: (template: string, values: InputValues) => string;\n};\nexport declare class CustomFormatPromptTemplate<RunInput extends InputValues = any, PartialVariableName extends string = any> extends PromptTemplate<RunInput, PartialVariableName> {\n static lc_name(): string;\n lc_serializable: boolean;\n templateValidator?: (template: string, inputVariables: string[]) => boolean;\n renderer: (template: string, values: InputValues) => string;\n constructor(input: CustomFormatPromptTemplateInput<RunInput>);\n /**\n * Load prompt template from a template\n */\n static fromTemplate<RunInput extends InputValues = Record<string, any>>(template: string, { customParser, ...rest }: Omit<CustomFormatPromptTemplateInput<RunInput>, \"template\" | \"inputVariables\">): CustomFormatPromptTemplate<RunInput extends Symbol ? never : RunInput, any>;\n /**\n * Formats the prompt template with the provided values.\n * @param values The values to be used to format the prompt template.\n * @returns A promise that resolves to a string which is the formatted prompt.\n */\n format(values: TypedPromptInputValues<RunInput>): Promise<string>;\n}\n//# sourceMappingURL=custom_format.d.ts.map"],"mappings":";;;;KAEYK,iDAAiDL,eAAeO,KAAKJ,oBAAoBG;sCAC7DL;EAD5BI,iBAAAA,CAAAA,EAAAA,CAAAA,QAAAA,EAAAA,MAA+B,
|
|
1
|
+
{"version":3,"file":"custom_format.d.ts","names":["InputValues","ParsedFStringNode","PromptTemplate","PromptTemplateInput","TypedPromptInputValues","CustomFormatPromptTemplateInput","RunInput","Omit","CustomFormatPromptTemplate","PartialVariableName","Record","customParser","Symbol","Promise"],"sources":["../../../src/experimental/prompts/custom_format.d.ts"],"sourcesContent":["import type { InputValues } from \"@langchain/core/utils/types\";\nimport { type ParsedFStringNode, PromptTemplate, type PromptTemplateInput, TypedPromptInputValues } from \"@langchain/core/prompts\";\nexport type CustomFormatPromptTemplateInput<RunInput extends InputValues> = Omit<PromptTemplateInput<RunInput, string>, \"templateFormat\"> & {\n customParser: (template: string) => ParsedFStringNode[];\n templateValidator?: (template: string, inputVariables: string[]) => boolean;\n renderer: (template: string, values: InputValues) => string;\n};\nexport declare class CustomFormatPromptTemplate<RunInput extends InputValues = any, PartialVariableName extends string = any> extends PromptTemplate<RunInput, PartialVariableName> {\n static lc_name(): string;\n lc_serializable: boolean;\n templateValidator?: (template: string, inputVariables: string[]) => boolean;\n renderer: (template: string, values: InputValues) => string;\n constructor(input: CustomFormatPromptTemplateInput<RunInput>);\n /**\n * Load prompt template from a template\n */\n static fromTemplate<RunInput extends InputValues = Record<string, any>>(template: string, { customParser, ...rest }: Omit<CustomFormatPromptTemplateInput<RunInput>, \"template\" | \"inputVariables\">): CustomFormatPromptTemplate<RunInput extends Symbol ? never : RunInput, any>;\n /**\n * Formats the prompt template with the provided values.\n * @param values The values to be used to format the prompt template.\n * @returns A promise that resolves to a string which is the formatted prompt.\n */\n format(values: TypedPromptInputValues<RunInput>): Promise<string>;\n}\n//# sourceMappingURL=custom_format.d.ts.map"],"mappings":";;;;KAEYK,iDAAiDL,eAAeO,KAAKJ,oBAAoBG;sCAC7DL;EAD5BI,iBAAAA,CAAAA,EAAAA,CAAAA,QAAAA,EAAAA,MAA+B,EAAAC,cA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version":3,"file":"handlebars.d.ts","names":["InputValues","CustomFormatPromptTemplate","CustomFormatPromptTemplateInput","parseHandlebars","_langchain_core_prompts0","ParsedTemplateNode","interpolateHandlebars","HandlebarsPromptTemplateInput","RunInput","HandlebarsPromptTemplate","Record","Omit","Symbol"],"sources":["../../../src/experimental/prompts/handlebars.d.ts"],"sourcesContent":["import type { InputValues } from \"@langchain/core/utils/types\";\nimport { CustomFormatPromptTemplate, CustomFormatPromptTemplateInput } from \"./custom_format.js\";\nexport declare const parseHandlebars: (template: string) => import(\"@langchain/core/prompts\").ParsedTemplateNode[];\nexport declare const interpolateHandlebars: (template: string, values: InputValues) => string;\nexport type HandlebarsPromptTemplateInput<RunInput extends InputValues> = CustomFormatPromptTemplateInput<RunInput>;\nexport declare class HandlebarsPromptTemplate<RunInput extends InputValues = any> extends CustomFormatPromptTemplate<RunInput> {\n static lc_name(): string;\n /**\n * Load prompt template from a template\n */\n static fromTemplate<RunInput extends InputValues = Record<string, any>>(template: string, params?: Omit<HandlebarsPromptTemplateInput<RunInput>, \"template\" | \"inputVariables\" | \"customParser\" | \"templateValidator\" | \"renderer\">): CustomFormatPromptTemplate<RunInput extends Symbol ? never : RunInput, any>;\n}\n//# sourceMappingURL=handlebars.d.ts.map"],"mappings":";;;;;cAEqBG,uCAA6FC,wBAAAA,CAApBC,kBAAkB;cAC3FC,kDAAkDN;KAC3DO,+CAA+CP,eAAeE,gCAAgCM;AAFrFL,cAGAM,wBAH6FL,CAAAA,iBAGnDJ,WAH+BK,
|
|
1
|
+
{"version":3,"file":"handlebars.d.ts","names":["InputValues","CustomFormatPromptTemplate","CustomFormatPromptTemplateInput","parseHandlebars","_langchain_core_prompts0","ParsedTemplateNode","interpolateHandlebars","HandlebarsPromptTemplateInput","RunInput","HandlebarsPromptTemplate","Record","Omit","Symbol"],"sources":["../../../src/experimental/prompts/handlebars.d.ts"],"sourcesContent":["import type { InputValues } from \"@langchain/core/utils/types\";\nimport { CustomFormatPromptTemplate, CustomFormatPromptTemplateInput } from \"./custom_format.js\";\nexport declare const parseHandlebars: (template: string) => import(\"@langchain/core/prompts\").ParsedTemplateNode[];\nexport declare const interpolateHandlebars: (template: string, values: InputValues) => string;\nexport type HandlebarsPromptTemplateInput<RunInput extends InputValues> = CustomFormatPromptTemplateInput<RunInput>;\nexport declare class HandlebarsPromptTemplate<RunInput extends InputValues = any> extends CustomFormatPromptTemplate<RunInput> {\n static lc_name(): string;\n /**\n * Load prompt template from a template\n */\n static fromTemplate<RunInput extends InputValues = Record<string, any>>(template: string, params?: Omit<HandlebarsPromptTemplateInput<RunInput>, \"template\" | \"inputVariables\" | \"customParser\" | \"templateValidator\" | \"renderer\">): CustomFormatPromptTemplate<RunInput extends Symbol ? never : RunInput, any>;\n}\n//# sourceMappingURL=handlebars.d.ts.map"],"mappings":";;;;;cAEqBG,uCAA6FC,wBAAAA,CAApBC,kBAAkB;cAC3FC,kDAAkDN;KAC3DO,+CAA+CP,eAAeE,gCAAgCM;AAFrFL,cAGAM,wBAH6FL,CAAAA,iBAGnDJ,WAH+BK,GAAkB,GAAA,CAAA,SAGtBJ,0BAHsB,CAGKO,QAHL,CAAA,CAAA;EAC3FF,OAAAA,OAAAA,CAAAA,CAAAA,EAAAA,MAAwE;EACjFC;;;EAA8DL,OAAAA,YAAAA,CAAAA,iBAMjCF,WANiCE,GAMnBQ,MANmBR,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,CAAAA,CAAAA,QAAAA,EAAAA,MAAAA,EAAAA,MAAAA,CAAAA,EAM6BS,IAN7BT,CAMkCK,6BANlCL,CAMgEM,QANhEN,CAAAA,EAAAA,UAAAA,GAAAA,gBAAAA,GAAAA,cAAAA,GAAAA,mBAAAA,GAAAA,UAAAA,CAAAA,CAAAA,EAMgKD,0BANhKC,CAM2LM,QAN3LN,SAM4MU,MAN5MV,GAAAA,KAAAA,GAM6NM,QAN7NN,EAAAA,GAAAA,CAAAA;AAA+B"}
|
package/dist/util/sql_utils.cjs
CHANGED
|
@@ -35,8 +35,8 @@ const formatToSqlTable = (rawResultsTableAndColumn) => {
|
|
|
35
35
|
};
|
|
36
36
|
const getTableAndColumnsName = async (appDataSource) => {
|
|
37
37
|
let sql;
|
|
38
|
-
if (appDataSource.options.type === "postgres") {
|
|
39
|
-
const schema = appDataSource.options?.schema ?? "public";
|
|
38
|
+
if (appDataSource.options.type === "postgres" || appDataSource.options.type === "aurora-postgres") {
|
|
39
|
+
const schema = appDataSource.options.type === "postgres" ? appDataSource.options?.schema ?? "public" : "public";
|
|
40
40
|
sql = `SELECT
|
|
41
41
|
t.table_name,
|
|
42
42
|
c.*
|
|
@@ -124,6 +124,7 @@ const generateTableInfoFromTables = async (tables, appDataSource, nbSampleRow, c
|
|
|
124
124
|
const tableCustomDescription = customDescription && Object.keys(customDescription).includes(currentTable.tableName) ? `${customDescription[currentTable.tableName]}\n` : "";
|
|
125
125
|
let schema = null;
|
|
126
126
|
if (appDataSource.options.type === "postgres") schema = appDataSource.options?.schema ?? "public";
|
|
127
|
+
else if (appDataSource.options.type === "aurora-postgres") schema = "public";
|
|
127
128
|
else if (appDataSource.options.type === "mssql") schema = appDataSource.options?.schema;
|
|
128
129
|
else if (appDataSource.options.type === "sap") schema = appDataSource.options?.schema ?? appDataSource.options?.username ?? "public";
|
|
129
130
|
else if (appDataSource.options.type === "oracle") schema = appDataSource.options.schema;
|
|
@@ -136,7 +137,7 @@ const generateTableInfoFromTables = async (tables, appDataSource, nbSampleRow, c
|
|
|
136
137
|
let sqlSelectInfoQuery;
|
|
137
138
|
if (appDataSource.options.type === "mysql") sqlSelectInfoQuery = `SELECT * FROM \`${currentTable.tableName}\` LIMIT ${nbSampleRow};\n`;
|
|
138
139
|
else if (appDataSource.options.type === "postgres") {
|
|
139
|
-
const schema$1 = appDataSource.options?.schema ?? "public";
|
|
140
|
+
const schema$1 = appDataSource.options.type === "postgres" ? appDataSource.options?.schema ?? "public" : "public";
|
|
140
141
|
sqlSelectInfoQuery = `SELECT * FROM "${schema$1}"."${currentTable.tableName}" LIMIT ${nbSampleRow};\n`;
|
|
141
142
|
} else if (appDataSource.options.type === "mssql") {
|
|
142
143
|
const schema$1 = appDataSource.options?.schema;
|
|
@@ -159,7 +160,7 @@ const generateTableInfoFromTables = async (tables, appDataSource, nbSampleRow, c
|
|
|
159
160
|
return globalString;
|
|
160
161
|
};
|
|
161
162
|
const getPromptTemplateFromDataSource = (appDataSource) => {
|
|
162
|
-
if (appDataSource.options.type === "postgres") return require_sql_db_prompt.SQL_POSTGRES_PROMPT;
|
|
163
|
+
if (appDataSource.options.type === "postgres" || appDataSource.options.type === "aurora-postgres") return require_sql_db_prompt.SQL_POSTGRES_PROMPT;
|
|
163
164
|
if (appDataSource.options.type === "sqlite") return require_sql_db_prompt.SQL_SQLITE_PROMPT;
|
|
164
165
|
if (appDataSource.options.type === "mysql") return require_sql_db_prompt.SQL_MYSQL_PROMPT;
|
|
165
166
|
if (appDataSource.options.type === "mssql") return require_sql_db_prompt.SQL_MSSQL_PROMPT;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql_utils.cjs","names":["tablesFromDatabase: Array<SqlTable>","listTables: Array<string>","errorPrefixMsg: string","onlyTableNames: Array<string>","table: SqlTable","includeTables: Array<string>","ignoreTables: Array<string>","rawResultsTableAndColumn: Array<RawResultTableAndColumn>","sqlTable: Array<SqlTable>","appDataSource: DataSource","sql","rep: Array<{ [key: string]: string }>","repLowerCase: Array<RawResultTableAndColumn>","rawResult: unknown","tables: Array<SqlTable> | undefined","nbSampleRow: number","customDescription?: Record<string, string>","schema","SQL_POSTGRES_PROMPT","SQL_SQLITE_PROMPT","SQL_MYSQL_PROMPT","SQL_MSSQL_PROMPT","SQL_SAP_HANA_PROMPT","SQL_ORACLE_PROMPT","DEFAULT_SQL_DATABASE_PROMPT"],"sources":["../../src/util/sql_utils.ts"],"sourcesContent":["import type { DataSource, DataSourceOptions } from \"typeorm\";\nimport type { PromptTemplate } from \"@langchain/core/prompts\";\nimport {\n DEFAULT_SQL_DATABASE_PROMPT,\n SQL_SAP_HANA_PROMPT,\n SQL_MSSQL_PROMPT,\n SQL_MYSQL_PROMPT,\n SQL_POSTGRES_PROMPT,\n SQL_SQLITE_PROMPT,\n SQL_ORACLE_PROMPT,\n} from \"../chains/sql_db/sql_db_prompt.js\";\n\ninterface RawResultTableAndColumn {\n table_name: string;\n column_name: string;\n data_type: string | undefined;\n is_nullable: string;\n}\n\nexport interface SqlDatabaseParams {\n includesTables?: Array<string>;\n ignoreTables?: Array<string>;\n sampleRowsInTableInfo?: number;\n customDescription?: Record<string, string>;\n}\n\nexport interface SqlDatabaseOptionsParams extends SqlDatabaseParams {\n appDataSourceOptions: DataSourceOptions;\n}\n\nexport interface SqlDatabaseDataSourceParams extends SqlDatabaseParams {\n appDataSource: DataSource;\n}\n\nexport type SerializedSqlDatabase = SqlDatabaseOptionsParams & {\n _type: string;\n};\n\nexport interface SqlTable {\n tableName: string;\n columns: SqlColumn[];\n}\n\nexport interface SqlColumn {\n columnName: string;\n dataType?: string;\n isNullable?: boolean;\n}\n\nexport const verifyListTablesExistInDatabase = (\n tablesFromDatabase: Array<SqlTable>,\n listTables: Array<string>,\n errorPrefixMsg: string\n): void => {\n const onlyTableNames: Array<string> = tablesFromDatabase.map(\n (table: SqlTable) => table.tableName\n );\n if (listTables.length > 0) {\n for (const tableName of listTables) {\n if (!onlyTableNames.includes(tableName)) {\n throw new Error(\n `${errorPrefixMsg} the table ${tableName} was not found in the database`\n );\n }\n }\n }\n};\n\nexport const verifyIncludeTablesExistInDatabase = (\n tablesFromDatabase: Array<SqlTable>,\n includeTables: Array<string>\n): void => {\n verifyListTablesExistInDatabase(\n tablesFromDatabase,\n includeTables,\n \"Include tables not found in database:\"\n );\n};\n\nexport const verifyIgnoreTablesExistInDatabase = (\n tablesFromDatabase: Array<SqlTable>,\n ignoreTables: Array<string>\n): void => {\n verifyListTablesExistInDatabase(\n tablesFromDatabase,\n ignoreTables,\n \"Ignore tables not found in database:\"\n );\n};\n\nconst formatToSqlTable = (\n rawResultsTableAndColumn: Array<RawResultTableAndColumn>\n): Array<SqlTable> => {\n const sqlTable: Array<SqlTable> = [];\n for (const oneResult of rawResultsTableAndColumn) {\n const sqlColumn = {\n columnName: oneResult.column_name,\n dataType: oneResult.data_type,\n isNullable: oneResult.is_nullable === \"YES\",\n };\n const currentTable = sqlTable.find(\n (oneTable) => oneTable.tableName === oneResult.table_name\n );\n if (currentTable) {\n currentTable.columns.push(sqlColumn);\n } else {\n const newTable = {\n tableName: oneResult.table_name,\n columns: [sqlColumn],\n };\n sqlTable.push(newTable);\n }\n }\n\n return sqlTable;\n};\n\nexport const getTableAndColumnsName = async (\n appDataSource: DataSource\n): Promise<Array<SqlTable>> => {\n let sql;\n if (appDataSource.options.type === \"postgres\") {\n const schema = appDataSource.options?.schema ?? \"public\";\n sql = `SELECT \n t.table_name, \n c.* \n FROM \n information_schema.tables t \n JOIN information_schema.columns c \n ON t.table_name = c.table_name \n WHERE \n t.table_schema = '${schema}' \n AND c.table_schema = '${schema}' \n ORDER BY \n t.table_name,\n c.ordinal_position;`;\n const rep = await appDataSource.query(sql);\n\n return formatToSqlTable(rep);\n }\n\n if (\n appDataSource.options.type === \"sqlite\" ||\n appDataSource.options.type === \"better-sqlite3\" ||\n appDataSource.options.type === \"sqljs\"\n ) {\n sql =\n \"SELECT \\n\" +\n \" m.name AS table_name,\\n\" +\n \" p.name AS column_name,\\n\" +\n \" p.type AS data_type,\\n\" +\n \" CASE \\n\" +\n \" WHEN p.\\\"notnull\\\" = 0 THEN 'YES' \\n\" +\n \" ELSE 'NO' \\n\" +\n \" END AS is_nullable \\n\" +\n \"FROM \\n\" +\n \" sqlite_master m \\n\" +\n \"JOIN \\n\" +\n \" pragma_table_info(m.name) p \\n\" +\n \"WHERE \\n\" +\n \" m.type = 'table' AND \\n\" +\n \" m.name NOT LIKE 'sqlite_%';\\n\";\n\n const rep = await appDataSource.query(sql);\n\n return formatToSqlTable(rep);\n }\n\n if (\n appDataSource.options.type === \"mysql\" ||\n appDataSource.options.type === \"aurora-mysql\"\n ) {\n sql =\n \"SELECT \" +\n \"TABLE_NAME AS table_name, \" +\n \"COLUMN_NAME AS column_name, \" +\n \"DATA_TYPE AS data_type, \" +\n \"IS_NULLABLE AS is_nullable \" +\n \"FROM INFORMATION_SCHEMA.COLUMNS \" +\n `WHERE TABLE_SCHEMA = '${appDataSource.options.database}';`;\n\n const rep = await appDataSource.query(sql);\n\n return formatToSqlTable(rep);\n }\n\n if (appDataSource.options.type === \"mssql\") {\n const schema = appDataSource.options?.schema;\n const sql = `SELECT\n TABLE_NAME AS table_name,\n COLUMN_NAME AS column_name,\n DATA_TYPE AS data_type,\n IS_NULLABLE AS is_nullable\n FROM INFORMATION_SCHEMA.COLUMNS\n ${schema && `WHERE TABLE_SCHEMA = '${schema}'`} \nORDER BY TABLE_NAME, ORDINAL_POSITION;`;\n\n const rep = await appDataSource.query(sql);\n return formatToSqlTable(rep);\n }\n\n if (appDataSource.options.type === \"sap\") {\n const schema = appDataSource.options?.schema ?? \"public\";\n sql = `SELECT\n TABLE_NAME,\n COLUMN_NAME,\n DATA_TYPE_NAME AS data_type,\n CASE WHEN IS_NULLABLE='TRUE' THEN 'YES' ELSE 'NO' END AS is_nullable\n FROM TABLE_COLUMNS\n WHERE SCHEMA_NAME='${schema}'`;\n\n const rep: Array<{ [key: string]: string }> =\n await appDataSource.query(sql);\n\n const repLowerCase: Array<RawResultTableAndColumn> = [];\n rep.forEach((_rep) =>\n repLowerCase.push({\n table_name: _rep.TABLE_NAME,\n column_name: _rep.COLUMN_NAME,\n data_type: _rep.DATA_TYPE,\n is_nullable: _rep.IS_NULLABLE,\n })\n );\n\n return formatToSqlTable(repLowerCase);\n }\n if (appDataSource.options.type === \"oracle\") {\n const schemaName = appDataSource.options.schema;\n const sql = ` \n SELECT\n TABLE_NAME AS \"table_name\",\n COLUMN_NAME AS \"column_name\",\n DATA_TYPE AS \"data_type\",\n NULLABLE AS \"is_nullable\"\n FROM ALL_TAB_COLS\n WHERE\n OWNER = UPPER('${schemaName}')`;\n const rep = await appDataSource.query(sql);\n return formatToSqlTable(rep);\n }\n throw new Error(\"Database type not implemented yet\");\n};\n\nconst formatSqlResponseToSimpleTableString = (rawResult: unknown): string => {\n if (!rawResult || !Array.isArray(rawResult) || rawResult.length === 0) {\n return \"\";\n }\n\n let globalString = \"\";\n for (const oneRow of rawResult) {\n globalString += `${Object.values(oneRow).reduce(\n (completeString, columnValue) => `${completeString} ${columnValue}`,\n \"\"\n )}\\n`;\n }\n\n return globalString;\n};\n\nexport const generateTableInfoFromTables = async (\n tables: Array<SqlTable> | undefined,\n appDataSource: DataSource,\n nbSampleRow: number,\n customDescription?: Record<string, string>\n): Promise<string> => {\n if (!tables) {\n return \"\";\n }\n\n let globalString = \"\";\n for (const currentTable of tables) {\n // Add the custom info of the table\n const tableCustomDescription =\n customDescription &&\n Object.keys(customDescription).includes(currentTable.tableName)\n ? `${customDescription[currentTable.tableName]}\\n`\n : \"\";\n // Add the creation of the table in SQL\n let schema = null;\n if (appDataSource.options.type === \"postgres\") {\n schema = appDataSource.options?.schema ?? \"public\";\n } else if (appDataSource.options.type === \"mssql\") {\n schema = appDataSource.options?.schema;\n } else if (appDataSource.options.type === \"sap\") {\n schema =\n appDataSource.options?.schema ??\n appDataSource.options?.username ??\n \"public\";\n } else if (appDataSource.options.type === \"oracle\") {\n schema = appDataSource.options.schema;\n }\n let sqlCreateTableQuery = schema\n ? `CREATE TABLE \"${schema}\".\"${currentTable.tableName}\" (\\n`\n : `CREATE TABLE ${currentTable.tableName} (\\n`;\n for (const [key, currentColumn] of currentTable.columns.entries()) {\n if (key > 0) {\n sqlCreateTableQuery += \", \";\n }\n sqlCreateTableQuery += `${currentColumn.columnName} ${\n currentColumn.dataType\n } ${currentColumn.isNullable ? \"\" : \"NOT NULL\"}`;\n }\n sqlCreateTableQuery += \") \\n\";\n\n let sqlSelectInfoQuery;\n if (appDataSource.options.type === \"mysql\") {\n // We use backticks to quote the table names and thus allow for example spaces in table names\n sqlSelectInfoQuery = `SELECT * FROM \\`${currentTable.tableName}\\` LIMIT ${nbSampleRow};\\n`;\n } else if (appDataSource.options.type === \"postgres\") {\n const schema = appDataSource.options?.schema ?? \"public\";\n sqlSelectInfoQuery = `SELECT * FROM \"${schema}\".\"${currentTable.tableName}\" LIMIT ${nbSampleRow};\\n`;\n } else if (appDataSource.options.type === \"mssql\") {\n const schema = appDataSource.options?.schema;\n sqlSelectInfoQuery = schema\n ? `SELECT TOP ${nbSampleRow} * FROM ${schema}.[${currentTable.tableName}];\\n`\n : `SELECT TOP ${nbSampleRow} * FROM [${currentTable.tableName}];\\n`;\n } else if (appDataSource.options.type === \"sap\") {\n const schema =\n appDataSource.options?.schema ??\n appDataSource.options?.username ??\n \"public\";\n sqlSelectInfoQuery = `SELECT * FROM \"${schema}\".\"${currentTable.tableName}\" LIMIT ${nbSampleRow};\\n`;\n } else if (appDataSource.options.type === \"oracle\") {\n sqlSelectInfoQuery = `SELECT * FROM \"${schema}\".\"${currentTable.tableName}\" WHERE ROWNUM <= '${nbSampleRow}'`;\n } else {\n sqlSelectInfoQuery = `SELECT * FROM \"${currentTable.tableName}\" LIMIT ${nbSampleRow};\\n`;\n }\n\n const columnNamesConcatString = `${currentTable.columns.reduce(\n (completeString, column) => `${completeString} ${column.columnName}`,\n \"\"\n )}\\n`;\n\n let sample = \"\";\n try {\n const infoObjectResult = nbSampleRow\n ? await appDataSource.query(sqlSelectInfoQuery)\n : null;\n sample = formatSqlResponseToSimpleTableString(infoObjectResult);\n } catch (error) {\n // If the request fails we catch it and only display a log message\n console.log(error);\n }\n\n globalString = globalString.concat(\n tableCustomDescription +\n sqlCreateTableQuery +\n sqlSelectInfoQuery +\n columnNamesConcatString +\n sample\n );\n }\n\n return globalString;\n};\n\nexport const getPromptTemplateFromDataSource = (\n appDataSource: DataSource\n): PromptTemplate => {\n if (appDataSource.options.type === \"postgres\") {\n return SQL_POSTGRES_PROMPT;\n }\n\n if (appDataSource.options.type === \"sqlite\") {\n return SQL_SQLITE_PROMPT;\n }\n\n if (appDataSource.options.type === \"mysql\") {\n return SQL_MYSQL_PROMPT;\n }\n\n if (appDataSource.options.type === \"mssql\") {\n return SQL_MSSQL_PROMPT;\n }\n\n if (appDataSource.options.type === \"sap\") {\n return SQL_SAP_HANA_PROMPT;\n }\n\n if (appDataSource.options.type === \"oracle\") {\n return SQL_ORACLE_PROMPT;\n }\n\n return DEFAULT_SQL_DATABASE_PROMPT;\n};\n"],"mappings":";;;AAiDA,MAAa,kCAAkC,CAC7CA,oBACAC,YACAC,mBACS;CACT,MAAMC,iBAAgC,mBAAmB,IACvD,CAACC,UAAoB,MAAM,UAC5B;AACD,KAAI,WAAW,SAAS,GACtB;OAAK,MAAM,aAAa,WACtB,KAAI,CAAC,eAAe,SAAS,UAAU,CACrC,OAAM,IAAI,MACR,GAAG,eAAe,WAAW,EAAE,UAAU,8BAA8B,CAAC;CAG7E;AAEJ;AAED,MAAa,qCAAqC,CAChDJ,oBACAK,kBACS;CACT,gCACE,oBACA,eACA,wCACD;AACF;AAED,MAAa,oCAAoC,CAC/CL,oBACAM,iBACS;CACT,gCACE,oBACA,cACA,uCACD;AACF;AAED,MAAM,mBAAmB,CACvBC,6BACoB;CACpB,MAAMC,WAA4B,CAAE;AACpC,MAAK,MAAM,aAAa,0BAA0B;EAChD,MAAM,YAAY;GAChB,YAAY,UAAU;GACtB,UAAU,UAAU;GACpB,YAAY,UAAU,gBAAgB;EACvC;EACD,MAAM,eAAe,SAAS,KAC5B,CAAC,aAAa,SAAS,cAAc,UAAU,WAChD;AACD,MAAI,cACF,aAAa,QAAQ,KAAK,UAAU;OAC/B;GACL,MAAM,WAAW;IACf,WAAW,UAAU;IACrB,SAAS,CAAC,SAAU;GACrB;GACD,SAAS,KAAK,SAAS;EACxB;CACF;AAED,QAAO;AACR;AAED,MAAa,yBAAyB,OACpCC,kBAC6B;CAC7B,IAAI;AACJ,KAAI,cAAc,QAAQ,SAA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ACrB,MAAM,cAAc,MAAM,mBAAmB,GAC7C;GACJ,SAAS,qCAAqC,iBAAiB;EAChE,SAAQ,OAAO;GAEd,QAAQ,IAAI,MAAM;EACnB;EAED,eAAe,aAAa,OAC1B,yBACE,sBACA,qBACA,0BACA,OACH;CACF;AAED,QAAO;AACR;AAED,MAAa,kCAAkC,CAC7CR,kBACmB;AACnB,KAAI,cAAc,QAAQ,SAAS,WACjC,QAAOS;AAGT,KAAI,cAAc,QAAQ,SAAS,SACjC,QAAOC;AAGT,KAAI,cAAc,QAAQ,SAAS,QACjC,QAAOC;AAGT,KAAI,cAAc,QAAQ,SAAS,QACjC,QAAOC;AAGT,KAAI,cAAc,QAAQ,SAAS,MACjC,QAAOC;AAGT,KAAI,cAAc,QAAQ,SAAS,SACjC,QAAOC;AAGT,QAAOC;AACR"}
|
|
1
|
+
{"version":3,"file":"sql_utils.cjs","names":["tablesFromDatabase: Array<SqlTable>","listTables: Array<string>","errorPrefixMsg: string","onlyTableNames: Array<string>","table: SqlTable","includeTables: Array<string>","ignoreTables: Array<string>","rawResultsTableAndColumn: Array<RawResultTableAndColumn>","sqlTable: Array<SqlTable>","appDataSource: DataSource","sql","rep: Array<{ [key: string]: string }>","repLowerCase: Array<RawResultTableAndColumn>","rawResult: unknown","tables: Array<SqlTable> | undefined","nbSampleRow: number","customDescription?: Record<string, string>","schema","SQL_POSTGRES_PROMPT","SQL_SQLITE_PROMPT","SQL_MYSQL_PROMPT","SQL_MSSQL_PROMPT","SQL_SAP_HANA_PROMPT","SQL_ORACLE_PROMPT","DEFAULT_SQL_DATABASE_PROMPT"],"sources":["../../src/util/sql_utils.ts"],"sourcesContent":["import type { DataSource, DataSourceOptions } from \"typeorm\";\nimport type { PromptTemplate } from \"@langchain/core/prompts\";\nimport {\n DEFAULT_SQL_DATABASE_PROMPT,\n SQL_SAP_HANA_PROMPT,\n SQL_MSSQL_PROMPT,\n SQL_MYSQL_PROMPT,\n SQL_POSTGRES_PROMPT,\n SQL_SQLITE_PROMPT,\n SQL_ORACLE_PROMPT,\n} from \"../chains/sql_db/sql_db_prompt.js\";\n\ninterface RawResultTableAndColumn {\n table_name: string;\n column_name: string;\n data_type: string | undefined;\n is_nullable: string;\n}\n\nexport interface SqlDatabaseParams {\n includesTables?: Array<string>;\n ignoreTables?: Array<string>;\n sampleRowsInTableInfo?: number;\n customDescription?: Record<string, string>;\n}\n\nexport interface SqlDatabaseOptionsParams extends SqlDatabaseParams {\n appDataSourceOptions: DataSourceOptions;\n}\n\nexport interface SqlDatabaseDataSourceParams extends SqlDatabaseParams {\n appDataSource: DataSource;\n}\n\nexport type SerializedSqlDatabase = SqlDatabaseOptionsParams & {\n _type: string;\n};\n\nexport interface SqlTable {\n tableName: string;\n columns: SqlColumn[];\n}\n\nexport interface SqlColumn {\n columnName: string;\n dataType?: string;\n isNullable?: boolean;\n}\n\nexport const verifyListTablesExistInDatabase = (\n tablesFromDatabase: Array<SqlTable>,\n listTables: Array<string>,\n errorPrefixMsg: string\n): void => {\n const onlyTableNames: Array<string> = tablesFromDatabase.map(\n (table: SqlTable) => table.tableName\n );\n if (listTables.length > 0) {\n for (const tableName of listTables) {\n if (!onlyTableNames.includes(tableName)) {\n throw new Error(\n `${errorPrefixMsg} the table ${tableName} was not found in the database`\n );\n }\n }\n }\n};\n\nexport const verifyIncludeTablesExistInDatabase = (\n tablesFromDatabase: Array<SqlTable>,\n includeTables: Array<string>\n): void => {\n verifyListTablesExistInDatabase(\n tablesFromDatabase,\n includeTables,\n \"Include tables not found in database:\"\n );\n};\n\nexport const verifyIgnoreTablesExistInDatabase = (\n tablesFromDatabase: Array<SqlTable>,\n ignoreTables: Array<string>\n): void => {\n verifyListTablesExistInDatabase(\n tablesFromDatabase,\n ignoreTables,\n \"Ignore tables not found in database:\"\n );\n};\n\nconst formatToSqlTable = (\n rawResultsTableAndColumn: Array<RawResultTableAndColumn>\n): Array<SqlTable> => {\n const sqlTable: Array<SqlTable> = [];\n for (const oneResult of rawResultsTableAndColumn) {\n const sqlColumn = {\n columnName: oneResult.column_name,\n dataType: oneResult.data_type,\n isNullable: oneResult.is_nullable === \"YES\",\n };\n const currentTable = sqlTable.find(\n (oneTable) => oneTable.tableName === oneResult.table_name\n );\n if (currentTable) {\n currentTable.columns.push(sqlColumn);\n } else {\n const newTable = {\n tableName: oneResult.table_name,\n columns: [sqlColumn],\n };\n sqlTable.push(newTable);\n }\n }\n\n return sqlTable;\n};\n\nexport const getTableAndColumnsName = async (\n appDataSource: DataSource\n): Promise<Array<SqlTable>> => {\n let sql;\n if (\n appDataSource.options.type === \"postgres\" ||\n appDataSource.options.type === \"aurora-postgres\"\n ) {\n const schema =\n appDataSource.options.type === \"postgres\"\n ? (appDataSource.options?.schema ?? \"public\")\n : \"public\";\n sql = `SELECT \n t.table_name, \n c.* \n FROM \n information_schema.tables t \n JOIN information_schema.columns c \n ON t.table_name = c.table_name \n WHERE \n t.table_schema = '${schema}' \n AND c.table_schema = '${schema}' \n ORDER BY \n t.table_name,\n c.ordinal_position;`;\n const rep = await appDataSource.query(sql);\n\n return formatToSqlTable(rep);\n }\n\n if (\n appDataSource.options.type === \"sqlite\" ||\n appDataSource.options.type === \"better-sqlite3\" ||\n appDataSource.options.type === \"sqljs\"\n ) {\n sql =\n \"SELECT \\n\" +\n \" m.name AS table_name,\\n\" +\n \" p.name AS column_name,\\n\" +\n \" p.type AS data_type,\\n\" +\n \" CASE \\n\" +\n \" WHEN p.\\\"notnull\\\" = 0 THEN 'YES' \\n\" +\n \" ELSE 'NO' \\n\" +\n \" END AS is_nullable \\n\" +\n \"FROM \\n\" +\n \" sqlite_master m \\n\" +\n \"JOIN \\n\" +\n \" pragma_table_info(m.name) p \\n\" +\n \"WHERE \\n\" +\n \" m.type = 'table' AND \\n\" +\n \" m.name NOT LIKE 'sqlite_%';\\n\";\n\n const rep = await appDataSource.query(sql);\n\n return formatToSqlTable(rep);\n }\n\n if (\n appDataSource.options.type === \"mysql\" ||\n appDataSource.options.type === \"aurora-mysql\"\n ) {\n sql =\n \"SELECT \" +\n \"TABLE_NAME AS table_name, \" +\n \"COLUMN_NAME AS column_name, \" +\n \"DATA_TYPE AS data_type, \" +\n \"IS_NULLABLE AS is_nullable \" +\n \"FROM INFORMATION_SCHEMA.COLUMNS \" +\n `WHERE TABLE_SCHEMA = '${appDataSource.options.database}';`;\n\n const rep = await appDataSource.query(sql);\n\n return formatToSqlTable(rep);\n }\n\n if (appDataSource.options.type === \"mssql\") {\n const schema = appDataSource.options?.schema;\n const sql = `SELECT\n TABLE_NAME AS table_name,\n COLUMN_NAME AS column_name,\n DATA_TYPE AS data_type,\n IS_NULLABLE AS is_nullable\n FROM INFORMATION_SCHEMA.COLUMNS\n ${schema && `WHERE TABLE_SCHEMA = '${schema}'`} \nORDER BY TABLE_NAME, ORDINAL_POSITION;`;\n\n const rep = await appDataSource.query(sql);\n return formatToSqlTable(rep);\n }\n\n if (appDataSource.options.type === \"sap\") {\n const schema = appDataSource.options?.schema ?? \"public\";\n sql = `SELECT\n TABLE_NAME,\n COLUMN_NAME,\n DATA_TYPE_NAME AS data_type,\n CASE WHEN IS_NULLABLE='TRUE' THEN 'YES' ELSE 'NO' END AS is_nullable\n FROM TABLE_COLUMNS\n WHERE SCHEMA_NAME='${schema}'`;\n\n const rep: Array<{ [key: string]: string }> =\n await appDataSource.query(sql);\n\n const repLowerCase: Array<RawResultTableAndColumn> = [];\n rep.forEach((_rep) =>\n repLowerCase.push({\n table_name: _rep.TABLE_NAME,\n column_name: _rep.COLUMN_NAME,\n data_type: _rep.DATA_TYPE,\n is_nullable: _rep.IS_NULLABLE,\n })\n );\n\n return formatToSqlTable(repLowerCase);\n }\n if (appDataSource.options.type === \"oracle\") {\n const schemaName = appDataSource.options.schema;\n const sql = ` \n SELECT\n TABLE_NAME AS \"table_name\",\n COLUMN_NAME AS \"column_name\",\n DATA_TYPE AS \"data_type\",\n NULLABLE AS \"is_nullable\"\n FROM ALL_TAB_COLS\n WHERE\n OWNER = UPPER('${schemaName}')`;\n const rep = await appDataSource.query(sql);\n return formatToSqlTable(rep);\n }\n throw new Error(\"Database type not implemented yet\");\n};\n\nconst formatSqlResponseToSimpleTableString = (rawResult: unknown): string => {\n if (!rawResult || !Array.isArray(rawResult) || rawResult.length === 0) {\n return \"\";\n }\n\n let globalString = \"\";\n for (const oneRow of rawResult) {\n globalString += `${Object.values(oneRow).reduce(\n (completeString, columnValue) => `${completeString} ${columnValue}`,\n \"\"\n )}\\n`;\n }\n\n return globalString;\n};\n\nexport const generateTableInfoFromTables = async (\n tables: Array<SqlTable> | undefined,\n appDataSource: DataSource,\n nbSampleRow: number,\n customDescription?: Record<string, string>\n): Promise<string> => {\n if (!tables) {\n return \"\";\n }\n\n let globalString = \"\";\n for (const currentTable of tables) {\n // Add the custom info of the table\n const tableCustomDescription =\n customDescription &&\n Object.keys(customDescription).includes(currentTable.tableName)\n ? `${customDescription[currentTable.tableName]}\\n`\n : \"\";\n // Add the creation of the table in SQL\n let schema = null;\n if (appDataSource.options.type === \"postgres\") {\n schema = appDataSource.options?.schema ?? \"public\";\n } else if (appDataSource.options.type === \"aurora-postgres\") {\n schema = \"public\";\n } else if (appDataSource.options.type === \"mssql\") {\n schema = appDataSource.options?.schema;\n } else if (appDataSource.options.type === \"sap\") {\n schema =\n appDataSource.options?.schema ??\n appDataSource.options?.username ??\n \"public\";\n } else if (appDataSource.options.type === \"oracle\") {\n schema = appDataSource.options.schema;\n }\n let sqlCreateTableQuery = schema\n ? `CREATE TABLE \"${schema}\".\"${currentTable.tableName}\" (\\n`\n : `CREATE TABLE ${currentTable.tableName} (\\n`;\n for (const [key, currentColumn] of currentTable.columns.entries()) {\n if (key > 0) {\n sqlCreateTableQuery += \", \";\n }\n sqlCreateTableQuery += `${currentColumn.columnName} ${\n currentColumn.dataType\n } ${currentColumn.isNullable ? \"\" : \"NOT NULL\"}`;\n }\n sqlCreateTableQuery += \") \\n\";\n\n let sqlSelectInfoQuery;\n if (appDataSource.options.type === \"mysql\") {\n // We use backticks to quote the table names and thus allow for example spaces in table names\n sqlSelectInfoQuery = `SELECT * FROM \\`${currentTable.tableName}\\` LIMIT ${nbSampleRow};\\n`;\n } else if (appDataSource.options.type === \"postgres\") {\n const schema =\n appDataSource.options.type === \"postgres\"\n ? (appDataSource.options?.schema ?? \"public\")\n : \"public\";\n sqlSelectInfoQuery = `SELECT * FROM \"${schema}\".\"${currentTable.tableName}\" LIMIT ${nbSampleRow};\\n`;\n } else if (appDataSource.options.type === \"mssql\") {\n const schema = appDataSource.options?.schema;\n sqlSelectInfoQuery = schema\n ? `SELECT TOP ${nbSampleRow} * FROM ${schema}.[${currentTable.tableName}];\\n`\n : `SELECT TOP ${nbSampleRow} * FROM [${currentTable.tableName}];\\n`;\n } else if (appDataSource.options.type === \"sap\") {\n const schema =\n appDataSource.options?.schema ??\n appDataSource.options?.username ??\n \"public\";\n sqlSelectInfoQuery = `SELECT * FROM \"${schema}\".\"${currentTable.tableName}\" LIMIT ${nbSampleRow};\\n`;\n } else if (appDataSource.options.type === \"oracle\") {\n sqlSelectInfoQuery = `SELECT * FROM \"${schema}\".\"${currentTable.tableName}\" WHERE ROWNUM <= '${nbSampleRow}'`;\n } else {\n sqlSelectInfoQuery = `SELECT * FROM \"${currentTable.tableName}\" LIMIT ${nbSampleRow};\\n`;\n }\n\n const columnNamesConcatString = `${currentTable.columns.reduce(\n (completeString, column) => `${completeString} ${column.columnName}`,\n \"\"\n )}\\n`;\n\n let sample = \"\";\n try {\n const infoObjectResult = nbSampleRow\n ? await appDataSource.query(sqlSelectInfoQuery)\n : null;\n sample = formatSqlResponseToSimpleTableString(infoObjectResult);\n } catch (error) {\n // If the request fails we catch it and only display a log message\n console.log(error);\n }\n\n globalString = globalString.concat(\n tableCustomDescription +\n sqlCreateTableQuery +\n sqlSelectInfoQuery +\n columnNamesConcatString +\n sample\n );\n }\n\n return globalString;\n};\n\nexport const getPromptTemplateFromDataSource = (\n appDataSource: DataSource\n): PromptTemplate => {\n if (\n appDataSource.options.type === \"postgres\" ||\n appDataSource.options.type === \"aurora-postgres\"\n ) {\n return SQL_POSTGRES_PROMPT;\n }\n\n if (appDataSource.options.type === \"sqlite\") {\n return SQL_SQLITE_PROMPT;\n }\n\n if (appDataSource.options.type === \"mysql\") {\n return SQL_MYSQL_PROMPT;\n }\n\n if (appDataSource.options.type === \"mssql\") {\n return SQL_MSSQL_PROMPT;\n }\n\n if (appDataSource.options.type === \"sap\") {\n return SQL_SAP_HANA_PROMPT;\n }\n\n if (appDataSource.options.type === \"oracle\") {\n return SQL_ORACLE_PROMPT;\n }\n\n return DEFAULT_SQL_DATABASE_PROMPT;\n};\n"],"mappings":";;;AAiDA,MAAa,kCAAkC,CAC7CA,oBACAC,YACAC,mBACS;CACT,MAAMC,iBAAgC,mBAAmB,IACvD,CAACC,UAAoB,MAAM,UAC5B;AACD,KAAI,WAAW,SAAS,GACtB;OAAK,MAAM,aAAa,WACtB,KAAI,CAAC,eAAe,SAAS,UAAU,CACrC,OAAM,IAAI,MACR,GAAG,eAAe,WAAW,EAAE,UAAU,8BAA8B,CAAC;CAG7E;AAEJ;AAED,MAAa,qCAAqC,CAChDJ,oBACAK,kBACS;CACT,gCACE,oBACA,eACA,wCACD;AACF;AAED,MAAa,oCAAoC,CAC/CL,oBACAM,iBACS;CACT,gCACE,oBACA,cACA,uCACD;AACF;AAED,MAAM,mBAAmB,CACvBC,6BACoB;CACpB,MAAMC,WAA4B,CAAE;AACpC,MAAK,MAAM,aAAa,0BAA0B;EAChD,MAAM,YAAY;GAChB,YAAY,UAAU;GACtB,UAAU,UAAU;GACpB,YAAY,UAAU,gBAAgB;EACvC;EACD,MAAM,eAAe,SAAS,KAC5B,CAAC,aAAa,SAAS,cAAc,UAAU,WAChD;AACD,MAAI,cACF,aAAa,QAAQ,KAAK,UAAU;OAC/B;GACL,MAAM,WAAW;IACf,WAAW,UAAU;IACrB,SAAS,CAAC,SAAU;GACrB;GACD,SAAS,KAAK,SAAS;EACxB;CACF;AAED,QAAO;AACR;AAED,M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Y,GAAG,CAAC;EAG1F,MAAM,0BAA0B,GAAG,aAAa,QAAQ,OACtD,CAAC,gBAAgB,WAAW,GAAG,eAAe,CAAC,EAAE,OAAO,YAAY,EACpE,GACD,CAAC,EAAE,CAAC;EAEL,IAAI,SAAS;AACb,MAAI;GACF,MAAM,mBAAmB,cACrB,MAAM,cAAc,MAAM,mBAAmB,GAC7C;GACJ,SAAS,qCAAqC,iBAAiB;EAChE,SAAQ,OAAO;GAEd,QAAQ,IAAI,MAAM;EACnB;EAED,eAAe,aAAa,OAC1B,yBACE,sBACA,qBACA,0BACA,OACH;CACF;AAED,QAAO;AACR;AAED,MAAa,kCAAkC,CAC7CR,kBACmB;AACnB,KACE,cAAc,QAAQ,SAAS,cAC/B,cAAc,QAAQ,SAAS,kBAE/B,QAAOS;AAGT,KAAI,cAAc,QAAQ,SAAS,SACjC,QAAOC;AAGT,KAAI,cAAc,QAAQ,SAAS,QACjC,QAAOC;AAGT,KAAI,cAAc,QAAQ,SAAS,QACjC,QAAOC;AAGT,KAAI,cAAc,QAAQ,SAAS,MACjC,QAAOC;AAGT,KAAI,cAAc,QAAQ,SAAS,SACjC,QAAOC;AAGT,QAAOC;AACR"}
|
package/dist/util/sql_utils.js
CHANGED
|
@@ -35,8 +35,8 @@ const formatToSqlTable = (rawResultsTableAndColumn) => {
|
|
|
35
35
|
};
|
|
36
36
|
const getTableAndColumnsName = async (appDataSource) => {
|
|
37
37
|
let sql;
|
|
38
|
-
if (appDataSource.options.type === "postgres") {
|
|
39
|
-
const schema = appDataSource.options?.schema ?? "public";
|
|
38
|
+
if (appDataSource.options.type === "postgres" || appDataSource.options.type === "aurora-postgres") {
|
|
39
|
+
const schema = appDataSource.options.type === "postgres" ? appDataSource.options?.schema ?? "public" : "public";
|
|
40
40
|
sql = `SELECT
|
|
41
41
|
t.table_name,
|
|
42
42
|
c.*
|
|
@@ -124,6 +124,7 @@ const generateTableInfoFromTables = async (tables, appDataSource, nbSampleRow, c
|
|
|
124
124
|
const tableCustomDescription = customDescription && Object.keys(customDescription).includes(currentTable.tableName) ? `${customDescription[currentTable.tableName]}\n` : "";
|
|
125
125
|
let schema = null;
|
|
126
126
|
if (appDataSource.options.type === "postgres") schema = appDataSource.options?.schema ?? "public";
|
|
127
|
+
else if (appDataSource.options.type === "aurora-postgres") schema = "public";
|
|
127
128
|
else if (appDataSource.options.type === "mssql") schema = appDataSource.options?.schema;
|
|
128
129
|
else if (appDataSource.options.type === "sap") schema = appDataSource.options?.schema ?? appDataSource.options?.username ?? "public";
|
|
129
130
|
else if (appDataSource.options.type === "oracle") schema = appDataSource.options.schema;
|
|
@@ -136,7 +137,7 @@ const generateTableInfoFromTables = async (tables, appDataSource, nbSampleRow, c
|
|
|
136
137
|
let sqlSelectInfoQuery;
|
|
137
138
|
if (appDataSource.options.type === "mysql") sqlSelectInfoQuery = `SELECT * FROM \`${currentTable.tableName}\` LIMIT ${nbSampleRow};\n`;
|
|
138
139
|
else if (appDataSource.options.type === "postgres") {
|
|
139
|
-
const schema$1 = appDataSource.options?.schema ?? "public";
|
|
140
|
+
const schema$1 = appDataSource.options.type === "postgres" ? appDataSource.options?.schema ?? "public" : "public";
|
|
140
141
|
sqlSelectInfoQuery = `SELECT * FROM "${schema$1}"."${currentTable.tableName}" LIMIT ${nbSampleRow};\n`;
|
|
141
142
|
} else if (appDataSource.options.type === "mssql") {
|
|
142
143
|
const schema$1 = appDataSource.options?.schema;
|
|
@@ -159,7 +160,7 @@ const generateTableInfoFromTables = async (tables, appDataSource, nbSampleRow, c
|
|
|
159
160
|
return globalString;
|
|
160
161
|
};
|
|
161
162
|
const getPromptTemplateFromDataSource = (appDataSource) => {
|
|
162
|
-
if (appDataSource.options.type === "postgres") return SQL_POSTGRES_PROMPT;
|
|
163
|
+
if (appDataSource.options.type === "postgres" || appDataSource.options.type === "aurora-postgres") return SQL_POSTGRES_PROMPT;
|
|
163
164
|
if (appDataSource.options.type === "sqlite") return SQL_SQLITE_PROMPT;
|
|
164
165
|
if (appDataSource.options.type === "mysql") return SQL_MYSQL_PROMPT;
|
|
165
166
|
if (appDataSource.options.type === "mssql") return SQL_MSSQL_PROMPT;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql_utils.js","names":["tablesFromDatabase: Array<SqlTable>","listTables: Array<string>","errorPrefixMsg: string","onlyTableNames: Array<string>","table: SqlTable","includeTables: Array<string>","ignoreTables: Array<string>","rawResultsTableAndColumn: Array<RawResultTableAndColumn>","sqlTable: Array<SqlTable>","appDataSource: DataSource","sql","rep: Array<{ [key: string]: string }>","repLowerCase: Array<RawResultTableAndColumn>","rawResult: unknown","tables: Array<SqlTable> | undefined","nbSampleRow: number","customDescription?: Record<string, string>","schema"],"sources":["../../src/util/sql_utils.ts"],"sourcesContent":["import type { DataSource, DataSourceOptions } from \"typeorm\";\nimport type { PromptTemplate } from \"@langchain/core/prompts\";\nimport {\n DEFAULT_SQL_DATABASE_PROMPT,\n SQL_SAP_HANA_PROMPT,\n SQL_MSSQL_PROMPT,\n SQL_MYSQL_PROMPT,\n SQL_POSTGRES_PROMPT,\n SQL_SQLITE_PROMPT,\n SQL_ORACLE_PROMPT,\n} from \"../chains/sql_db/sql_db_prompt.js\";\n\ninterface RawResultTableAndColumn {\n table_name: string;\n column_name: string;\n data_type: string | undefined;\n is_nullable: string;\n}\n\nexport interface SqlDatabaseParams {\n includesTables?: Array<string>;\n ignoreTables?: Array<string>;\n sampleRowsInTableInfo?: number;\n customDescription?: Record<string, string>;\n}\n\nexport interface SqlDatabaseOptionsParams extends SqlDatabaseParams {\n appDataSourceOptions: DataSourceOptions;\n}\n\nexport interface SqlDatabaseDataSourceParams extends SqlDatabaseParams {\n appDataSource: DataSource;\n}\n\nexport type SerializedSqlDatabase = SqlDatabaseOptionsParams & {\n _type: string;\n};\n\nexport interface SqlTable {\n tableName: string;\n columns: SqlColumn[];\n}\n\nexport interface SqlColumn {\n columnName: string;\n dataType?: string;\n isNullable?: boolean;\n}\n\nexport const verifyListTablesExistInDatabase = (\n tablesFromDatabase: Array<SqlTable>,\n listTables: Array<string>,\n errorPrefixMsg: string\n): void => {\n const onlyTableNames: Array<string> = tablesFromDatabase.map(\n (table: SqlTable) => table.tableName\n );\n if (listTables.length > 0) {\n for (const tableName of listTables) {\n if (!onlyTableNames.includes(tableName)) {\n throw new Error(\n `${errorPrefixMsg} the table ${tableName} was not found in the database`\n );\n }\n }\n }\n};\n\nexport const verifyIncludeTablesExistInDatabase = (\n tablesFromDatabase: Array<SqlTable>,\n includeTables: Array<string>\n): void => {\n verifyListTablesExistInDatabase(\n tablesFromDatabase,\n includeTables,\n \"Include tables not found in database:\"\n );\n};\n\nexport const verifyIgnoreTablesExistInDatabase = (\n tablesFromDatabase: Array<SqlTable>,\n ignoreTables: Array<string>\n): void => {\n verifyListTablesExistInDatabase(\n tablesFromDatabase,\n ignoreTables,\n \"Ignore tables not found in database:\"\n );\n};\n\nconst formatToSqlTable = (\n rawResultsTableAndColumn: Array<RawResultTableAndColumn>\n): Array<SqlTable> => {\n const sqlTable: Array<SqlTable> = [];\n for (const oneResult of rawResultsTableAndColumn) {\n const sqlColumn = {\n columnName: oneResult.column_name,\n dataType: oneResult.data_type,\n isNullable: oneResult.is_nullable === \"YES\",\n };\n const currentTable = sqlTable.find(\n (oneTable) => oneTable.tableName === oneResult.table_name\n );\n if (currentTable) {\n currentTable.columns.push(sqlColumn);\n } else {\n const newTable = {\n tableName: oneResult.table_name,\n columns: [sqlColumn],\n };\n sqlTable.push(newTable);\n }\n }\n\n return sqlTable;\n};\n\nexport const getTableAndColumnsName = async (\n appDataSource: DataSource\n): Promise<Array<SqlTable>> => {\n let sql;\n if (appDataSource.options.type === \"postgres\") {\n const schema = appDataSource.options?.schema ?? \"public\";\n sql = `SELECT \n t.table_name, \n c.* \n FROM \n information_schema.tables t \n JOIN information_schema.columns c \n ON t.table_name = c.table_name \n WHERE \n t.table_schema = '${schema}' \n AND c.table_schema = '${schema}' \n ORDER BY \n t.table_name,\n c.ordinal_position;`;\n const rep = await appDataSource.query(sql);\n\n return formatToSqlTable(rep);\n }\n\n if (\n appDataSource.options.type === \"sqlite\" ||\n appDataSource.options.type === \"better-sqlite3\" ||\n appDataSource.options.type === \"sqljs\"\n ) {\n sql =\n \"SELECT \\n\" +\n \" m.name AS table_name,\\n\" +\n \" p.name AS column_name,\\n\" +\n \" p.type AS data_type,\\n\" +\n \" CASE \\n\" +\n \" WHEN p.\\\"notnull\\\" = 0 THEN 'YES' \\n\" +\n \" ELSE 'NO' \\n\" +\n \" END AS is_nullable \\n\" +\n \"FROM \\n\" +\n \" sqlite_master m \\n\" +\n \"JOIN \\n\" +\n \" pragma_table_info(m.name) p \\n\" +\n \"WHERE \\n\" +\n \" m.type = 'table' AND \\n\" +\n \" m.name NOT LIKE 'sqlite_%';\\n\";\n\n const rep = await appDataSource.query(sql);\n\n return formatToSqlTable(rep);\n }\n\n if (\n appDataSource.options.type === \"mysql\" ||\n appDataSource.options.type === \"aurora-mysql\"\n ) {\n sql =\n \"SELECT \" +\n \"TABLE_NAME AS table_name, \" +\n \"COLUMN_NAME AS column_name, \" +\n \"DATA_TYPE AS data_type, \" +\n \"IS_NULLABLE AS is_nullable \" +\n \"FROM INFORMATION_SCHEMA.COLUMNS \" +\n `WHERE TABLE_SCHEMA = '${appDataSource.options.database}';`;\n\n const rep = await appDataSource.query(sql);\n\n return formatToSqlTable(rep);\n }\n\n if (appDataSource.options.type === \"mssql\") {\n const schema = appDataSource.options?.schema;\n const sql = `SELECT\n TABLE_NAME AS table_name,\n COLUMN_NAME AS column_name,\n DATA_TYPE AS data_type,\n IS_NULLABLE AS is_nullable\n FROM INFORMATION_SCHEMA.COLUMNS\n ${schema && `WHERE TABLE_SCHEMA = '${schema}'`} \nORDER BY TABLE_NAME, ORDINAL_POSITION;`;\n\n const rep = await appDataSource.query(sql);\n return formatToSqlTable(rep);\n }\n\n if (appDataSource.options.type === \"sap\") {\n const schema = appDataSource.options?.schema ?? \"public\";\n sql = `SELECT\n TABLE_NAME,\n COLUMN_NAME,\n DATA_TYPE_NAME AS data_type,\n CASE WHEN IS_NULLABLE='TRUE' THEN 'YES' ELSE 'NO' END AS is_nullable\n FROM TABLE_COLUMNS\n WHERE SCHEMA_NAME='${schema}'`;\n\n const rep: Array<{ [key: string]: string }> =\n await appDataSource.query(sql);\n\n const repLowerCase: Array<RawResultTableAndColumn> = [];\n rep.forEach((_rep) =>\n repLowerCase.push({\n table_name: _rep.TABLE_NAME,\n column_name: _rep.COLUMN_NAME,\n data_type: _rep.DATA_TYPE,\n is_nullable: _rep.IS_NULLABLE,\n })\n );\n\n return formatToSqlTable(repLowerCase);\n }\n if (appDataSource.options.type === \"oracle\") {\n const schemaName = appDataSource.options.schema;\n const sql = ` \n SELECT\n TABLE_NAME AS \"table_name\",\n COLUMN_NAME AS \"column_name\",\n DATA_TYPE AS \"data_type\",\n NULLABLE AS \"is_nullable\"\n FROM ALL_TAB_COLS\n WHERE\n OWNER = UPPER('${schemaName}')`;\n const rep = await appDataSource.query(sql);\n return formatToSqlTable(rep);\n }\n throw new Error(\"Database type not implemented yet\");\n};\n\nconst formatSqlResponseToSimpleTableString = (rawResult: unknown): string => {\n if (!rawResult || !Array.isArray(rawResult) || rawResult.length === 0) {\n return \"\";\n }\n\n let globalString = \"\";\n for (const oneRow of rawResult) {\n globalString += `${Object.values(oneRow).reduce(\n (completeString, columnValue) => `${completeString} ${columnValue}`,\n \"\"\n )}\\n`;\n }\n\n return globalString;\n};\n\nexport const generateTableInfoFromTables = async (\n tables: Array<SqlTable> | undefined,\n appDataSource: DataSource,\n nbSampleRow: number,\n customDescription?: Record<string, string>\n): Promise<string> => {\n if (!tables) {\n return \"\";\n }\n\n let globalString = \"\";\n for (const currentTable of tables) {\n // Add the custom info of the table\n const tableCustomDescription =\n customDescription &&\n Object.keys(customDescription).includes(currentTable.tableName)\n ? `${customDescription[currentTable.tableName]}\\n`\n : \"\";\n // Add the creation of the table in SQL\n let schema = null;\n if (appDataSource.options.type === \"postgres\") {\n schema = appDataSource.options?.schema ?? \"public\";\n } else if (appDataSource.options.type === \"mssql\") {\n schema = appDataSource.options?.schema;\n } else if (appDataSource.options.type === \"sap\") {\n schema =\n appDataSource.options?.schema ??\n appDataSource.options?.username ??\n \"public\";\n } else if (appDataSource.options.type === \"oracle\") {\n schema = appDataSource.options.schema;\n }\n let sqlCreateTableQuery = schema\n ? `CREATE TABLE \"${schema}\".\"${currentTable.tableName}\" (\\n`\n : `CREATE TABLE ${currentTable.tableName} (\\n`;\n for (const [key, currentColumn] of currentTable.columns.entries()) {\n if (key > 0) {\n sqlCreateTableQuery += \", \";\n }\n sqlCreateTableQuery += `${currentColumn.columnName} ${\n currentColumn.dataType\n } ${currentColumn.isNullable ? \"\" : \"NOT NULL\"}`;\n }\n sqlCreateTableQuery += \") \\n\";\n\n let sqlSelectInfoQuery;\n if (appDataSource.options.type === \"mysql\") {\n // We use backticks to quote the table names and thus allow for example spaces in table names\n sqlSelectInfoQuery = `SELECT * FROM \\`${currentTable.tableName}\\` LIMIT ${nbSampleRow};\\n`;\n } else if (appDataSource.options.type === \"postgres\") {\n const schema = appDataSource.options?.schema ?? \"public\";\n sqlSelectInfoQuery = `SELECT * FROM \"${schema}\".\"${currentTable.tableName}\" LIMIT ${nbSampleRow};\\n`;\n } else if (appDataSource.options.type === \"mssql\") {\n const schema = appDataSource.options?.schema;\n sqlSelectInfoQuery = schema\n ? `SELECT TOP ${nbSampleRow} * FROM ${schema}.[${currentTable.tableName}];\\n`\n : `SELECT TOP ${nbSampleRow} * FROM [${currentTable.tableName}];\\n`;\n } else if (appDataSource.options.type === \"sap\") {\n const schema =\n appDataSource.options?.schema ??\n appDataSource.options?.username ??\n \"public\";\n sqlSelectInfoQuery = `SELECT * FROM \"${schema}\".\"${currentTable.tableName}\" LIMIT ${nbSampleRow};\\n`;\n } else if (appDataSource.options.type === \"oracle\") {\n sqlSelectInfoQuery = `SELECT * FROM \"${schema}\".\"${currentTable.tableName}\" WHERE ROWNUM <= '${nbSampleRow}'`;\n } else {\n sqlSelectInfoQuery = `SELECT * FROM \"${currentTable.tableName}\" LIMIT ${nbSampleRow};\\n`;\n }\n\n const columnNamesConcatString = `${currentTable.columns.reduce(\n (completeString, column) => `${completeString} ${column.columnName}`,\n \"\"\n )}\\n`;\n\n let sample = \"\";\n try {\n const infoObjectResult = nbSampleRow\n ? await appDataSource.query(sqlSelectInfoQuery)\n : null;\n sample = formatSqlResponseToSimpleTableString(infoObjectResult);\n } catch (error) {\n // If the request fails we catch it and only display a log message\n console.log(error);\n }\n\n globalString = globalString.concat(\n tableCustomDescription +\n sqlCreateTableQuery +\n sqlSelectInfoQuery +\n columnNamesConcatString +\n sample\n );\n }\n\n return globalString;\n};\n\nexport const getPromptTemplateFromDataSource = (\n appDataSource: DataSource\n): PromptTemplate => {\n if (appDataSource.options.type === \"postgres\") {\n return SQL_POSTGRES_PROMPT;\n }\n\n if (appDataSource.options.type === \"sqlite\") {\n return SQL_SQLITE_PROMPT;\n }\n\n if (appDataSource.options.type === \"mysql\") {\n return SQL_MYSQL_PROMPT;\n }\n\n if (appDataSource.options.type === \"mssql\") {\n return SQL_MSSQL_PROMPT;\n }\n\n if (appDataSource.options.type === \"sap\") {\n return SQL_SAP_HANA_PROMPT;\n }\n\n if (appDataSource.options.type === \"oracle\") {\n return SQL_ORACLE_PROMPT;\n }\n\n return DEFAULT_SQL_DATABASE_PROMPT;\n};\n"],"mappings":";;;AAiDA,MAAa,kCAAkC,CAC7CA,oBACAC,YACAC,mBACS;CACT,MAAMC,iBAAgC,mBAAmB,IACvD,CAACC,UAAoB,MAAM,UAC5B;AACD,KAAI,WAAW,SAAS,GACtB;OAAK,MAAM,aAAa,WACtB,KAAI,CAAC,eAAe,SAAS,UAAU,CACrC,OAAM,IAAI,MACR,GAAG,eAAe,WAAW,EAAE,UAAU,8BAA8B,CAAC;CAG7E;AAEJ;AAED,MAAa,qCAAqC,CAChDJ,oBACAK,kBACS;CACT,gCACE,oBACA,eACA,wCACD;AACF;A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,QAAQ,SAAS,OAAO;GAC/C,MAAMA,WACJ,cAAc,SAAS,UACvB,cAAc,SAAS,YACvB;GACF,qBAAqB,CAAC,eAAe,EAAEA,SAAO,GAAG,EAAE,aAAa,UAAU,QAAQ,EAAE,YAAY,GAAG,CAAC;EACrG,WAAU,cAAc,QAAQ,SAAS,UACxC,qBAAqB,CAAC,eAAe,EAAE,OAAO,GAAG,EAAE,aAAa,UAAU,mBAAmB,EAAE,YAAY,CAAC,CAAC;OAE7G,qBAAqB,CAAC,eAAe,EAAE,aAAa,UAAU,QAAQ,EAAE,YAAY,GAAG,CAAC;EAG1F,MAAM,0BAA0B,GAAG,aAAa,QAAQ,OACtD,CAAC,gBAAgB,WAAW,GAAG,eAAe,CAAC,EAAE,OAAO,YAAY,EACpE,GACD,CAAC,EAAE,CAAC;EAEL,IAAI,SAAS;AACb,MAAI;GACF,MAAM,mBAAmB,cACrB,MAAM,cAAc,MAAM,mBAAmB,GAC7C;GACJ,SAAS,qCAAqC,iBAAiB;EAChE,SAAQ,OAAO;GAEd,QAAQ,IAAI,MAAM;EACnB;EAED,eAAe,aAAa,OAC1B,yBACE,sBACA,qBACA,0BACA,OACH;CACF;AAED,QAAO;AACR;AAED,MAAa,kCAAkC,CAC7CR,kBACmB;AACnB,KAAI,cAAc,QAAQ,SAAS,WACjC,QAAO;AAGT,KAAI,cAAc,QAAQ,SAAS,SACjC,QAAO;AAGT,KAAI,cAAc,QAAQ,SAAS,QACjC,QAAO;AAGT,KAAI,cAAc,QAAQ,SAAS,QACjC,QAAO;AAGT,KAAI,cAAc,QAAQ,SAAS,MACjC,QAAO;AAGT,KAAI,cAAc,QAAQ,SAAS,SACjC,QAAO;AAGT,QAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"sql_utils.js","names":["tablesFromDatabase: Array<SqlTable>","listTables: Array<string>","errorPrefixMsg: string","onlyTableNames: Array<string>","table: SqlTable","includeTables: Array<string>","ignoreTables: Array<string>","rawResultsTableAndColumn: Array<RawResultTableAndColumn>","sqlTable: Array<SqlTable>","appDataSource: DataSource","sql","rep: Array<{ [key: string]: string }>","repLowerCase: Array<RawResultTableAndColumn>","rawResult: unknown","tables: Array<SqlTable> | undefined","nbSampleRow: number","customDescription?: Record<string, string>","schema"],"sources":["../../src/util/sql_utils.ts"],"sourcesContent":["import type { DataSource, DataSourceOptions } from \"typeorm\";\nimport type { PromptTemplate } from \"@langchain/core/prompts\";\nimport {\n DEFAULT_SQL_DATABASE_PROMPT,\n SQL_SAP_HANA_PROMPT,\n SQL_MSSQL_PROMPT,\n SQL_MYSQL_PROMPT,\n SQL_POSTGRES_PROMPT,\n SQL_SQLITE_PROMPT,\n SQL_ORACLE_PROMPT,\n} from \"../chains/sql_db/sql_db_prompt.js\";\n\ninterface RawResultTableAndColumn {\n table_name: string;\n column_name: string;\n data_type: string | undefined;\n is_nullable: string;\n}\n\nexport interface SqlDatabaseParams {\n includesTables?: Array<string>;\n ignoreTables?: Array<string>;\n sampleRowsInTableInfo?: number;\n customDescription?: Record<string, string>;\n}\n\nexport interface SqlDatabaseOptionsParams extends SqlDatabaseParams {\n appDataSourceOptions: DataSourceOptions;\n}\n\nexport interface SqlDatabaseDataSourceParams extends SqlDatabaseParams {\n appDataSource: DataSource;\n}\n\nexport type SerializedSqlDatabase = SqlDatabaseOptionsParams & {\n _type: string;\n};\n\nexport interface SqlTable {\n tableName: string;\n columns: SqlColumn[];\n}\n\nexport interface SqlColumn {\n columnName: string;\n dataType?: string;\n isNullable?: boolean;\n}\n\nexport const verifyListTablesExistInDatabase = (\n tablesFromDatabase: Array<SqlTable>,\n listTables: Array<string>,\n errorPrefixMsg: string\n): void => {\n const onlyTableNames: Array<string> = tablesFromDatabase.map(\n (table: SqlTable) => table.tableName\n );\n if (listTables.length > 0) {\n for (const tableName of listTables) {\n if (!onlyTableNames.includes(tableName)) {\n throw new Error(\n `${errorPrefixMsg} the table ${tableName} was not found in the database`\n );\n }\n }\n }\n};\n\nexport const verifyIncludeTablesExistInDatabase = (\n tablesFromDatabase: Array<SqlTable>,\n includeTables: Array<string>\n): void => {\n verifyListTablesExistInDatabase(\n tablesFromDatabase,\n includeTables,\n \"Include tables not found in database:\"\n );\n};\n\nexport const verifyIgnoreTablesExistInDatabase = (\n tablesFromDatabase: Array<SqlTable>,\n ignoreTables: Array<string>\n): void => {\n verifyListTablesExistInDatabase(\n tablesFromDatabase,\n ignoreTables,\n \"Ignore tables not found in database:\"\n );\n};\n\nconst formatToSqlTable = (\n rawResultsTableAndColumn: Array<RawResultTableAndColumn>\n): Array<SqlTable> => {\n const sqlTable: Array<SqlTable> = [];\n for (const oneResult of rawResultsTableAndColumn) {\n const sqlColumn = {\n columnName: oneResult.column_name,\n dataType: oneResult.data_type,\n isNullable: oneResult.is_nullable === \"YES\",\n };\n const currentTable = sqlTable.find(\n (oneTable) => oneTable.tableName === oneResult.table_name\n );\n if (currentTable) {\n currentTable.columns.push(sqlColumn);\n } else {\n const newTable = {\n tableName: oneResult.table_name,\n columns: [sqlColumn],\n };\n sqlTable.push(newTable);\n }\n }\n\n return sqlTable;\n};\n\nexport const getTableAndColumnsName = async (\n appDataSource: DataSource\n): Promise<Array<SqlTable>> => {\n let sql;\n if (\n appDataSource.options.type === \"postgres\" ||\n appDataSource.options.type === \"aurora-postgres\"\n ) {\n const schema =\n appDataSource.options.type === \"postgres\"\n ? (appDataSource.options?.schema ?? \"public\")\n : \"public\";\n sql = `SELECT \n t.table_name, \n c.* \n FROM \n information_schema.tables t \n JOIN information_schema.columns c \n ON t.table_name = c.table_name \n WHERE \n t.table_schema = '${schema}' \n AND c.table_schema = '${schema}' \n ORDER BY \n t.table_name,\n c.ordinal_position;`;\n const rep = await appDataSource.query(sql);\n\n return formatToSqlTable(rep);\n }\n\n if (\n appDataSource.options.type === \"sqlite\" ||\n appDataSource.options.type === \"better-sqlite3\" ||\n appDataSource.options.type === \"sqljs\"\n ) {\n sql =\n \"SELECT \\n\" +\n \" m.name AS table_name,\\n\" +\n \" p.name AS column_name,\\n\" +\n \" p.type AS data_type,\\n\" +\n \" CASE \\n\" +\n \" WHEN p.\\\"notnull\\\" = 0 THEN 'YES' \\n\" +\n \" ELSE 'NO' \\n\" +\n \" END AS is_nullable \\n\" +\n \"FROM \\n\" +\n \" sqlite_master m \\n\" +\n \"JOIN \\n\" +\n \" pragma_table_info(m.name) p \\n\" +\n \"WHERE \\n\" +\n \" m.type = 'table' AND \\n\" +\n \" m.name NOT LIKE 'sqlite_%';\\n\";\n\n const rep = await appDataSource.query(sql);\n\n return formatToSqlTable(rep);\n }\n\n if (\n appDataSource.options.type === \"mysql\" ||\n appDataSource.options.type === \"aurora-mysql\"\n ) {\n sql =\n \"SELECT \" +\n \"TABLE_NAME AS table_name, \" +\n \"COLUMN_NAME AS column_name, \" +\n \"DATA_TYPE AS data_type, \" +\n \"IS_NULLABLE AS is_nullable \" +\n \"FROM INFORMATION_SCHEMA.COLUMNS \" +\n `WHERE TABLE_SCHEMA = '${appDataSource.options.database}';`;\n\n const rep = await appDataSource.query(sql);\n\n return formatToSqlTable(rep);\n }\n\n if (appDataSource.options.type === \"mssql\") {\n const schema = appDataSource.options?.schema;\n const sql = `SELECT\n TABLE_NAME AS table_name,\n COLUMN_NAME AS column_name,\n DATA_TYPE AS data_type,\n IS_NULLABLE AS is_nullable\n FROM INFORMATION_SCHEMA.COLUMNS\n ${schema && `WHERE TABLE_SCHEMA = '${schema}'`} \nORDER BY TABLE_NAME, ORDINAL_POSITION;`;\n\n const rep = await appDataSource.query(sql);\n return formatToSqlTable(rep);\n }\n\n if (appDataSource.options.type === \"sap\") {\n const schema = appDataSource.options?.schema ?? \"public\";\n sql = `SELECT\n TABLE_NAME,\n COLUMN_NAME,\n DATA_TYPE_NAME AS data_type,\n CASE WHEN IS_NULLABLE='TRUE' THEN 'YES' ELSE 'NO' END AS is_nullable\n FROM TABLE_COLUMNS\n WHERE SCHEMA_NAME='${schema}'`;\n\n const rep: Array<{ [key: string]: string }> =\n await appDataSource.query(sql);\n\n const repLowerCase: Array<RawResultTableAndColumn> = [];\n rep.forEach((_rep) =>\n repLowerCase.push({\n table_name: _rep.TABLE_NAME,\n column_name: _rep.COLUMN_NAME,\n data_type: _rep.DATA_TYPE,\n is_nullable: _rep.IS_NULLABLE,\n })\n );\n\n return formatToSqlTable(repLowerCase);\n }\n if (appDataSource.options.type === \"oracle\") {\n const schemaName = appDataSource.options.schema;\n const sql = ` \n SELECT\n TABLE_NAME AS \"table_name\",\n COLUMN_NAME AS \"column_name\",\n DATA_TYPE AS \"data_type\",\n NULLABLE AS \"is_nullable\"\n FROM ALL_TAB_COLS\n WHERE\n OWNER = UPPER('${schemaName}')`;\n const rep = await appDataSource.query(sql);\n return formatToSqlTable(rep);\n }\n throw new Error(\"Database type not implemented yet\");\n};\n\nconst formatSqlResponseToSimpleTableString = (rawResult: unknown): string => {\n if (!rawResult || !Array.isArray(rawResult) || rawResult.length === 0) {\n return \"\";\n }\n\n let globalString = \"\";\n for (const oneRow of rawResult) {\n globalString += `${Object.values(oneRow).reduce(\n (completeString, columnValue) => `${completeString} ${columnValue}`,\n \"\"\n )}\\n`;\n }\n\n return globalString;\n};\n\nexport const generateTableInfoFromTables = async (\n tables: Array<SqlTable> | undefined,\n appDataSource: DataSource,\n nbSampleRow: number,\n customDescription?: Record<string, string>\n): Promise<string> => {\n if (!tables) {\n return \"\";\n }\n\n let globalString = \"\";\n for (const currentTable of tables) {\n // Add the custom info of the table\n const tableCustomDescription =\n customDescription &&\n Object.keys(customDescription).includes(currentTable.tableName)\n ? `${customDescription[currentTable.tableName]}\\n`\n : \"\";\n // Add the creation of the table in SQL\n let schema = null;\n if (appDataSource.options.type === \"postgres\") {\n schema = appDataSource.options?.schema ?? \"public\";\n } else if (appDataSource.options.type === \"aurora-postgres\") {\n schema = \"public\";\n } else if (appDataSource.options.type === \"mssql\") {\n schema = appDataSource.options?.schema;\n } else if (appDataSource.options.type === \"sap\") {\n schema =\n appDataSource.options?.schema ??\n appDataSource.options?.username ??\n \"public\";\n } else if (appDataSource.options.type === \"oracle\") {\n schema = appDataSource.options.schema;\n }\n let sqlCreateTableQuery = schema\n ? `CREATE TABLE \"${schema}\".\"${currentTable.tableName}\" (\\n`\n : `CREATE TABLE ${currentTable.tableName} (\\n`;\n for (const [key, currentColumn] of currentTable.columns.entries()) {\n if (key > 0) {\n sqlCreateTableQuery += \", \";\n }\n sqlCreateTableQuery += `${currentColumn.columnName} ${\n currentColumn.dataType\n } ${currentColumn.isNullable ? \"\" : \"NOT NULL\"}`;\n }\n sqlCreateTableQuery += \") \\n\";\n\n let sqlSelectInfoQuery;\n if (appDataSource.options.type === \"mysql\") {\n // We use backticks to quote the table names and thus allow for example spaces in table names\n sqlSelectInfoQuery = `SELECT * FROM \\`${currentTable.tableName}\\` LIMIT ${nbSampleRow};\\n`;\n } else if (appDataSource.options.type === \"postgres\") {\n const schema =\n appDataSource.options.type === \"postgres\"\n ? (appDataSource.options?.schema ?? \"public\")\n : \"public\";\n sqlSelectInfoQuery = `SELECT * FROM \"${schema}\".\"${currentTable.tableName}\" LIMIT ${nbSampleRow};\\n`;\n } else if (appDataSource.options.type === \"mssql\") {\n const schema = appDataSource.options?.schema;\n sqlSelectInfoQuery = schema\n ? `SELECT TOP ${nbSampleRow} * FROM ${schema}.[${currentTable.tableName}];\\n`\n : `SELECT TOP ${nbSampleRow} * FROM [${currentTable.tableName}];\\n`;\n } else if (appDataSource.options.type === \"sap\") {\n const schema =\n appDataSource.options?.schema ??\n appDataSource.options?.username ??\n \"public\";\n sqlSelectInfoQuery = `SELECT * FROM \"${schema}\".\"${currentTable.tableName}\" LIMIT ${nbSampleRow};\\n`;\n } else if (appDataSource.options.type === \"oracle\") {\n sqlSelectInfoQuery = `SELECT * FROM \"${schema}\".\"${currentTable.tableName}\" WHERE ROWNUM <= '${nbSampleRow}'`;\n } else {\n sqlSelectInfoQuery = `SELECT * FROM \"${currentTable.tableName}\" LIMIT ${nbSampleRow};\\n`;\n }\n\n const columnNamesConcatString = `${currentTable.columns.reduce(\n (completeString, column) => `${completeString} ${column.columnName}`,\n \"\"\n )}\\n`;\n\n let sample = \"\";\n try {\n const infoObjectResult = nbSampleRow\n ? await appDataSource.query(sqlSelectInfoQuery)\n : null;\n sample = formatSqlResponseToSimpleTableString(infoObjectResult);\n } catch (error) {\n // If the request fails we catch it and only display a log message\n console.log(error);\n }\n\n globalString = globalString.concat(\n tableCustomDescription +\n sqlCreateTableQuery +\n sqlSelectInfoQuery +\n columnNamesConcatString +\n sample\n );\n }\n\n return globalString;\n};\n\nexport const getPromptTemplateFromDataSource = (\n appDataSource: DataSource\n): PromptTemplate => {\n if (\n appDataSource.options.type === \"postgres\" ||\n appDataSource.options.type === \"aurora-postgres\"\n ) {\n return SQL_POSTGRES_PROMPT;\n }\n\n if (appDataSource.options.type === \"sqlite\") {\n return SQL_SQLITE_PROMPT;\n }\n\n if (appDataSource.options.type === \"mysql\") {\n return SQL_MYSQL_PROMPT;\n }\n\n if (appDataSource.options.type === \"mssql\") {\n return SQL_MSSQL_PROMPT;\n }\n\n if (appDataSource.options.type === \"sap\") {\n return SQL_SAP_HANA_PROMPT;\n }\n\n if (appDataSource.options.type === \"oracle\") {\n return SQL_ORACLE_PROMPT;\n }\n\n return DEFAULT_SQL_DATABASE_PROMPT;\n};\n"],"mappings":";;;AAiDA,MAAa,kCAAkC,CAC7CA,oBACAC,YACAC,mBACS;CACT,MAAMC,iBAAgC,mBAAmB,IACvD,CAACC,UAAoB,MAAM,UAC5B;AACD,KAAI,WAAW,SAAS,GACtB;OAAK,MAAM,aAAa,WACtB,KAAI,CAAC,eAAe,SAAS,UAAU,CACrC,OAAM,IAAI,MACR,GAAG,eAAe,WAAW,EAAE,UAAU,8BAA8B,CAAC;CAG7E;AAEJ;AAED,MAAa,qCAAqC,CAChDJ,oBACAK,kBACS;CACT,gCACE,oBACA,eACA,wCACD;AACF;AAED,MAAa,oCAAoC,CAC/CL,oBACAM,iBACS;CACT,gCACE,oBACA,cACA,uCACD;AACF;AAED,MAAM,mBA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
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "Old abstractions form LangChain.js",
|
|
5
5
|
"author": "LangChain",
|
|
6
6
|
"license": "MIT",
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
"@vitest/coverage-v8": "^3.2.4",
|
|
132
132
|
"@xata.io/client": "^0.28.4",
|
|
133
133
|
"@zilliz/milvus2-sdk-node": "^2.3.5",
|
|
134
|
-
"axios": "^
|
|
134
|
+
"axios": "^1.12.0",
|
|
135
135
|
"cheerio": "1.0.0-rc.12",
|
|
136
136
|
"chromadb": "^1.5.3",
|
|
137
137
|
"cohere-ai": "^7.14.0",
|
|
@@ -170,22 +170,22 @@
|
|
|
170
170
|
"voy-search": "0.6.2",
|
|
171
171
|
"weaviate-client": "^3.8.0",
|
|
172
172
|
"zod-to-json-schema": "^3.24.6",
|
|
173
|
-
"@langchain/anthropic": "1.3.
|
|
173
|
+
"@langchain/anthropic": "1.3.12",
|
|
174
174
|
"@langchain/aws": "1.2.1",
|
|
175
175
|
"@langchain/azure-cosmosdb": "1.1.0",
|
|
176
176
|
"@langchain/azure-dynamic-sessions": "1.0.1",
|
|
177
177
|
"@langchain/baidu-qianfan": "1.0.1",
|
|
178
|
-
"@langchain/cloudflare": "1.0.1",
|
|
179
178
|
"@langchain/cohere": "1.0.1",
|
|
180
|
-
"@langchain/
|
|
181
|
-
"@langchain/
|
|
179
|
+
"@langchain/cloudflare": "1.0.1",
|
|
180
|
+
"@langchain/core": "1.1.17",
|
|
181
|
+
"@langchain/deepseek": "1.0.7",
|
|
182
182
|
"@langchain/eslint": "0.1.1",
|
|
183
183
|
"@langchain/exa": "1.0.1",
|
|
184
|
-
"@langchain/google-cloud-sql-pg": "1.0.
|
|
185
|
-
"@langchain/google-common": "2.1.
|
|
186
|
-
"@langchain/google-genai": "2.1.
|
|
187
|
-
"@langchain/google-vertexai": "2.1.
|
|
188
|
-
"@langchain/google-vertexai-web": "2.1.
|
|
184
|
+
"@langchain/google-cloud-sql-pg": "1.0.18",
|
|
185
|
+
"@langchain/google-common": "2.1.13",
|
|
186
|
+
"@langchain/google-genai": "2.1.13",
|
|
187
|
+
"@langchain/google-vertexai": "2.1.13",
|
|
188
|
+
"@langchain/google-vertexai-web": "2.1.13",
|
|
189
189
|
"@langchain/groq": "1.0.3",
|
|
190
190
|
"@langchain/mistralai": "1.0.3",
|
|
191
191
|
"@langchain/mongodb": "1.1.0",
|
|
@@ -200,7 +200,7 @@
|
|
|
200
200
|
"@langchain/xai": "1.2.2",
|
|
201
201
|
"@langchain/yandex": "1.0.1",
|
|
202
202
|
"@langchain/tsconfig": "0.0.1",
|
|
203
|
-
"langchain": "1.2.
|
|
203
|
+
"langchain": "1.2.14"
|
|
204
204
|
},
|
|
205
205
|
"peerDependencies": {
|
|
206
206
|
"@langchain/core": "^1.0.0",
|