langchain 0.0.69 → 0.0.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/agents/mrkl/prompt.cjs +1 -1
  2. package/dist/agents/mrkl/prompt.d.ts +1 -1
  3. package/dist/agents/mrkl/prompt.js +1 -1
  4. package/dist/callbacks/base.cjs +25 -2
  5. package/dist/callbacks/base.js +2 -2
  6. package/dist/chains/llm_chain.d.ts +7 -7
  7. package/dist/chains/question_answering/load.cjs +14 -40
  8. package/dist/chains/question_answering/load.d.ts +3 -3
  9. package/dist/chains/question_answering/load.js +16 -42
  10. package/dist/chains/sql_db/sql_db_chain.cjs +4 -0
  11. package/dist/chains/sql_db/sql_db_chain.d.ts +3 -1
  12. package/dist/chains/sql_db/sql_db_chain.js +4 -0
  13. package/dist/chains/sql_db/sql_db_prompt.cjs +58 -1
  14. package/dist/chains/sql_db/sql_db_prompt.d.ts +3 -0
  15. package/dist/chains/sql_db/sql_db_prompt.js +57 -0
  16. package/dist/chat_models/openai.cjs +89 -4
  17. package/dist/chat_models/openai.d.ts +18 -53
  18. package/dist/chat_models/openai.js +90 -5
  19. package/dist/document_loaders/fs/directory.d.ts +5 -6
  20. package/dist/document_loaders/fs/pdf.d.ts +1 -1
  21. package/dist/document_loaders/fs/unstructured.cjs +68 -49
  22. package/dist/document_loaders/fs/unstructured.d.ts +16 -11
  23. package/dist/document_loaders/fs/unstructured.js +69 -50
  24. package/dist/document_loaders/web/s3.cjs +2 -1
  25. package/dist/document_loaders/web/s3.js +2 -1
  26. package/dist/embeddings/openai.cjs +86 -6
  27. package/dist/embeddings/openai.d.ts +7 -2
  28. package/dist/embeddings/openai.js +86 -6
  29. package/dist/llms/openai-chat.cjs +97 -6
  30. package/dist/llms/openai-chat.d.ts +22 -58
  31. package/dist/llms/openai-chat.js +97 -6
  32. package/dist/llms/openai.cjs +94 -5
  33. package/dist/llms/openai.d.ts +18 -59
  34. package/dist/llms/openai.js +95 -6
  35. package/dist/memory/base.cjs +1 -1
  36. package/dist/memory/base.js +1 -1
  37. package/dist/memory/index.cjs +3 -1
  38. package/dist/memory/index.d.ts +1 -0
  39. package/dist/memory/index.js +1 -0
  40. package/dist/memory/vector_store.cjs +61 -0
  41. package/dist/memory/vector_store.d.ts +19 -0
  42. package/dist/memory/vector_store.js +57 -0
  43. package/dist/output_parsers/combining.cjs +15 -4
  44. package/dist/output_parsers/combining.d.ts +1 -0
  45. package/dist/output_parsers/combining.js +15 -4
  46. package/dist/output_parsers/structured.cjs +10 -5
  47. package/dist/output_parsers/structured.js +10 -5
  48. package/dist/retrievers/time_weighted.d.ts +1 -1
  49. package/dist/tools/webbrowser.cjs +1 -1
  50. package/dist/tools/webbrowser.js +1 -1
  51. package/dist/util/sql_utils.cjs +15 -1
  52. package/dist/util/sql_utils.d.ts +2 -0
  53. package/dist/util/sql_utils.js +13 -0
  54. package/dist/vectorstores/chroma.cjs +25 -2
  55. package/dist/vectorstores/chroma.js +2 -2
  56. package/dist/vectorstores/milvus.cjs +25 -2
  57. package/dist/vectorstores/milvus.js +2 -2
  58. package/dist/vectorstores/myscale.cjs +26 -3
  59. package/dist/vectorstores/myscale.js +3 -3
  60. package/dist/vectorstores/opensearch.cjs +25 -2
  61. package/dist/vectorstores/opensearch.js +2 -2
  62. package/dist/vectorstores/pinecone.cjs +25 -2
  63. package/dist/vectorstores/pinecone.js +2 -2
  64. package/dist/vectorstores/prisma.cjs +1 -1
  65. package/dist/vectorstores/prisma.js +2 -1
  66. package/dist/vectorstores/supabase.cjs +13 -1
  67. package/dist/vectorstores/supabase.d.ts +6 -1
  68. package/dist/vectorstores/supabase.js +13 -1
  69. package/dist/vectorstores/weaviate.cjs +25 -2
  70. package/dist/vectorstores/weaviate.js +2 -2
  71. package/package.json +5 -5
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SUFFIX = exports.FORMAT_INSTRUCTIONS = exports.PREFIX = void 0;
4
4
  exports.PREFIX = `Answer the following questions as best you can. You have access to the following tools:`;
