langchain 0.0.127 → 0.0.128

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 (80) hide show
  1. package/dist/agents/toolkits/conversational_retrieval/tool.cjs +8 -2
  2. package/dist/agents/toolkits/conversational_retrieval/tool.d.ts +9 -2
  3. package/dist/agents/toolkits/conversational_retrieval/tool.js +9 -3
  4. package/dist/chains/query_constructor/ir.d.ts +5 -4
  5. package/dist/chains/query_constructor/prompt.cjs +3 -1
  6. package/dist/chains/query_constructor/prompt.d.ts +2 -2
  7. package/dist/chains/query_constructor/prompt.js +3 -1
  8. package/dist/chains/question_answering/refine_prompts.cjs +2 -2
  9. package/dist/chains/question_answering/refine_prompts.d.ts +1 -1
  10. package/dist/chains/question_answering/refine_prompts.js +2 -2
  11. package/dist/chains/sql_db/index.cjs +2 -1
  12. package/dist/chains/sql_db/index.d.ts +1 -1
  13. package/dist/chains/sql_db/index.js +1 -1
  14. package/dist/chains/sql_db/sql_db_prompt.cjs +21 -1
  15. package/dist/chains/sql_db/sql_db_prompt.d.ts +6 -0
  16. package/dist/chains/sql_db/sql_db_prompt.js +20 -0
  17. package/dist/chat_models/openai.cjs +8 -0
  18. package/dist/chat_models/openai.d.ts +1 -0
  19. package/dist/chat_models/openai.js +8 -0
  20. package/dist/document_loaders/web/github.cjs +104 -32
  21. package/dist/document_loaders/web/github.d.ts +46 -3
  22. package/dist/document_loaders/web/github.js +104 -32
  23. package/dist/document_transformers/mozilla_readability.cjs +30 -0
  24. package/dist/document_transformers/mozilla_readability.d.ts +8 -0
  25. package/dist/document_transformers/mozilla_readability.js +26 -0
  26. package/dist/llms/base.cjs +3 -1
  27. package/dist/llms/base.js +3 -1
  28. package/dist/llms/bedrock.cjs +152 -0
  29. package/dist/llms/bedrock.d.ts +54 -0
  30. package/dist/llms/bedrock.js +148 -0
  31. package/dist/llms/openai-chat.cjs +8 -0
  32. package/dist/llms/openai-chat.d.ts +1 -0
  33. package/dist/llms/openai-chat.js +8 -0
  34. package/dist/llms/openai.cjs +8 -0
  35. package/dist/llms/openai.d.ts +1 -0
  36. package/dist/llms/openai.js +8 -0
  37. package/dist/load/import_constants.cjs +2 -0
  38. package/dist/load/import_constants.js +2 -0
  39. package/dist/retrievers/self_query/base.cjs +31 -0
  40. package/dist/retrievers/self_query/base.d.ts +5 -2
  41. package/dist/retrievers/self_query/base.js +31 -0
  42. package/dist/retrievers/self_query/chroma.d.ts +2 -1
  43. package/dist/retrievers/self_query/functional.cjs +28 -1
  44. package/dist/retrievers/self_query/functional.d.ts +3 -0
  45. package/dist/retrievers/self_query/functional.js +28 -1
  46. package/dist/retrievers/self_query/index.cjs +18 -4
  47. package/dist/retrievers/self_query/index.d.ts +14 -10
  48. package/dist/retrievers/self_query/index.js +18 -4
  49. package/dist/retrievers/self_query/pinecone.d.ts +2 -1
  50. package/dist/retrievers/self_query/supabase.cjs +30 -0
  51. package/dist/retrievers/self_query/supabase.d.ts +3 -5
  52. package/dist/retrievers/self_query/supabase.js +30 -0
  53. package/dist/retrievers/self_query/utils.cjs +21 -0
  54. package/dist/retrievers/self_query/utils.d.ts +2 -0
  55. package/dist/retrievers/self_query/utils.js +16 -0
  56. package/dist/retrievers/self_query/weaviate.cjs +67 -16
  57. package/dist/retrievers/self_query/weaviate.d.ts +6 -3
  58. package/dist/retrievers/self_query/weaviate.js +67 -16
  59. package/dist/types/openai-types.d.ts +2 -0
  60. package/dist/util/event-source-parse.cjs +22 -6
  61. package/dist/util/event-source-parse.js +22 -6
  62. package/dist/util/ollama.cjs +16 -2
  63. package/dist/util/ollama.js +16 -2
  64. package/dist/util/sql_utils.cjs +38 -3
  65. package/dist/util/sql_utils.js +39 -4
  66. package/dist/vectorstores/chroma.cjs +5 -6
  67. package/dist/vectorstores/chroma.js +5 -6
  68. package/dist/vectorstores/faiss.cjs +41 -1
  69. package/dist/vectorstores/faiss.d.ts +6 -0
  70. package/dist/vectorstores/faiss.js +41 -1
  71. package/dist/vectorstores/supabase.cjs +10 -4
  72. package/dist/vectorstores/supabase.d.ts +4 -2
  73. package/dist/vectorstores/supabase.js +10 -4
  74. package/document_transformers/mozilla_readability.cjs +1 -0
  75. package/document_transformers/mozilla_readability.d.ts +1 -0
  76. package/document_transformers/mozilla_readability.js +1 -0
  77. package/llms/bedrock.cjs +1 -0
  78. package/llms/bedrock.d.ts +1 -0
  79. package/llms/bedrock.js +1 -0
  80. package/package.json +46 -3
@@ -1,12 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRetrieverTool = void 0;
4
+ const zod_1 = require("zod");
4
5
  const dynamic_js_1 = require("../../../tools/dynamic.cjs");
5
6
  function createRetrieverTool(retriever, input) {
6
- const func = async (input, runManager) => {
7
+ const func = async ({ input }, runManager) => {
7
8
  const docs = await retriever.getRelevantDocuments(input, runManager?.getChild("retriever"));
8
9
  return docs.map((doc) => doc.pageContent).join("\n");
9
10
  };
10
- return new dynamic_js_1.DynamicTool({ ...input, func });
11
+ const schema = zod_1.z.object({
12
+ input: zod_1.z
13
+ .string()
14
+ .describe("Natural language query used as input to the retriever"),
15
+ });
16
+ return new dynamic_js_1.DynamicStructuredTool({ ...input, func, schema });
11
17
  }
12
18
  exports.createRetrieverTool = createRetrieverTool;
@@ -1,3 +1,10 @@
1
+ import { z } from "zod";
1
2
  import { BaseRetriever } from "../../../schema/retriever.js";
2
- import { DynamicTool, DynamicToolInput } from "../../../tools/dynamic.js";
3
- export declare function createRetrieverTool(retriever: BaseRetriever, input: Omit<DynamicToolInput, "func">): DynamicTool;
3
+ import { DynamicStructuredTool, DynamicStructuredToolInput } from "../../../tools/dynamic.js";
4
+ export declare function createRetrieverTool(retriever: BaseRetriever, input: Omit<DynamicStructuredToolInput, "func" | "schema">): DynamicStructuredTool<z.ZodObject<{
5
+ input: z.ZodString;
6
+ }, "strip", z.ZodTypeAny, {
7
+ input: string;
8
+ }, {
9
+ input: string;
10
+ }>>;
@@ -1,8 +1,14 @@
1
- import { DynamicTool } from "../../../tools/dynamic.js";
1
+ import { z } from "zod";
2
+ import { DynamicStructuredTool, } from "../../../tools/dynamic.js";
2
3
  export function createRetrieverTool(retriever, input) {
3
- const func = async (input, runManager) => {
4
+ const func = async ({ input }, runManager) => {
4
5
  const docs = await retriever.getRelevantDocuments(input, runManager?.getChild("retriever"));
5
6
  return docs.map((doc) => doc.pageContent).join("\n");
6
7
  };
7
- return new DynamicTool({ ...input, func });
8
+ const schema = z.object({
9
+ input: z
10
+ .string()
11
+ .describe("Natural language query used as input to the retriever"),
12
+ });
13
+ return new DynamicStructuredTool({ ...input, func, schema });
8
14
  }
@@ -1,3 +1,4 @@
1
+ import { VectorStore } from "../../vectorstores/base.js";
1
2
  export type AND = "and";
2
3
  export type OR = "or";
3
4
  export type NOT = "not";
@@ -15,7 +16,7 @@ export declare const Operators: {
15
16
  export declare const Comparators: {
16
17
  [key: string]: Comparator;
17
18
  };
18
- export type VisitorResult = VisitorOperationResult | VisitorComparisonResult | VisitorStructuredQueryResult;
19
+ export type VisitorResult = VisitorOperationResult | VisitorComparisonResult;
19
20
  export type VisitorOperationResult = {
20
21
  [operator: string]: VisitorResult[];
21
22
  };
@@ -25,13 +26,13 @@ export type VisitorComparisonResult = {
25
26
  };
26
27
  };
27
28
  export type VisitorStructuredQueryResult = {
28
- filter?: VisitorStructuredQueryResult | VisitorComparisonResult | VisitorOperationResult;
29
+ filter?: VisitorComparisonResult | VisitorOperationResult;
29
30
  };
30
- export declare abstract class Visitor {
31
+ export declare abstract class Visitor<T extends VectorStore = VectorStore> {
31
32
  VisitOperationOutput: object;
32
33
  VisitComparisonOutput: object;
33
34
  VisitStructuredQueryOutput: {
34
- filter?: object;
35
+ filter?: T["FilterType"];
35
36
  };
36
37
  abstract allowedOperators: Operator[];
37
38
  abstract allowedComparators: Comparator[];
@@ -100,6 +100,8 @@ statements): one or more statements to apply the operation to
100
100
  Make sure that you only use the comparators and logical operators listed above and \
101
101
  no others.
102
102
  Make sure that filters only refer to attributes that exist in the data source.
103
+ Make sure that filters only use the attributed names with its function names if there are functions applied on them.
104
+ Make sure that filters only use format \`YYYY-MM-DD\` when handling timestamp data typed values.
103
105
  Make sure that filters take into account the descriptions of attributes and only make \
104
106
  comparisons that are feasible given the type of data being stored.
105
107
  Make sure that filters are only used as needed. If there are no filters that should be \
@@ -115,7 +117,7 @@ exports.DEFAULT_SUFFIX = `\
115
117
  Data Source:
116
118
  \`\`\`json
117
119
  {{{{
118
- "content": {content},
120
+ "content": "{content}",
119
121
  "attributes": {attributes}
120
122
  }}}}
121
123
  \`\`\`
@@ -15,6 +15,6 @@ export declare const EXAMPLE_PROMPT: PromptTemplate<{
15
15
  user_query: any;
16
16
  structured_request: any;
17
17
  }, any>;
18
- export declare const DEFAULT_SCHEMA = "<< Structured Request Schema >>\nWhen responding use a markdown code snippet with a JSON object formatted in the following schema:\n\n```json\n{{{{\n \"query\": string \\ text string to compare to document contents\n \"filter\": string \\ logical condition statement for filtering documents\n}}}}\n```\n\nThe query string should contain only text that is expected to match the contents of documents. Any conditions in the filter should not be mentioned in the query as well.\n\nA logical condition statement is composed of one or more comparison and logical operation statements.\n\nA comparison statement takes the form: `comp(attr, val)`:\n- `comp` ({allowed_comparators}): comparator\n- `attr` (string): name of attribute to apply the comparison to\n- `val` (string): is the comparison value\n\nA logical operation statement takes the form `op(statement1, statement2, ...)`:\n- `op` ({allowed_operators}): logical operator\n- `statement1`, `statement2`, ... (comparison statements or logical operation statements): one or more statements to apply the operation to\n\nMake sure that you only use the comparators and logical operators listed above and no others.\nMake sure that filters only refer to attributes that exist in the data source.\nMake sure that filters take into account the descriptions of attributes and only make comparisons that are feasible given the type of data being stored.\nMake sure that filters are only used as needed. If there are no filters that should be applied return \"NO_FILTER\" for the filter value.";
18
+ export declare const DEFAULT_SCHEMA = "<< Structured Request Schema >>\nWhen responding use a markdown code snippet with a JSON object formatted in the following schema:\n\n```json\n{{{{\n \"query\": string \\ text string to compare to document contents\n \"filter\": string \\ logical condition statement for filtering documents\n}}}}\n```\n\nThe query string should contain only text that is expected to match the contents of documents. Any conditions in the filter should not be mentioned in the query as well.\n\nA logical condition statement is composed of one or more comparison and logical operation statements.\n\nA comparison statement takes the form: `comp(attr, val)`:\n- `comp` ({allowed_comparators}): comparator\n- `attr` (string): name of attribute to apply the comparison to\n- `val` (string): is the comparison value\n\nA logical operation statement takes the form `op(statement1, statement2, ...)`:\n- `op` ({allowed_operators}): logical operator\n- `statement1`, `statement2`, ... (comparison statements or logical operation statements): one or more statements to apply the operation to\n\nMake sure that you only use the comparators and logical operators listed above and no others.\nMake sure that filters only refer to attributes that exist in the data source.\nMake sure that filters only use the attributed names with its function names if there are functions applied on them.\nMake sure that filters only use format `YYYY-MM-DD` when handling timestamp data typed values.\nMake sure that filters take into account the descriptions of attributes and only make comparisons that are feasible given the type of data being stored.\nMake sure that filters are only used as needed. If there are no filters that should be applied return \"NO_FILTER\" for the filter value.";
19
19
  export declare const DEFAULT_PREFIX = "Your goal is to structure the user's query to match the request schema provided below.\n\n{schema}";
20
- export declare const DEFAULT_SUFFIX = "<< Example {i}. >>\nData Source:\n```json\n{{{{\n \"content\": {content},\n \"attributes\": {attributes}\n}}}}\n```\n\nUser Query:\n{{query}}\n\nStructured Request:\n";
20
+ export declare const DEFAULT_SUFFIX = "<< Example {i}. >>\nData Source:\n```json\n{{{{\n \"content\": \"{content}\",\n \"attributes\": {attributes}\n}}}}\n```\n\nUser Query:\n{{query}}\n\nStructured Request:\n";
@@ -97,6 +97,8 @@ statements): one or more statements to apply the operation to
97
97
  Make sure that you only use the comparators and logical operators listed above and \
98
98
  no others.
99
99
  Make sure that filters only refer to attributes that exist in the data source.
100
+ Make sure that filters only use the attributed names with its function names if there are functions applied on them.
101
+ Make sure that filters only use format \`YYYY-MM-DD\` when handling timestamp data typed values.
100
102
  Make sure that filters take into account the descriptions of attributes and only make \
101
103
  comparisons that are feasible given the type of data being stored.
102
104
  Make sure that filters are only used as needed. If there are no filters that should be \
@@ -112,7 +114,7 @@ export const DEFAULT_SUFFIX = `\
112
114
  Data Source:
113
115
  \`\`\`json
114
116
  {{{{
115
- "content": {content},
117
+ "content": "{content}",
116
118
  "attributes": {attributes}
117
119
  }}}}
118
120
  \`\`\`
@@ -41,7 +41,7 @@ exports.DEFAULT_TEXT_QA_PROMPT_TMPL = `Context information is below.
41
41
  ---------------------
42
42
  {context}
43
43
  ---------------------
44
- Given the context information and not prior knowledge, answer the question: {question}`;
44
+ Given the context information and no prior knowledge, answer the question: {question}`;
45
45
  exports.DEFAULT_TEXT_QA_PROMPT = new index_js_1.PromptTemplate({
46
46
  inputVariables: ["context", "question"],
47
47
  template: exports.DEFAULT_TEXT_QA_PROMPT_TMPL,
@@ -50,7 +50,7 @@ const chat_qa_prompt_template = `Context information is below.
50
50
  ---------------------
51
51
  {context}
52
52
  ---------------------
53
- Given the context information and not prior knowledge, answer any questions`;
53
+ Given the context information and no prior knowledge, answer any questions`;
54
54
  const chat_messages = [
55
55
  /*#__PURE__*/ index_js_1.SystemMessagePromptTemplate.fromTemplate(chat_qa_prompt_template),
56
56
  /*#__PURE__*/ index_js_1.HumanMessagePromptTemplate.fromTemplate("{question}"),
@@ -8,7 +8,7 @@ export declare const DEFAULT_REFINE_PROMPT: PromptTemplate<{
8
8
  }, any>;
9
9
  export declare const CHAT_REFINE_PROMPT: ChatPromptTemplate<any, any>;
10
10
  export declare const REFINE_PROMPT_SELECTOR: ConditionalPromptSelector;
11
- export declare const DEFAULT_TEXT_QA_PROMPT_TMPL = "Context information is below. \n---------------------\n{context}\n---------------------\nGiven the context information and not prior knowledge, answer the question: {question}";
11
+ export declare const DEFAULT_TEXT_QA_PROMPT_TMPL = "Context information is below. \n---------------------\n{context}\n---------------------\nGiven the context information and no prior knowledge, answer the question: {question}";
12
12
  export declare const DEFAULT_TEXT_QA_PROMPT: PromptTemplate<{
13
13
  context: any;
14
14
  question: any;
@@ -38,7 +38,7 @@ export const DEFAULT_TEXT_QA_PROMPT_TMPL = `Context information is below.
38
38
  ---------------------
39
39
  {context}
40
40
  ---------------------
41
- Given the context information and not prior knowledge, answer the question: {question}`;
41
+ Given the context information and no prior knowledge, answer the question: {question}`;
42
42
  export const DEFAULT_TEXT_QA_PROMPT = /*#__PURE__*/ new PromptTemplate({
43
43
  inputVariables: ["context", "question"],
44
44
  template: DEFAULT_TEXT_QA_PROMPT_TMPL,
@@ -47,7 +47,7 @@ const chat_qa_prompt_template = `Context information is below.
47
47
  ---------------------
48
48
  {context}
49
49
  ---------------------
50
- Given the context information and not prior knowledge, answer any questions`;
50
+ Given the context information and no prior knowledge, answer any questions`;
51
51
  const chat_messages = [
52
52
  /*#__PURE__*/ SystemMessagePromptTemplate.fromTemplate(chat_qa_prompt_template),
53
53
  /*#__PURE__*/ HumanMessagePromptTemplate.fromTemplate("{question}"),
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SQL_MYSQL_PROMPT = exports.SQL_MSSQL_PROMPT = exports.SQL_SQLITE_PROMPT = exports.SQL_POSTGRES_PROMPT = exports.DEFAULT_SQL_DATABASE_PROMPT = exports.SqlDatabaseChain = void 0;
3
+ exports.SQL_SAP_HANA_PROMPT = exports.SQL_MYSQL_PROMPT = exports.SQL_MSSQL_PROMPT = exports.SQL_SQLITE_PROMPT = exports.SQL_POSTGRES_PROMPT = exports.DEFAULT_SQL_DATABASE_PROMPT = exports.SqlDatabaseChain = void 0;
4
4
  var sql_db_chain_js_1 = require("./sql_db_chain.cjs");
5
5
  Object.defineProperty(exports, "SqlDatabaseChain", { enumerable: true, get: function () { return sql_db_chain_js_1.SqlDatabaseChain; } });
6
6
  var sql_db_prompt_js_1 = require("./sql_db_prompt.cjs");
@@ -9,3 +9,4 @@ Object.defineProperty(exports, "SQL_POSTGRES_PROMPT", { enumerable: true, get: f
9
9
  Object.defineProperty(exports, "SQL_SQLITE_PROMPT", { enumerable: true, get: function () { return sql_db_prompt_js_1.SQL_SQLITE_PROMPT; } });
10
10
  Object.defineProperty(exports, "SQL_MSSQL_PROMPT", { enumerable: true, get: function () { return sql_db_prompt_js_1.SQL_MSSQL_PROMPT; } });
11
11
  Object.defineProperty(exports, "SQL_MYSQL_PROMPT", { enumerable: true, get: function () { return sql_db_prompt_js_1.SQL_MYSQL_PROMPT; } });
12
+ Object.defineProperty(exports, "SQL_SAP_HANA_PROMPT", { enumerable: true, get: function () { return sql_db_prompt_js_1.SQL_SAP_HANA_PROMPT; } });
@@ -1,2 +1,2 @@
1
1
  export { SqlDatabaseChain, SqlDatabaseChainInput } from "./sql_db_chain.js";
2
- export { DEFAULT_SQL_DATABASE_PROMPT, SQL_POSTGRES_PROMPT, SQL_SQLITE_PROMPT, SQL_MSSQL_PROMPT, SQL_MYSQL_PROMPT, } from "./sql_db_prompt.js";
2
+ export { DEFAULT_SQL_DATABASE_PROMPT, SQL_POSTGRES_PROMPT, SQL_SQLITE_PROMPT, SQL_MSSQL_PROMPT, SQL_MYSQL_PROMPT, SQL_SAP_HANA_PROMPT, } from "./sql_db_prompt.js";
@@ -1,2 +1,2 @@
1
1
  export { SqlDatabaseChain } from "./sql_db_chain.js";
2
- export { DEFAULT_SQL_DATABASE_PROMPT, SQL_POSTGRES_PROMPT, SQL_SQLITE_PROMPT, SQL_MSSQL_PROMPT, SQL_MYSQL_PROMPT, } from "./sql_db_prompt.js";
2
+ export { DEFAULT_SQL_DATABASE_PROMPT, SQL_POSTGRES_PROMPT, SQL_SQLITE_PROMPT, SQL_MSSQL_PROMPT, SQL_MYSQL_PROMPT, SQL_SAP_HANA_PROMPT, } from "./sql_db_prompt.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SQL_MSSQL_PROMPT = exports.SQL_MYSQL_PROMPT = exports.SQL_SQLITE_PROMPT = exports.SQL_POSTGRES_PROMPT = exports.DEFAULT_SQL_DATABASE_PROMPT = void 0;
3
+ exports.SQL_SAP_HANA_PROMPT = exports.SQL_MSSQL_PROMPT = 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({
@@ -100,3 +100,23 @@ Only use the following tables:
100
100
  Question: {input}`,
101
101
  inputVariables: ["dialect", "table_info", "input", "top_k"],
102
102
  });
103
+ exports.SQL_SAP_HANA_PROMPT = new prompt_js_1.PromptTemplate({
104
+ template: `You are a SAP HANA expert. Given an input question, first create a syntactically correct SAP HANA query to run, then look at the results of the query and return the answer to the input question.
105
+ 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 SAP HANA. You can order the results to return the most informative data in the database.
106
+ 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.
107
+ 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.
108
+ Always use a schema name when executing a query.
109
+
110
+ Use the following format:
111
+
112
+ Question: "Question here"
113
+ SQLQuery: "SQL Query to run"
114
+ SQLResult: "Result of the SQLQuery"
115
+ Answer: "Final answer here"
116
+
117
+ Only use the following tables:
118
+ {table_info}
119
+
120
+ Question: {input}`,
121
+ inputVariables: ["dialect", "table_info", "input", "top_k"],
122
+ });
@@ -29,3 +29,9 @@ export declare const SQL_MSSQL_PROMPT: PromptTemplate<{
29
29
  table_info: any;
30
30
  top_k: any;
31
31
  }, any>;
32
+ export declare const SQL_SAP_HANA_PROMPT: PromptTemplate<{
33
+ input: any;
34
+ dialect: any;
35
+ table_info: any;
36
+ top_k: any;
37
+ }, any>;
@@ -97,3 +97,23 @@ Only use the following tables:
97
97
  Question: {input}`,
98
98
  inputVariables: ["dialect", "table_info", "input", "top_k"],
99
99
  });
100
+ export const SQL_SAP_HANA_PROMPT = /*#__PURE__*/ new PromptTemplate({
101
+ template: `You are a SAP HANA expert. Given an input question, first create a syntactically correct SAP HANA query to run, then look at the results of the query and return the answer to the input question.
102
+ 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 SAP HANA. You can order the results to return the most informative data in the database.
103
+ 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.
104
+ 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.
105
+ Always use a schema name when executing a query.
106
+
107
+ Use the following format:
108
+
109
+ Question: "Question here"
110
+ SQLQuery: "SQL Query to run"
111
+ SQLResult: "Result of the SQLQuery"
112
+ Answer: "Final answer here"
113
+
114
+ Only use the following tables:
115
+ {table_info}
116
+
117
+ Question: {input}`,
118
+ inputVariables: ["dialect", "table_info", "input", "top_k"],
119
+ });
@@ -201,6 +201,12 @@ class ChatOpenAI extends base_js_1.BaseChatModel {
201
201
  writable: true,
202
202
  value: void 0
203
203
  });
204
+ Object.defineProperty(this, "user", {
205
+ enumerable: true,
206
+ configurable: true,
207
+ writable: true,
208
+ value: void 0
209
+ });
204
210
  Object.defineProperty(this, "timeout", {
205
211
  enumerable: true,
206
212
  configurable: true,
@@ -298,6 +304,7 @@ class ChatOpenAI extends base_js_1.BaseChatModel {
298
304
  this.n = fields?.n ?? this.n;
299
305
  this.logitBias = fields?.logitBias;
300
306
  this.stop = fields?.stop;
307
+ this.user = fields?.user;
301
308
  this.streaming = fields?.streaming ?? false;
302
309
  if (this.azureOpenAIApiKey) {
303
310
  if (!this.azureOpenAIApiInstanceName && !this.azureOpenAIBasePath) {
@@ -330,6 +337,7 @@ class ChatOpenAI extends base_js_1.BaseChatModel {
330
337
  n: this.n,
331
338
  logit_bias: this.logitBias,
332
339
  stop: options?.stop ?? this.stop,
340
+ user: this.user,
333
341
  stream: this.streaming,
334
342
  functions: options?.functions ??
335
343
  (options?.tools
@@ -55,6 +55,7 @@ export declare class ChatOpenAI extends BaseChatModel<ChatOpenAICallOptions> imp
55
55
  modelName: string;
56
56
  modelKwargs?: OpenAIChatInput["modelKwargs"];
57
57
  stop?: string[];
58
+ user?: string;
58
59
  timeout?: number;
59
60
  streaming: boolean;
60
61
  maxTokens?: number;
@@ -195,6 +195,12 @@ export class ChatOpenAI extends BaseChatModel {
195
195
  writable: true,
196
196
  value: void 0
197
197
  });
198
+ Object.defineProperty(this, "user", {
199
+ enumerable: true,
200
+ configurable: true,
201
+ writable: true,
202
+ value: void 0
203
+ });
198
204
  Object.defineProperty(this, "timeout", {
199
205
  enumerable: true,
200
206
  configurable: true,
@@ -292,6 +298,7 @@ export class ChatOpenAI extends BaseChatModel {
292
298
  this.n = fields?.n ?? this.n;
293
299
  this.logitBias = fields?.logitBias;
294
300
  this.stop = fields?.stop;
301
+ this.user = fields?.user;
295
302
  this.streaming = fields?.streaming ?? false;
296
303
  if (this.azureOpenAIApiKey) {
297
304
  if (!this.azureOpenAIApiInstanceName && !this.azureOpenAIBasePath) {
@@ -324,6 +331,7 @@ export class ChatOpenAI extends BaseChatModel {
324
331
  n: this.n,
325
332
  logit_bias: this.logitBias,
326
333
  stop: options?.stop ?? this.stop,
334
+ user: this.user,
327
335
  stream: this.streaming,
328
336
  functions: options?.functions ??
329
337
  (options?.tools
@@ -11,12 +11,13 @@ const base_js_1 = require("../base.cjs");
11
11
  const directory_js_1 = require("../fs/directory.cjs");
12
12
  const extname_js_1 = require("../../util/extname.cjs");
13
13
  const env_js_1 = require("../../util/env.cjs");
14
+ const async_caller_js_1 = require("../../util/async_caller.cjs");
14
15
  const extensions = new Set(binary_extensions_1.default);
15
16
  function isBinaryPath(name) {
16
17
  return extensions.has((0, extname_js_1.extname)(name).slice(1).toLowerCase());
17
18
  }
18
19
  class GithubRepoLoader extends base_js_1.BaseDocumentLoader {
19
- constructor(githubUrl, { accessToken = (0, env_js_1.getEnvironmentVariable)("GITHUB_ACCESS_TOKEN"), branch = "main", recursive = true, unknown = directory_js_1.UnknownHandling.Warn, ignoreFiles = [], ignorePaths, } = {}) {
20
+ constructor(githubUrl, { accessToken = (0, env_js_1.getEnvironmentVariable)("GITHUB_ACCESS_TOKEN"), branch = "main", recursive = true, unknown = directory_js_1.UnknownHandling.Warn, ignoreFiles = [], ignorePaths, verbose = false, maxConcurrency = 2, maxRetries = 2, ...rest } = {}) {
20
21
  super();
21
22
  Object.defineProperty(this, "owner", {
22
23
  enumerable: true,
@@ -78,6 +79,18 @@ class GithubRepoLoader extends base_js_1.BaseDocumentLoader {
78
79
  writable: true,
79
80
  value: void 0
80
81
  });
82
+ Object.defineProperty(this, "verbose", {
83
+ enumerable: true,
84
+ configurable: true,
85
+ writable: true,
86
+ value: void 0
87
+ });
88
+ Object.defineProperty(this, "caller", {
89
+ enumerable: true,
90
+ configurable: true,
91
+ writable: true,
92
+ value: void 0
93
+ });
81
94
  const { owner, repo, path } = this.extractOwnerAndRepoAndPath(githubUrl);
82
95
  this.owner = owner;
83
96
  this.repo = repo;
@@ -87,6 +100,12 @@ class GithubRepoLoader extends base_js_1.BaseDocumentLoader {
87
100
  this.unknown = unknown;
88
101
  this.accessToken = accessToken;
89
102
  this.ignoreFiles = ignoreFiles;
103
+ this.verbose = verbose;
104
+ this.caller = new async_caller_js_1.AsyncCaller({
105
+ maxConcurrency,
106
+ maxRetries,
107
+ ...rest,
108
+ });
90
109
  if (ignorePaths) {
91
110
  this.ignore = ignore_1.default.default().add(ignorePaths);
92
111
  }
@@ -104,11 +123,12 @@ class GithubRepoLoader extends base_js_1.BaseDocumentLoader {
104
123
  return { owner: match[1], repo: match[2], path: match[4] || "" };
105
124
  }
106
125
  async load() {
107
- const documents = [];
108
- await this.processDirectory(this.initialPath, documents);
109
- return documents;
126
+ return (await this.processRepo()).map((fileResponse) => new document_js_1.Document({
127
+ pageContent: fileResponse.contents,
128
+ metadata: fileResponse.metadata,
129
+ }));
110
130
  }
111
- async shouldIgnore(path, fileType) {
131
+ shouldIgnore(path, fileType) {
112
132
  if (fileType !== "dir" && isBinaryPath(path)) {
113
133
  return true;
114
134
  }
@@ -128,46 +148,98 @@ class GithubRepoLoader extends base_js_1.BaseDocumentLoader {
128
148
  }
129
149
  }));
130
150
  }
131
- async processDirectory(path, documents) {
132
- try {
133
- const files = await this.fetchRepoFiles(path);
134
- for (const file of files) {
135
- if (!(await this.shouldIgnore(file.path, file.type))) {
136
- if (file.type !== "dir") {
137
- try {
138
- const fileContent = await this.fetchFileContent(file);
139
- const metadata = { source: file.path };
140
- documents.push(new document_js_1.Document({ pageContent: fileContent, metadata }));
141
- }
142
- catch (e) {
143
- this.handleError(`Failed to fetch file content: ${file.path}, ${e}`);
144
- }
151
+ /**
152
+ * Takes the file info and wrap it in a promise that will resolve to the file content and metadata
153
+ * @param file
154
+ * @returns
155
+ */
156
+ async fetchFileContentWrapper(file) {
157
+ const fileContent = await this.fetchFileContent(file).catch((error) => {
158
+ this.handleError(`Failed wrap file content: ${file}, ${error}`);
159
+ });
160
+ return {
161
+ contents: fileContent || "",
162
+ metadata: { source: file.path },
163
+ };
164
+ }
165
+ /**
166
+ * Maps a list of files / directories to a list of promises that will fetch the file / directory contents
167
+ */
168
+ async getCurrentDirectoryFilePromises(files) {
169
+ const currentDirectoryFilePromises = [];
170
+ // Directories have nested files / directories, which is why this is a list of promises of promises
171
+ const currentDirectoryDirectoryPromises = [];
172
+ for (const file of files) {
173
+ if (!this.shouldIgnore(file.path, file.type)) {
174
+ if (file.type !== "dir") {
175
+ try {
176
+ currentDirectoryFilePromises.push(this.fetchFileContentWrapper(file));
145
177
  }
146
- else if (this.recursive) {
147
- await this.processDirectory(file.path, documents);
178
+ catch (e) {
179
+ this.handleError(`Failed to fetch file content: ${file.path}, ${e}`);
148
180
  }
149
181
  }
182
+ else if (this.recursive) {
183
+ currentDirectoryDirectoryPromises.push(this.processDirectory(file.path));
184
+ }
150
185
  }
151
186
  }
187
+ const curDirDirectories = await Promise.all(currentDirectoryDirectoryPromises);
188
+ return [...currentDirectoryFilePromises, ...curDirDirectories.flat()];
189
+ }
190
+ /**
191
+ * Begins the process of fetching the contents of the repository
192
+ */
193
+ async processRepo() {
194
+ try {
195
+ // Get the list of file / directory names in the root directory
196
+ const files = await this.fetchRepoFiles(this.initialPath);
197
+ // Map the file / directory paths to promises that will fetch the file / directory contents
198
+ const currentDirectoryFilePromises = await this.getCurrentDirectoryFilePromises(files);
199
+ return Promise.all(currentDirectoryFilePromises);
200
+ }
201
+ catch (error) {
202
+ this.handleError(`Failed to process directory: ${this.initialPath}, ${error}`);
203
+ return Promise.reject(error);
204
+ }
205
+ }
206
+ async processDirectory(path) {
207
+ try {
208
+ const files = await this.fetchRepoFiles(path);
209
+ return this.getCurrentDirectoryFilePromises(files);
210
+ }
152
211
  catch (error) {
153
212
  this.handleError(`Failed to process directory: ${path}, ${error}`);
213
+ return Promise.reject(error);
154
214
  }
155
215
  }
156
216
  async fetchRepoFiles(path) {
157
217
  const url = `https://api.github.com/repos/${this.owner}/${this.repo}/contents/${path}?ref=${this.branch}`;
158
- const response = await fetch(url, { headers: this.headers });
159
- const data = await response.json();
160
- if (!response.ok) {
161
- throw new Error(`Unable to fetch repository files: ${response.status} ${JSON.stringify(data)}`);
162
- }
163
- if (!Array.isArray(data)) {
164
- throw new Error("Unable to fetch repository files.");
165
- }
166
- return data;
218
+ return this.caller.call(async () => {
219
+ if (this.verbose) {
220
+ console.log("Fetching", url);
221
+ }
222
+ const response = await fetch(url, { headers: this.headers });
223
+ const data = await response.json();
224
+ if (!response.ok) {
225
+ throw new Error(`Unable to fetch repository files: ${response.status} ${JSON.stringify(data)}`);
226
+ }
227
+ if (!Array.isArray(data)) {
228
+ throw new Error("Unable to fetch repository files.");
229
+ }
230
+ return data;
231
+ });
167
232
  }
168
233
  async fetchFileContent(file) {
169
- const response = await fetch(file.download_url, { headers: this.headers });
170
- return response.text();
234
+ return this.caller.call(async () => {
235
+ if (this.verbose) {
236
+ console.log("Fetching", file.download_url);
237
+ }
238
+ const response = await fetch(file.download_url, {
239
+ headers: this.headers,
240
+ });
241
+ return response.text();
242
+ });
171
243
  }
172
244
  handleError(message) {
173
245
  switch (this.unknown) {
@@ -2,13 +2,40 @@ import { Ignore } from "ignore";
2
2
  import { Document } from "../../document.js";
3
3
  import { BaseDocumentLoader } from "../base.js";
4
4
  import { UnknownHandling } from "../fs/directory.js";
5
- export interface GithubRepoLoaderParams {
5
+ import { AsyncCaller, AsyncCallerParams } from "../../util/async_caller.js";
6
+ export interface GithubFile {
7
+ name: string;
8
+ path: string;
9
+ sha: string;
10
+ size: number;
11
+ url: string;
12
+ html_url: string;
13
+ git_url: string;
14
+ download_url: string;
15
+ type: string;
16
+ _links: {
17
+ self: string;
18
+ git: string;
19
+ html: string;
20
+ };
21
+ }
22
+ export interface GithubRepoLoaderParams extends AsyncCallerParams {
6
23
  branch?: string;
7
24
  recursive?: boolean;
8
25
  unknown?: UnknownHandling;
9
26
  accessToken?: string;
10
27
  ignoreFiles?: (string | RegExp)[];
11
28
  ignorePaths?: string[];
29
+ verbose?: boolean;
30
+ /**
31
+ * The maximum number of concurrent calls that can be made. Defaults to 2.
32
+ */
33
+ maxConcurrency?: number;
34
+ /**
35
+ * The maximum number of retries that can be made for a single call,
36
+ * with an exponential backoff between each attempt. Defaults to 2.
37
+ */
38
+ maxRetries?: number;
12
39
  }
13
40
  export declare class GithubRepoLoader extends BaseDocumentLoader implements GithubRepoLoaderParams {
14
41
  private readonly owner;
@@ -21,10 +48,26 @@ export declare class GithubRepoLoader extends BaseDocumentLoader implements Gith
21
48
  accessToken?: string;
22
49
  ignoreFiles: (string | RegExp)[];
23
50
  ignore?: Ignore;
24
- constructor(githubUrl: string, { accessToken, branch, recursive, unknown, ignoreFiles, ignorePaths, }?: GithubRepoLoaderParams);
51
+ verbose?: boolean;
52
+ protected caller: AsyncCaller;
53
+ constructor(githubUrl: string, { accessToken, branch, recursive, unknown, ignoreFiles, ignorePaths, verbose, maxConcurrency, maxRetries, ...rest }?: GithubRepoLoaderParams);
25
54
  private extractOwnerAndRepoAndPath;
26
55
  load(): Promise<Document[]>;
27
- protected shouldIgnore(path: string, fileType: string): Promise<boolean>;
56
+ protected shouldIgnore(path: string, fileType: string): boolean;
57
+ /**
58
+ * Takes the file info and wrap it in a promise that will resolve to the file content and metadata
59
+ * @param file
60
+ * @returns
61
+ */
62
+ private fetchFileContentWrapper;
63
+ /**
64
+ * Maps a list of files / directories to a list of promises that will fetch the file / directory contents
65
+ */
66
+ private getCurrentDirectoryFilePromises;
67
+ /**
68
+ * Begins the process of fetching the contents of the repository
69
+ */
70
+ private processRepo;
28
71
  private processDirectory;
29
72
  private fetchRepoFiles;
30
73
  private fetchFileContent;