5
- exports.FORMAT_INSTRUCTIONS = `Use the following format:
5
+ exports.FORMAT_INSTRUCTIONS = `Use the following format in your response:
6
6
 
7
7
  Question: the input question you must answer
8
8
  Thought: you should always think about what to do
@@ -1,3 +1,3 @@
1
1
  export declare const PREFIX = "Answer the following questions as best you can. You have access to the following tools:";
2
- export declare const FORMAT_INSTRUCTIONS = "Use the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question";
2
+ export declare const FORMAT_INSTRUCTIONS = "Use the following format in your response:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [{tool_names}]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question";
3
3
  export declare const SUFFIX = "Begin!\n\nQuestion: {input}\nThought:{agent_scratchpad}";
@@ -1,5 +1,5 @@
1
1
  export const PREFIX = `Answer the following questions as best you can. You have access to the following tools:`;
2
- export const FORMAT_INSTRUCTIONS = `Use the following format:
2
+ export const FORMAT_INSTRUCTIONS = `Use the following format in your response:
3
3
 
4
4
  Question: the input question you must answer
5
5
  Thought: you should always think about what to do
@@ -1,7 +1,30 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.BaseCallbackHandler = void 0;
4
- const uuid_1 = require("uuid");
27
+ const uuid = __importStar(require("uuid"));
5
28
  class BaseCallbackHandlerMethodsClass {
6
29
  }
7
30
  class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass {
@@ -42,7 +65,7 @@ class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass {
42
65
  enumerable: true,
43
66
  configurable: true,
44
67
  writable: true,
45
- value: (0, uuid_1.v4)()
68
+ value: uuid.v4()
46
69
  });
47
70
  Object.assign(this, methods);
48
71
  }
@@ -1,4 +1,4 @@
1
- import { v4 as uuidv4 } from "uuid";
1
+ import * as uuid from "uuid";
2
2
  class BaseCallbackHandlerMethodsClass {
3
3
  }
4
4
  export class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass {
@@ -39,7 +39,7 @@ export class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass {
39
39
  enumerable: true,
40
40
  configurable: true,
41
41
  writable: true,
42
- value: uuidv4()
42
+ value: uuid.v4()
43
43
  });
44
44
  Object.assign(this, methods);
45
45
  }
@@ -6,13 +6,13 @@ import { BaseOutputParser } from "../schema/output_parser.js";
6
6
  import { SerializedLLMChain } from "./serde.js";
7
7
  import { CallbackManager } from "../callbacks/index.js";
8
8
  import { CallbackManagerForChainRun } from "../callbacks/manager.js";
9
- export interface LLMChainInput extends ChainInputs {
9
+ export interface LLMChainInput<T extends string | object = string> extends ChainInputs {
10
10
  /** Prompt object to use */
11
11
  prompt: BasePromptTemplate;
12
12
  /** LLM Wrapper to use */
13
13
  llm: BaseLanguageModel;
14
14
  /** OutputParser to use */
15
- outputParser?: BaseOutputParser;
15
+ outputParser?: BaseOutputParser<T>;
16
16
  /** Key to use for output, defaults to `text` */
17
17
  outputKey?: string;
18
18
  }
@@ -29,14 +29,14 @@ export interface LLMChainInput extends ChainInputs {
29
29
  * const llm = new LLMChain({ llm: new OpenAI(), prompt });
30
30
  * ```
31
31
  */
32
- export declare class LLMChain extends BaseChain implements LLMChainInput {
32
+ export declare class LLMChain<T extends string | object = string> extends BaseChain implements LLMChainInput<T> {
33
33
  prompt: BasePromptTemplate;
34
34
  llm: BaseLanguageModel;
35
35
  outputKey: string;
36
- outputParser?: BaseOutputParser;
36
+ outputParser?: BaseOutputParser<T>;
37
37
  get inputKeys(): string[];
38
38
  get outputKeys(): string[];
39
- constructor(fields: LLMChainInput);
39
+ constructor(fields: LLMChainInput<T>);
40
40
  /** @ignore */
41
41
  _getFinalOutput(generations: Generation[], promptValue: BasePromptValue, runManager?: CallbackManagerForChainRun): Promise<unknown>;
42
42
  /** @ignore */
@@ -53,8 +53,8 @@ export declare class LLMChain extends BaseChain implements LLMChainInput {
53
53
  * llm.predict({ adjective: "funny" })
54
54
  * ```
55
55
  */
56
- predict(values: ChainValues, callbackManager?: CallbackManager): Promise<string>;
56
+ predict(values: ChainValues, callbackManager?: CallbackManager): Promise<T>;
57
57
  _chainType(): "llm_chain";
58
- static deserialize(data: SerializedLLMChain): Promise<LLMChain>;
58
+ static deserialize(data: SerializedLLMChain): Promise<LLMChain<string>>;
59
59
  serialize(): SerializedLLMChain;
60
60
  }
@@ -7,79 +7,53 @@ const stuff_prompts_js_1 = require("./stuff_prompts.cjs");
7
7
  const map_reduce_prompts_js_1 = require("./map_reduce_prompts.cjs");
8
8
  const refine_prompts_js_1 = require("./refine_prompts.cjs");
9
9
  const loadQAChain = (llm, params = { type: "stuff" }) => {
10
- const { type, verbose } = params;
10
+ const { type } = params;
11
11
  if (type === "stuff") {
12
- const { prompt = stuff_prompts_js_1.DEFAULT_QA_PROMPT } = params;
13
- const llmChain = new llm_chain_js_1.LLMChain({ prompt, llm, verbose });
14
- const chain = new combine_docs_chain_js_1.StuffDocumentsChain({ llmChain, verbose });
15
- return chain;
12
+ return loadQAStuffChain(llm, params);
16
13
  }
17
14
  if (type === "map_reduce") {
18
- const { combineMapPrompt = map_reduce_prompts_js_1.DEFAULT_COMBINE_QA_PROMPT, combinePrompt = map_reduce_prompts_js_1.COMBINE_PROMPT, returnIntermediateSteps, } = params;
19
- const llmChain = new llm_chain_js_1.LLMChain({ prompt: combineMapPrompt, llm, verbose });
20
- const combineLLMChain = new llm_chain_js_1.LLMChain({
21
- prompt: combinePrompt,
22
- llm,
23
- verbose,
24
- });
25
- const combineDocumentChain = new combine_docs_chain_js_1.StuffDocumentsChain({
26
- llmChain: combineLLMChain,
27
- documentVariableName: "summaries",
28
- verbose,
29
- });
30
- const chain = new combine_docs_chain_js_1.MapReduceDocumentsChain({
31
- llmChain,
32
- combineDocumentChain,
33
- returnIntermediateSteps,
34
- verbose,
35
- });
36
- return chain;
15
+ return loadQAMapReduceChain(llm, params);
37
16
  }
38
17
  if (type === "refine") {
39
- const { questionPrompt = refine_prompts_js_1.QUESTION_PROMPT_SELECTOR.getPrompt(llm), refinePrompt = refine_prompts_js_1.REFINE_PROMPT_SELECTOR.getPrompt(llm), } = params;
40
- const llmChain = new llm_chain_js_1.LLMChain({ prompt: questionPrompt, llm, verbose });
41
- const refineLLMChain = new llm_chain_js_1.LLMChain({ prompt: refinePrompt, llm, verbose });
42
- const chain = new combine_docs_chain_js_1.RefineDocumentsChain({
43
- llmChain,
44
- refineLLMChain,
45
- verbose,
46
- });
47
- return chain;
18
+ return loadQARefineChain(llm, params);
48
19
  }
49
20
  throw new Error(`Invalid _type: ${type}`);
50
21
  };
51
22
  exports.loadQAChain = loadQAChain;
52
- const loadQAStuffChain = (llm, params = {}) => {
23
+ function loadQAStuffChain(llm, params = {}) {
53
24
  const { prompt = stuff_prompts_js_1.QA_PROMPT_SELECTOR.getPrompt(llm), verbose } = params;
54
25
  const llmChain = new llm_chain_js_1.LLMChain({ prompt, llm, verbose });
55
- const chain = new combine_docs_chain_js_1.StuffDocumentsChain({ llmChain });
26
+ const chain = new combine_docs_chain_js_1.StuffDocumentsChain({ llmChain, verbose });
56
27
  return chain;
57
- };
28
+ }
58
29
  exports.loadQAStuffChain = loadQAStuffChain;
59
- const loadQAMapReduceChain = (llm, params = {}) => {
30
+ function loadQAMapReduceChain(llm, params = {}) {
60
31
  const { combineMapPrompt = map_reduce_prompts_js_1.COMBINE_QA_PROMPT_SELECTOR.getPrompt(llm), combinePrompt = map_reduce_prompts_js_1.COMBINE_PROMPT_SELECTOR.getPrompt(llm), verbose, returnIntermediateSteps, } = params;
61
32
  const llmChain = new llm_chain_js_1.LLMChain({ prompt: combineMapPrompt, llm, verbose });
62
33
  const combineLLMChain = new llm_chain_js_1.LLMChain({ prompt: combinePrompt, llm, verbose });
63
34
  const combineDocumentChain = new combine_docs_chain_js_1.StuffDocumentsChain({
64
35
  llmChain: combineLLMChain,
65
36
  documentVariableName: "summaries",
37
+ verbose,
66
38
  });
67
39
  const chain = new combine_docs_chain_js_1.MapReduceDocumentsChain({
68
40
  llmChain,
69
41
  combineDocumentChain,
70
42
  returnIntermediateSteps,
43
+ verbose,
71
44
  });
72
45
  return chain;
73
- };
46
+ }
74
47
  exports.loadQAMapReduceChain = loadQAMapReduceChain;
75
- const loadQARefineChain = (llm, params = {}) => {
48
+ function loadQARefineChain(llm, params = {}) {
76
49
  const { questionPrompt = refine_prompts_js_1.QUESTION_PROMPT_SELECTOR.getPrompt(llm), refinePrompt = refine_prompts_js_1.REFINE_PROMPT_SELECTOR.getPrompt(llm), verbose, } = params;
77
50
  const llmChain = new llm_chain_js_1.LLMChain({ prompt: questionPrompt, llm, verbose });
78
51
  const refineLLMChain = new llm_chain_js_1.LLMChain({ prompt: refinePrompt, llm, verbose });
79
52
  const chain = new combine_docs_chain_js_1.RefineDocumentsChain({
80
53
  llmChain,
81
54
  refineLLMChain,
55
+ verbose,
82
56
  });
83
57
  return chain;
84
- };
58
+ }
85
59
  exports.loadQARefineChain = loadQARefineChain;
@@ -13,17 +13,17 @@ export interface StuffQAChainParams {
13
13
  prompt?: BasePromptTemplate;
14
14
  verbose?: boolean;
15
15
  }
16
- export declare const loadQAStuffChain: (llm: BaseLanguageModel, params?: StuffQAChainParams) => StuffDocumentsChain;
16
+ export declare function loadQAStuffChain(llm: BaseLanguageModel, params?: StuffQAChainParams): StuffDocumentsChain;
17
17
  export interface MapReduceQAChainParams {
18
18
  returnIntermediateSteps?: MapReduceDocumentsChainInput["returnIntermediateSteps"];
19
19
  combineMapPrompt?: BasePromptTemplate;
20
20
  combinePrompt?: BasePromptTemplate;
21
21
  verbose?: boolean;
22
22
  }
23
- export declare const loadQAMapReduceChain: (llm: BaseLanguageModel, params?: MapReduceQAChainParams) => MapReduceDocumentsChain;
23
+ export declare function loadQAMapReduceChain(llm: BaseLanguageModel, params?: MapReduceQAChainParams): MapReduceDocumentsChain;
24
24
  export interface RefineQAChainParams {
25
25
  questionPrompt?: BasePromptTemplate;
26
26
  refinePrompt?: BasePromptTemplate;
27
27
  verbose?: boolean;
28
28
  }
29
- export declare const loadQARefineChain: (llm: BaseLanguageModel, params?: RefineQAChainParams) => RefineDocumentsChain;
29
+ export declare function loadQARefineChain(llm: BaseLanguageModel, params?: RefineQAChainParams): RefineDocumentsChain;
@@ -1,78 +1,52 @@
1
1
  import { LLMChain } from "../llm_chain.js";
2
2
  import { StuffDocumentsChain, MapReduceDocumentsChain, RefineDocumentsChain, } from "../combine_docs_chain.js";
3
- import { QA_PROMPT_SELECTOR, DEFAULT_QA_PROMPT } from "./stuff_prompts.js";
4
- import { COMBINE_PROMPT, DEFAULT_COMBINE_QA_PROMPT, COMBINE_PROMPT_SELECTOR, COMBINE_QA_PROMPT_SELECTOR, } from "./map_reduce_prompts.js";
3
+ import { QA_PROMPT_SELECTOR } from "./stuff_prompts.js";
4
+ import { COMBINE_PROMPT_SELECTOR, COMBINE_QA_PROMPT_SELECTOR, } from "./map_reduce_prompts.js";
5
5
  import { QUESTION_PROMPT_SELECTOR, REFINE_PROMPT_SELECTOR, } from "./refine_prompts.js";
6
6
  export const loadQAChain = (llm, params = { type: "stuff" }) => {
7
- const { type, verbose } = params;
7
+ const { type } = params;
8
8
  if (type === "stuff") {
9
- const { prompt = DEFAULT_QA_PROMPT } = params;
10
- const llmChain = new LLMChain({ prompt, llm, verbose });
11
- const chain = new StuffDocumentsChain({ llmChain, verbose });
12
- return chain;
9
+ return loadQAStuffChain(llm, params);
13
10
  }
14
11
  if (type === "map_reduce") {
15
- const { combineMapPrompt = DEFAULT_COMBINE_QA_PROMPT, combinePrompt = COMBINE_PROMPT, returnIntermediateSteps, } = params;
16
- const llmChain = new LLMChain({ prompt: combineMapPrompt, llm, verbose });
17
- const combineLLMChain = new LLMChain({
18
- prompt: combinePrompt,
19
- llm,
20
- verbose,
21
- });
22
- const combineDocumentChain = new StuffDocumentsChain({
23
- llmChain: combineLLMChain,
24
- documentVariableName: "summaries",
25
- verbose,
26
- });
27
- const chain = new MapReduceDocumentsChain({
28
- llmChain,
29
- combineDocumentChain,
30
- returnIntermediateSteps,
31
- verbose,
32
- });
33
- return chain;
12
+ return loadQAMapReduceChain(llm, params);
34
13
  }
35
14
  if (type === "refine") {
36
- const { questionPrompt = QUESTION_PROMPT_SELECTOR.getPrompt(llm), refinePrompt = REFINE_PROMPT_SELECTOR.getPrompt(llm), } = params;
37
- const llmChain = new LLMChain({ prompt: questionPrompt, llm, verbose });
38
- const refineLLMChain = new LLMChain({ prompt: refinePrompt, llm, verbose });
39
- const chain = new RefineDocumentsChain({
40
- llmChain,
41
- refineLLMChain,
42
- verbose,
43
- });
44
- return chain;
15
+ return loadQARefineChain(llm, params);
45
16
  }
46
17
  throw new Error(`Invalid _type: ${type}`);
47
18
  };
48
- export const loadQAStuffChain = (llm, params = {}) => {
19
+ export function loadQAStuffChain(llm, params = {}) {
49
20
  const { prompt = QA_PROMPT_SELECTOR.getPrompt(llm), verbose } = params;
50
21
  const llmChain = new LLMChain({ prompt, llm, verbose });
51
- const chain = new StuffDocumentsChain({ llmChain });
22
+ const chain = new StuffDocumentsChain({ llmChain, verbose });
52
23
  return chain;
53
- };
54
- export const loadQAMapReduceChain = (llm, params = {}) => {
24
+ }
25
+ export function loadQAMapReduceChain(llm, params = {}) {
55
26
  const { combineMapPrompt = COMBINE_QA_PROMPT_SELECTOR.getPrompt(llm), combinePrompt = COMBINE_PROMPT_SELECTOR.getPrompt(llm), verbose, returnIntermediateSteps, } = params;
56
27
  const llmChain = new LLMChain({ prompt: combineMapPrompt, llm, verbose });
57
28
  const combineLLMChain = new LLMChain({ prompt: combinePrompt, llm, verbose });
58
29
  const combineDocumentChain = new StuffDocumentsChain({
59
30
  llmChain: combineLLMChain,
60
31
  documentVariableName: "summaries",
32
+ verbose,
61
33
  });
62
34
  const chain = new MapReduceDocumentsChain({
63
35
  llmChain,
64
36
  combineDocumentChain,
65
37
  returnIntermediateSteps,
38
+ verbose,
66
39
  });
67
40
  return chain;
68
- };
69
- export const loadQARefineChain = (llm, params = {}) => {
41
+ }
42
+ export function loadQARefineChain(llm, params = {}) {
70
43
  const { questionPrompt = QUESTION_PROMPT_SELECTOR.getPrompt(llm), refinePrompt = REFINE_PROMPT_SELECTOR.getPrompt(llm), verbose, } = params;
71
44
  const llmChain = new LLMChain({ prompt: questionPrompt, llm, verbose });
72
45
  const refineLLMChain = new LLMChain({ prompt: refinePrompt, llm, verbose });
73
46
  const chain = new RefineDocumentsChain({
74
47
  llmChain,
75
48
  refineLLMChain,
49
+ verbose,
76
50
  });
77
51
  return chain;
78
- };
52
+ }
@@ -6,6 +6,7 @@ const base_js_1 = require("../base.cjs");
6
6
  const llm_chain_js_1 = require("../llm_chain.cjs");
7
7
  const index_js_1 = require("../../base_language/index.cjs");
8
8
  const count_tokens_js_1 = require("../../base_language/count_tokens.cjs");
9
+ const sql_utils_js_1 = require("../../util/sql_utils.cjs");
9
10
  class SqlDatabaseChain extends base_js_1.BaseChain {
10
11
  constructor(fields) {
11
12
  super(fields);
@@ -61,6 +62,9 @@ class SqlDatabaseChain extends base_js_1.BaseChain {
61
62
  this.topK = fields.topK ?? this.topK;
62
63
  this.inputKey = fields.inputKey ?? this.inputKey;
63
64
  this.outputKey = fields.outputKey ?? this.outputKey;
65
+ this.prompt =
66
+ fields.prompt ??
67
+ (0, sql_utils_js_1.getPromptTemplateFromDataSource)(this.database.appDataSource);
64
68
  }
65
69
  /** @ignore */
66
70
  async _call(values, runManager) {
@@ -4,17 +4,19 @@ import { ChainValues } from "../../schema/index.js";
4
4
  import { SerializedSqlDatabaseChain } from "../serde.js";
5
5
  import { BaseLanguageModel } from "../../base_language/index.js";
6
6
  import { CallbackManagerForChainRun } from "../../callbacks/manager.js";
7
+ import { PromptTemplate } from "../../prompts/index.js";
7
8
  export interface SqlDatabaseChainInput extends ChainInputs {
8
9
  llm: BaseLanguageModel;
9
10
  database: SqlDatabase;
10
11
  topK?: number;
11
12
  inputKey?: string;
12
13
  outputKey?: string;
14
+ prompt?: PromptTemplate;
13
15
  }
14
16
  export declare class SqlDatabaseChain extends BaseChain {
15
17
  llm: BaseLanguageModel;
16
18
  database: SqlDatabase;
17
- prompt: import("../../index.js").PromptTemplate;
19
+ prompt: PromptTemplate;
18
20
  topK: number;
19
21
  inputKey: string;
20
22
  outputKey: string;
@@ -3,6 +3,7 @@ import { BaseChain } from "../base.js";
3
3
  import { LLMChain } from "../llm_chain.js";
4
4
  import { BaseLanguageModel } from "../../base_language/index.js";
5
5
  import { calculateMaxTokens, getModelContextSize, } from "../../base_language/count_tokens.js";
6
+ import { getPromptTemplateFromDataSource } from "../../util/sql_utils.js";
6
7
  export class SqlDatabaseChain extends BaseChain {
7
8
  constructor(fields) {
8
9
  super(fields);
@@ -58,6 +59,9 @@ export class SqlDatabaseChain extends BaseChain {
58
59
  this.topK = fields.topK ?? this.topK;
59
60
  this.inputKey = fields.inputKey ?? this.inputKey;
60
61
  this.outputKey = fields.outputKey ?? this.outputKey;
62
+ this.prompt =
63
+ fields.prompt ??
64
+ getPromptTemplateFromDataSource(this.database.appDataSource);
61
65
  }
62
66
  /** @ignore */
63
67
  async _call(values, runManager) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_SQL_DATABASE_PROMPT = void 0;
3
+ exports.SQL_MYSQL_PROMPT = exports.SQL_SQLITE_PROMPT = exports.SQL_POSTGRES_PROMPT = exports.DEFAULT_SQL_DATABASE_PROMPT = void 0;
4
4
  /* eslint-disable spaced-comment */
5
5
  const prompt_js_1 = require("../../prompts/prompt.cjs");
6
6
  exports.DEFAULT_SQL_DATABASE_PROMPT = new prompt_js_1.PromptTemplate({
@@ -24,3 +24,60 @@ Only use the tables listed below.
24
24
  Question: {input}`,
25
25
  inputVariables: ["dialect", "table_info", "input", "top_k"],
26
26
  });
27
+ exports.SQL_POSTGRES_PROMPT = new prompt_js_1.PromptTemplate({
28
+ template: `You are a PostgreSQL expert. Given an input question, first create a syntactically correct PostgreSQL query to run, then look at the results of the query and return the answer to the input question.
29
+ Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the LIMIT clause as per PostgreSQL. You can order the results to return the most informative data in the database.
30
+ Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in double quotes (") to denote them as delimited identifiers.
31
+ Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
32
+
33
+ Use the following format:
34
+
35
+ Question: "Question here"
36
+ SQLQuery: "SQL Query to run"
37
+ SQLResult: "Result of the SQLQuery"
38
+ Answer: "Final answer here"
39
+
40
+ Only use the following tables:
41
+ {table_info}
42
+
43
+ Question: {input}`,
44
+ inputVariables: ["dialect", "table_info", "input", "top_k"],
45
+ });
46
+ exports.SQL_SQLITE_PROMPT = new prompt_js_1.PromptTemplate({
47
+ template: `You are a SQLite expert. Given an input question, first create a syntactically correct SQLite query to run, then look at the results of the query and return the answer to the input question.
48
+ Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the LIMIT clause as per SQLite. You can order the results to return the most informative data in the database.
49
+ Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in double quotes (") to denote them as delimited identifiers.
50
+ Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
51
+
52
+ Use the following format:
53
+
54
+ Question: "Question here"
55
+ SQLQuery: "SQL Query to run"
56
+ SQLResult: "Result of the SQLQuery"
57
+ Answer: "Final answer here"
58
+
59
+ Only use the following tables:
60
+ {table_info}
61
+
62
+ Question: {input}`,
63
+ inputVariables: ["dialect", "table_info", "input", "top_k"],
64
+ });
65
+ exports.SQL_MYSQL_PROMPT = new prompt_js_1.PromptTemplate({
66
+ template: `You are a MySQL expert. Given an input question, first create a syntactically correct MySQL query to run, then look at the results of the query and return the answer to the input question.
67
+ Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the LIMIT clause as per MySQL. You can order the results to return the most informative data in the database.
68
+ Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in backticks (\`) to denote them as delimited identifiers.
69
+ Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
70
+
71
+ Use the following format:
72
+
73
+ Question: "Question here"
74
+ SQLQuery: "SQL Query to run"
75
+ SQLResult: "Result of the SQLQuery"
76
+ Answer: "Final answer here"
77
+
78
+ Only use the following tables:
79
+ {table_info}
80
+
81
+ Question: {input}`,
82
+ inputVariables: ["dialect", "table_info", "input", "top_k"],
83
+ });
@@ -1,2 +1,5 @@
1
1
  import { PromptTemplate } from "../../prompts/prompt.js";
2
2
  export declare const DEFAULT_SQL_DATABASE_PROMPT: PromptTemplate;
3
+ export declare const SQL_POSTGRES_PROMPT: PromptTemplate;
4
+ export declare const SQL_SQLITE_PROMPT: PromptTemplate;
5
+ export declare const SQL_MYSQL_PROMPT: PromptTemplate;
@@ -21,3 +21,60 @@ Only use the tables listed below.
21
21
  Question: {input}`,
22
22
  inputVariables: ["dialect", "table_info", "input", "top_k"],
23
23
  });
24
+ export const SQL_POSTGRES_PROMPT = /*#__PURE__*/ new PromptTemplate({
25
+ template: `You are a PostgreSQL expert. Given an input question, first create a syntactically correct PostgreSQL query to run, then look at the results of the query and return the answer to the input question.
26
+ Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the LIMIT clause as per PostgreSQL. You can order the results to return the most informative data in the database.
27
+ Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in double quotes (") to denote them as delimited identifiers.
28
+ Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
29
+
30
+ Use the following format:
31
+
32
+ Question: "Question here"
33
+ SQLQuery: "SQL Query to run"
34
+ SQLResult: "Result of the SQLQuery"
35
+ Answer: "Final answer here"
36
+
37
+ Only use the following tables:
38
+ {table_info}
39
+
40
+ Question: {input}`,
41
+ inputVariables: ["dialect", "table_info", "input", "top_k"],
42
+ });
43
+ export const SQL_SQLITE_PROMPT = /*#__PURE__*/ new PromptTemplate({
44
+ template: `You are a SQLite expert. Given an input question, first create a syntactically correct SQLite query to run, then look at the results of the query and return the answer to the input question.
45
+ Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the LIMIT clause as per SQLite. You can order the results to return the most informative data in the database.
46
+ Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in double quotes (") to denote them as delimited identifiers.
47
+ Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
48
+
49
+ Use the following format:
50
+
51
+ Question: "Question here"
52
+ SQLQuery: "SQL Query to run"
53
+ SQLResult: "Result of the SQLQuery"
54
+ Answer: "Final answer here"
55
+
56
+ Only use the following tables:
57
+ {table_info}
58
+
59
+ Question: {input}`,
60
+ inputVariables: ["dialect", "table_info", "input", "top_k"],
61
+ });
62
+ export const SQL_MYSQL_PROMPT = /*#__PURE__*/ new PromptTemplate({
63
+ template: `You are a MySQL expert. Given an input question, first create a syntactically correct MySQL query to run, then look at the results of the query and return the answer to the input question.
64
+ Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the LIMIT clause as per MySQL. You can order the results to return the most informative data in the database.
65
+ Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in backticks (\`) to denote them as delimited identifiers.
66
+ Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
67
+
68
+ Use the following format:
69
+
70
+ Question: "Question here"
71
+ SQLQuery: "SQL Query to run"
72
+ SQLResult: "Result of the SQLQuery"
73
+ Answer: "Final answer here"
74
+
75
+ Only use the following tables:
76
+ {table_info}
77
+
78
+ Question: {input}`,
79
+ inputVariables: ["dialect", "table_info", "input", "top_k"],
80
+ });