langchain 0.1.1 → 0.1.3

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 (74) hide show
  1. package/dist/agents/agent.cjs +1 -1
  2. package/dist/agents/agent.d.ts +1 -1
  3. package/dist/agents/agent.js +1 -1
  4. package/dist/agents/openai_functions/index.cjs +3 -3
  5. package/dist/agents/openai_functions/index.js +3 -3
  6. package/dist/agents/openai_functions/output_parser.cjs +1 -1
  7. package/dist/agents/openai_functions/output_parser.d.ts +1 -1
  8. package/dist/agents/openai_functions/output_parser.js +1 -1
  9. package/dist/agents/openai_tools/index.cjs +2 -2
  10. package/dist/agents/openai_tools/index.js +2 -2
  11. package/dist/agents/openai_tools/output_parser.cjs +1 -1
  12. package/dist/agents/openai_tools/output_parser.d.ts +1 -1
  13. package/dist/agents/openai_tools/output_parser.js +1 -1
  14. package/dist/cache/cloudflare_kv.cjs +2 -1
  15. package/dist/cache/cloudflare_kv.js +2 -1
  16. package/dist/chains/history_aware_retriever.cjs +1 -1
  17. package/dist/chains/history_aware_retriever.d.ts +1 -1
  18. package/dist/chains/history_aware_retriever.js +1 -1
  19. package/dist/chains/openai_functions/index.d.ts +1 -1
  20. package/dist/chains/sql_db/sql_db_prompt.cjs +20 -1
  21. package/dist/chains/sql_db/sql_db_prompt.d.ts +6 -0
  22. package/dist/chains/sql_db/sql_db_prompt.js +19 -0
  23. package/dist/chat_models/cloudflare_workersai.cjs +2 -0
  24. package/dist/chat_models/cloudflare_workersai.js +2 -0
  25. package/dist/embeddings/cloudflare_workersai.cjs +2 -0
  26. package/dist/embeddings/cloudflare_workersai.js +2 -0
  27. package/dist/evaluation/agents/trajectory.d.ts +2 -2
  28. package/dist/evaluation/base.d.ts +7 -6
  29. package/dist/evaluation/comparison/pairwise.d.ts +2 -2
  30. package/dist/evaluation/criteria/criteria.d.ts +2 -2
  31. package/dist/experimental/chat_models/anthropic_functions.cjs +2 -2
  32. package/dist/experimental/chat_models/anthropic_functions.js +2 -2
  33. package/dist/experimental/chat_models/ollama_functions.d.ts +1 -0
  34. package/dist/experimental/prompts/custom_format.cjs +68 -0
  35. package/dist/experimental/prompts/custom_format.d.ts +24 -0
  36. package/dist/experimental/prompts/custom_format.js +64 -0
  37. package/dist/experimental/prompts/handlebars.cjs +71 -0
  38. package/dist/experimental/prompts/handlebars.d.ts +13 -0
  39. package/dist/experimental/prompts/handlebars.js +62 -0
  40. package/dist/llms/cloudflare_workersai.cjs +2 -0
  41. package/dist/llms/cloudflare_workersai.js +2 -0
  42. package/dist/load/import_constants.cjs +1 -0
  43. package/dist/load/import_constants.js +1 -0
  44. package/dist/load/import_map.cjs +2 -1
  45. package/dist/load/import_map.d.ts +1 -0
  46. package/dist/load/import_map.js +1 -0
  47. package/dist/output_parsers/datetime.cjs +63 -0
  48. package/dist/output_parsers/datetime.d.ts +27 -0
  49. package/dist/output_parsers/datetime.js +59 -0
  50. package/dist/output_parsers/index.cjs +3 -1
  51. package/dist/output_parsers/index.d.ts +1 -0
  52. package/dist/output_parsers/index.js +1 -0
  53. package/dist/output_parsers/openai_functions.cjs +8 -3
  54. package/dist/output_parsers/openai_functions.d.ts +3 -0
  55. package/dist/output_parsers/openai_functions.js +8 -3
  56. package/dist/output_parsers/openai_tools.cjs +18 -5
  57. package/dist/output_parsers/openai_tools.d.ts +4 -0
  58. package/dist/output_parsers/openai_tools.js +18 -5
  59. package/dist/stores/message/cloudflare_d1.cjs +2 -0
  60. package/dist/stores/message/cloudflare_d1.js +2 -0
  61. package/dist/tools/convert_to_openai.cjs +3 -26
  62. package/dist/tools/convert_to_openai.d.ts +2 -8
  63. package/dist/tools/convert_to_openai.js +2 -24
  64. package/dist/util/sql_utils.cjs +23 -0
  65. package/dist/util/sql_utils.js +24 -1
  66. package/dist/vectorstores/cloudflare_vectorize.cjs +2 -0
  67. package/dist/vectorstores/cloudflare_vectorize.js +2 -0
  68. package/experimental/prompts/custom_format.cjs +1 -0
  69. package/experimental/prompts/custom_format.d.ts +1 -0
  70. package/experimental/prompts/custom_format.js +1 -0
  71. package/experimental/prompts/handlebars.cjs +1 -0
  72. package/experimental/prompts/handlebars.d.ts +1 -0
  73. package/experimental/prompts/handlebars.js +1 -0
  74. package/package.json +26 -4
@@ -0,0 +1,64 @@
1
+ import { PromptTemplate, } from "@langchain/core/prompts";
2
+ export class CustomFormatPromptTemplate extends PromptTemplate {
3
+ static lc_name() {
4
+ return "CustomPromptTemplate";
5
+ }
6
+ constructor(input) {
7
+ super(input);
8
+ Object.defineProperty(this, "lc_serializable", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: false
13
+ });
14
+ Object.defineProperty(this, "templateValidator", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: void 0
19
+ });
20
+ Object.defineProperty(this, "renderer", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: void 0
25
+ });
26
+ Object.assign(this, input);
27
+ if (this.validateTemplate && this.templateValidator !== undefined) {
28
+ let totalInputVariables = this.inputVariables;
29
+ if (this.partialVariables) {
30
+ totalInputVariables = totalInputVariables.concat(Object.keys(this.partialVariables));
31
+ }
32
+ this.templateValidator(this.template, totalInputVariables);
33
+ }
34
+ }
35
+ /**
36
+ * Load prompt template from a template
37
+ */
38
+ static fromTemplate(template, { customParser, ...rest }) {
39
+ const names = new Set();
40
+ const nodes = customParser(template);
41
+ for (const node of nodes) {
42
+ if (node.type === "variable") {
43
+ names.add(node.name);
44
+ }
45
+ }
46
+ // eslint-disable-next-line @typescript-eslint/ban-types
47
+ return new this({
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
+ inputVariables: [...names],
50
+ template,
51
+ customParser,
52
+ ...rest,
53
+ });
54
+ }
55
+ /**
56
+ * Formats the prompt template with the provided values.
57
+ * @param values The values to be used to format the prompt template.
58
+ * @returns A promise that resolves to a string which is the formatted prompt.
59
+ */
60
+ async format(values) {
61
+ const allValues = await this.mergePartialAndUserVariables(values);
62
+ return this.renderer(this.template, allValues);
63
+ }
64
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HandlebarsPromptTemplate = exports.interpolateHandlebars = exports.parseHandlebars = void 0;
7
+ const handlebars_1 = __importDefault(require("handlebars"));
8
+ const custom_format_js_1 = require("./custom_format.cjs");
9
+ const parseHandlebars = (template) => {
10
+ const parsed = [];
11
+ const nodes = [...handlebars_1.default.parse(template).body];
12
+ while (nodes.length) {
13
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14
+ const node = nodes.pop();
15
+ if (node.type === "ContentStatement") {
16
+ // @ts-expect-error - handlebars' hbs.AST.ContentStatement isn't exported
17
+ const text = node.value;
18
+ parsed.push({ type: "literal", text });
19
+ }
20
+ else if (node.type === "MustacheStatement") {
21
+ // @ts-expect-error - handlebars' hbs.AST.MustacheStatement isn't exported
22
+ const name = node.path.parts[0];
23
+ // @ts-expect-error - handlebars' hbs.AST.MustacheStatement isn't exported
24
+ const { original } = node.path;
25
+ if (!!name &&
26
+ !original.startsWith("this.") &&
27
+ !original.startsWith("@")) {
28
+ parsed.push({ type: "variable", name });
29
+ }
30
+ }
31
+ else if (node.type === "PathExpression") {
32
+ // @ts-expect-error - handlebars' hbs.AST.PathExpression isn't exported
33
+ const name = node.parts[0];
34
+ // @ts-expect-error - handlebars' hbs.AST.PathExpression isn't exported
35
+ const { original } = node;
36
+ if (!!name &&
37
+ !original.startsWith("this.") &&
38
+ !original.startsWith("@")) {
39
+ parsed.push({ type: "variable", name });
40
+ }
41
+ }
42
+ else if (node.type === "BlockStatement") {
43
+ // @ts-expect-error - handlebars' hbs.AST.BlockStatement isn't exported
44
+ nodes.push(...node.params, ...node.program.body);
45
+ }
46
+ }
47
+ return parsed;
48
+ };
49
+ exports.parseHandlebars = parseHandlebars;
50
+ const interpolateHandlebars = (template, values) => {
51
+ const compiled = handlebars_1.default.compile(template, { noEscape: true });
52
+ return compiled(values);
53
+ };
54
+ exports.interpolateHandlebars = interpolateHandlebars;
55
+ class HandlebarsPromptTemplate extends custom_format_js_1.CustomFormatPromptTemplate {
56
+ static lc_name() {
57
+ return "HandlebarsPromptTemplate";
58
+ }
59
+ /**
60
+ * Load prompt template from a template
61
+ */
62
+ static fromTemplate(template, params) {
63
+ return super.fromTemplate(template, {
64
+ ...params,
65
+ validateTemplate: false,
66
+ customParser: exports.parseHandlebars,
67
+ renderer: exports.interpolateHandlebars,
68
+ });
69
+ }
70
+ }
71
+ exports.HandlebarsPromptTemplate = HandlebarsPromptTemplate;
@@ -0,0 +1,13 @@
1
+ import { type ParsedFStringNode } from "@langchain/core/prompts";
2
+ import type { InputValues } from "@langchain/core/utils/types";
3
+ import { CustomFormatPromptTemplate, CustomFormatPromptTemplateInput } from "./custom_format.js";
4
+ export declare const parseHandlebars: (template: string) => ParsedFStringNode[];
5
+ export declare const interpolateHandlebars: (template: string, values: InputValues) => string;
6
+ export type HandlebarsPromptTemplateInput<RunInput extends InputValues> = CustomFormatPromptTemplateInput<RunInput>;
7
+ export declare class HandlebarsPromptTemplate<RunInput extends InputValues = any> extends CustomFormatPromptTemplate<RunInput> {
8
+ static lc_name(): string;
9
+ /**
10
+ * Load prompt template from a template
11
+ */
12
+ 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>;
13
+ }
@@ -0,0 +1,62 @@
1
+ import Handlebars from "handlebars";
2
+ import { CustomFormatPromptTemplate, } from "./custom_format.js";
3
+ export const parseHandlebars = (template) => {
4
+ const parsed = [];
5
+ const nodes = [...Handlebars.parse(template).body];
6
+ while (nodes.length) {
7
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8
+ const node = nodes.pop();
9
+ if (node.type === "ContentStatement") {
10
+ // @ts-expect-error - handlebars' hbs.AST.ContentStatement isn't exported
11
+ const text = node.value;
12
+ parsed.push({ type: "literal", text });
13
+ }
14
+ else if (node.type === "MustacheStatement") {
15
+ // @ts-expect-error - handlebars' hbs.AST.MustacheStatement isn't exported
16
+ const name = node.path.parts[0];
17
+ // @ts-expect-error - handlebars' hbs.AST.MustacheStatement isn't exported
18
+ const { original } = node.path;
19
+ if (!!name &&
20
+ !original.startsWith("this.") &&
21
+ !original.startsWith("@")) {
22
+ parsed.push({ type: "variable", name });
23
+ }
24
+ }
25
+ else if (node.type === "PathExpression") {
26
+ // @ts-expect-error - handlebars' hbs.AST.PathExpression isn't exported
27
+ const name = node.parts[0];
28
+ // @ts-expect-error - handlebars' hbs.AST.PathExpression isn't exported
29
+ const { original } = node;
30
+ if (!!name &&
31
+ !original.startsWith("this.") &&
32
+ !original.startsWith("@")) {
33
+ parsed.push({ type: "variable", name });
34
+ }
35
+ }
36
+ else if (node.type === "BlockStatement") {
37
+ // @ts-expect-error - handlebars' hbs.AST.BlockStatement isn't exported
38
+ nodes.push(...node.params, ...node.program.body);
39
+ }
40
+ }
41
+ return parsed;
42
+ };
43
+ export const interpolateHandlebars = (template, values) => {
44
+ const compiled = Handlebars.compile(template, { noEscape: true });
45
+ return compiled(values);
46
+ };
47
+ export class HandlebarsPromptTemplate extends CustomFormatPromptTemplate {
48
+ static lc_name() {
49
+ return "HandlebarsPromptTemplate";
50
+ }
51
+ /**
52
+ * Load prompt template from a template
53
+ */
54
+ static fromTemplate(template, params) {
55
+ return super.fromTemplate(template, {
56
+ ...params,
57
+ validateTemplate: false,
58
+ customParser: parseHandlebars,
59
+ renderer: interpolateHandlebars,
60
+ });
61
+ }
62
+ }
@@ -17,5 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  const entrypoint_deprecation_js_1 = require("../util/entrypoint_deprecation.cjs");
18
18
  /* #__PURE__ */ (0, entrypoint_deprecation_js_1.logVersion010MigrationWarning)({
19
19
  oldEntrypointName: "llms/cloudflare_workersai",
20
+ newEntrypointName: "",
21
+ newPackageName: "@langchain/cloudflare",
20
22
  });
21
23
  __exportStar(require("@langchain/community/llms/cloudflare_workersai"), exports);
@@ -1,5 +1,7 @@
1
1
  import { logVersion010MigrationWarning } from "../util/entrypoint_deprecation.js";
2
2
  /* #__PURE__ */ logVersion010MigrationWarning({
3
3
  oldEntrypointName: "llms/cloudflare_workersai",
4
+ newEntrypointName: "",
5
+ newPackageName: "@langchain/cloudflare",
4
6
  });
5
7
  export * from "@langchain/community/llms/cloudflare_workersai";
@@ -175,5 +175,6 @@ exports.optionalImportEntrypoints = [
175
175
  "langchain/experimental/chat_models/anthropic_functions",
176
176
  "langchain/experimental/llms/bittensor",
177
177
  "langchain/experimental/hubs/makersuite/googlemakersuitehub",
178
+ "langchain/experimental/prompts/handlebars",
178
179
  "langchain/experimental/tools/pyinterpreter",
179
180
  ];
@@ -172,5 +172,6 @@ export const optionalImportEntrypoints = [
172
172
  "langchain/experimental/chat_models/anthropic_functions",
173
173
  "langchain/experimental/llms/bittensor",
174
174
  "langchain/experimental/hubs/makersuite/googlemakersuitehub",
175
+ "langchain/experimental/prompts/handlebars",
175
176
  "langchain/experimental/tools/pyinterpreter",
176
177
  ];
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.util__document = exports.storage__in_memory = exports.storage__encoder_backed = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__embeddings_filter = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__remote = exports.output_parsers = exports.schema__query_constructor = exports.schema__prompt_template = exports.chat_models__anthropic = exports.document_transformers__openai_functions = exports.document_loaders__web__sort_xyz_blockchain = exports.document_loaders__web__serpapi = exports.document_loaders__web__searchapi = exports.document_loaders__base = exports.text_splitter = exports.vectorstores__memory = exports.llms__fake = exports.embeddings__fake = exports.embeddings__cache_backed = exports.chains__retrieval = exports.chains__openai_functions = exports.chains__history_aware_retriever = exports.chains__combine_documents__reduce = exports.chains__combine_documents = exports.chains = exports.tools__retriever = exports.tools__render = exports.agents__openai__output_parser = exports.agents__xml__output_parser = exports.agents__react__output_parser = exports.agents__format_scratchpad__log_to_message = exports.agents__format_scratchpad__xml = exports.agents__format_scratchpad__log = exports.agents__format_scratchpad__openai_tools = exports.agents__format_scratchpad = exports.agents__toolkits = exports.agents = void 0;
28
- exports.llms__fireworks = exports.chat_models__fireworks = exports.schema__output = exports.schema__output_parser = exports.schema__runnable = exports.prompts__base = exports.prompts__pipeline = exports.prompts__chat = exports.schema__messages = exports.prompts__prompt = exports.embeddings__openai = exports.llms__openai = exports.chat_models__openai = exports.runnables__remote = exports.evaluation = exports.experimental__masking = exports.experimental__chains__violation_of_expectations = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__openai_files = exports.experimental__openai_assistant = exports.experimental__autogpt = exports.util__time = exports.util__math = void 0;
28
+ exports.llms__fireworks = exports.chat_models__fireworks = exports.schema__output = exports.schema__output_parser = exports.schema__runnable = exports.prompts__base = exports.prompts__pipeline = exports.prompts__chat = exports.schema__messages = exports.prompts__prompt = exports.embeddings__openai = exports.llms__openai = exports.chat_models__openai = exports.runnables__remote = exports.evaluation = exports.experimental__prompts__custom_format = exports.experimental__masking = exports.experimental__chains__violation_of_expectations = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__openai_files = exports.experimental__openai_assistant = exports.experimental__autogpt = exports.util__time = exports.util__math = void 0;
29
29
  exports.agents = __importStar(require("../agents/index.cjs"));
30
30
  exports.agents__toolkits = __importStar(require("../agents/toolkits/index.cjs"));
31
31
  exports.agents__format_scratchpad = __importStar(require("../agents/format_scratchpad/openai_functions.cjs"));
@@ -87,6 +87,7 @@ exports.experimental__plan_and_execute = __importStar(require("../experimental/p
87
87
  exports.experimental__chat_models__bittensor = __importStar(require("../experimental/chat_models/bittensor.cjs"));
88
88
  exports.experimental__chains__violation_of_expectations = __importStar(require("../experimental/chains/violation_of_expectations/index.cjs"));
89
89
  exports.experimental__masking = __importStar(require("../experimental/masking/index.cjs"));
90
+ exports.experimental__prompts__custom_format = __importStar(require("../experimental/prompts/custom_format.cjs"));
90
91
  exports.evaluation = __importStar(require("../evaluation/index.cjs"));
91
92
  exports.runnables__remote = __importStar(require("../runnables/remote.cjs"));
92
93
  const openai_1 = require("@langchain/openai");
@@ -59,6 +59,7 @@ export * as experimental__plan_and_execute from "../experimental/plan_and_execut
59
59
  export * as experimental__chat_models__bittensor from "../experimental/chat_models/bittensor.js";
60
60
  export * as experimental__chains__violation_of_expectations from "../experimental/chains/violation_of_expectations/index.js";
61
61
  export * as experimental__masking from "../experimental/masking/index.js";
62
+ export * as experimental__prompts__custom_format from "../experimental/prompts/custom_format.js";
62
63
  export * as evaluation from "../evaluation/index.js";
63
64
  export * as runnables__remote from "../runnables/remote.js";
64
65
  import { ChatOpenAI, OpenAI, OpenAIEmbeddings } from "@langchain/openai";
@@ -60,6 +60,7 @@ export * as experimental__plan_and_execute from "../experimental/plan_and_execut
60
60
  export * as experimental__chat_models__bittensor from "../experimental/chat_models/bittensor.js";
61
61
  export * as experimental__chains__violation_of_expectations from "../experimental/chains/violation_of_expectations/index.js";
62
62
  export * as experimental__masking from "../experimental/masking/index.js";
63
+ export * as experimental__prompts__custom_format from "../experimental/prompts/custom_format.js";
63
64
  export * as evaluation from "../evaluation/index.js";
64
65
  export * as runnables__remote from "../runnables/remote.js";
65
66
  import { ChatOpenAI, OpenAI, OpenAIEmbeddings } from "@langchain/openai";
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatetimeOutputParser = void 0;
4
+ const output_parsers_1 = require("@langchain/core/output_parsers");
5
+ /**
6
+ * Class to parse the output of an LLM call to a date.
7
+ * @augments BaseOutputParser
8
+ */
9
+ class DatetimeOutputParser extends output_parsers_1.BaseOutputParser {
10
+ constructor() {
11
+ super(...arguments);
12
+ Object.defineProperty(this, "lc_namespace", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: ["langchain", "output_parsers"]
17
+ });
18
+ Object.defineProperty(this, "lc_serializable", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: true
23
+ });
24
+ /**
25
+ * ISO 8601 date time standard.
26
+ */
27
+ Object.defineProperty(this, "format", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: "YYYY-MM-DDTHH:mm:ssZ"
32
+ });
33
+ }
34
+ static lc_name() {
35
+ return "DatetimeOutputParser";
36
+ }
37
+ /**
38
+ * Parses the given text into a Date.
39
+ * If the parsing fails, throws an OutputParserException.
40
+ * @param text The text to parse.
41
+ * @returns A date object.
42
+ */
43
+ async parse(text) {
44
+ const parsedDate = new Date(text.trim());
45
+ if (Number.isNaN(parsedDate.getTime())) {
46
+ throw new output_parsers_1.OutputParserException(`Could not parse output: ${text}`, text);
47
+ }
48
+ return parsedDate;
49
+ }
50
+ /**
51
+ * Provides instructions on the expected format of the response for the
52
+ * CommaSeparatedListOutputParser.
53
+ * @returns A string containing instructions on the expected format of the response.
54
+ */
55
+ getFormatInstructions() {
56
+ return [
57
+ `Your response should be a datetime string that matches the following pattern: "${this.format}".`,
58
+ `Examples: 2011-10-05T14:48:00Z, 2019-01-01T00:00:00Z, 1932-04-21T04:42:23Z`,
59
+ `Return ONLY this string, no other words!`,
60
+ ].join("\n\n");
61
+ }
62
+ }
63
+ exports.DatetimeOutputParser = DatetimeOutputParser;
@@ -0,0 +1,27 @@
1
+ import { BaseOutputParser } from "@langchain/core/output_parsers";
2
+ /**
3
+ * Class to parse the output of an LLM call to a date.
4
+ * @augments BaseOutputParser
5
+ */
6
+ export declare class DatetimeOutputParser extends BaseOutputParser<Date> {
7
+ static lc_name(): string;
8
+ lc_namespace: string[];
9
+ lc_serializable: boolean;
10
+ /**
11
+ * ISO 8601 date time standard.
12
+ */
13
+ format: string;
14
+ /**
15
+ * Parses the given text into a Date.
16
+ * If the parsing fails, throws an OutputParserException.
17
+ * @param text The text to parse.
18
+ * @returns A date object.
19
+ */
20
+ parse(text: string): Promise<Date>;
21
+ /**
22
+ * Provides instructions on the expected format of the response for the
23
+ * CommaSeparatedListOutputParser.
24
+ * @returns A string containing instructions on the expected format of the response.
25
+ */
26
+ getFormatInstructions(): string;
27
+ }
@@ -0,0 +1,59 @@
1
+ import { BaseOutputParser, OutputParserException, } from "@langchain/core/output_parsers";
2
+ /**
3
+ * Class to parse the output of an LLM call to a date.
4
+ * @augments BaseOutputParser
5
+ */
6
+ export class DatetimeOutputParser extends BaseOutputParser {
7
+ constructor() {
8
+ super(...arguments);
9
+ Object.defineProperty(this, "lc_namespace", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: ["langchain", "output_parsers"]
14
+ });
15
+ Object.defineProperty(this, "lc_serializable", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: true
20
+ });
21
+ /**
22
+ * ISO 8601 date time standard.
23
+ */
24
+ Object.defineProperty(this, "format", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: "YYYY-MM-DDTHH:mm:ssZ"
29
+ });
30
+ }
31
+ static lc_name() {
32
+ return "DatetimeOutputParser";
33
+ }
34
+ /**
35
+ * Parses the given text into a Date.
36
+ * If the parsing fails, throws an OutputParserException.
37
+ * @param text The text to parse.
38
+ * @returns A date object.
39
+ */
40
+ async parse(text) {
41
+ const parsedDate = new Date(text.trim());
42
+ if (Number.isNaN(parsedDate.getTime())) {
43
+ throw new OutputParserException(`Could not parse output: ${text}`, text);
44
+ }
45
+ return parsedDate;
46
+ }
47
+ /**
48
+ * Provides instructions on the expected format of the response for the
49
+ * CommaSeparatedListOutputParser.
50
+ * @returns A string containing instructions on the expected format of the response.
51
+ */
52
+ getFormatInstructions() {
53
+ return [
54
+ `Your response should be a datetime string that matches the following pattern: "${this.format}".`,
55
+ `Examples: 2011-10-05T14:48:00Z, 2019-01-01T00:00:00Z, 1932-04-21T04:42:23Z`,
56
+ `Return ONLY this string, no other words!`,
57
+ ].join("\n\n");
58
+ }
59
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpResponseOutputParser = exports.JsonOutputToolsParser = exports.JsonKeyOutputFunctionsParser = exports.JsonOutputFunctionsParser = exports.OutputFunctionsParser = exports.CustomListOutputParser = exports.RouterOutputParser = exports.CombiningOutputParser = exports.OutputFixingParser = exports.JsonMarkdownStructuredOutputParser = exports.AsymmetricStructuredOutputParser = exports.StructuredOutputParser = exports.RegexParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
3
+ exports.DatetimeOutputParser = exports.HttpResponseOutputParser = exports.JsonOutputToolsParser = exports.JsonKeyOutputFunctionsParser = exports.JsonOutputFunctionsParser = exports.OutputFunctionsParser = exports.CustomListOutputParser = exports.RouterOutputParser = exports.CombiningOutputParser = exports.OutputFixingParser = exports.JsonMarkdownStructuredOutputParser = exports.AsymmetricStructuredOutputParser = exports.StructuredOutputParser = exports.RegexParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
4
4
  var list_js_1 = require("./list.cjs");
5
5
  Object.defineProperty(exports, "ListOutputParser", { enumerable: true, get: function () { return list_js_1.ListOutputParser; } });
6
6
  Object.defineProperty(exports, "CommaSeparatedListOutputParser", { enumerable: true, get: function () { return list_js_1.CommaSeparatedListOutputParser; } });
@@ -26,3 +26,5 @@ var openai_tools_js_1 = require("../output_parsers/openai_tools.cjs");
26
26
  Object.defineProperty(exports, "JsonOutputToolsParser", { enumerable: true, get: function () { return openai_tools_js_1.JsonOutputToolsParser; } });
27
27
  var http_response_js_1 = require("./http_response.cjs");
28
28
  Object.defineProperty(exports, "HttpResponseOutputParser", { enumerable: true, get: function () { return http_response_js_1.HttpResponseOutputParser; } });
29
+ var datetime_js_1 = require("./datetime.cjs");
30
+ Object.defineProperty(exports, "DatetimeOutputParser", { enumerable: true, get: function () { return datetime_js_1.DatetimeOutputParser; } });
@@ -8,3 +8,4 @@ export { CustomListOutputParser } from "./list.js";
8
8
  export { type FunctionParameters, OutputFunctionsParser, JsonOutputFunctionsParser, JsonKeyOutputFunctionsParser, } from "../output_parsers/openai_functions.js";
9
9
  export { type ParsedToolCall, JsonOutputToolsParser, } from "../output_parsers/openai_tools.js";
10
10
  export { HttpResponseOutputParser, type HttpResponseOutputParserInput, } from "./http_response.js";
11
+ export { DatetimeOutputParser } from "./datetime.js";
@@ -8,3 +8,4 @@ export { CustomListOutputParser } from "./list.js";
8
8
  export { OutputFunctionsParser, JsonOutputFunctionsParser, JsonKeyOutputFunctionsParser, } from "../output_parsers/openai_functions.js";
9
9
  export { JsonOutputToolsParser, } from "../output_parsers/openai_tools.js";
10
10
  export { HttpResponseOutputParser, } from "./http_response.js";
11
+ export { DatetimeOutputParser } from "./datetime.js";
@@ -18,7 +18,7 @@ class OutputFunctionsParser extends output_parsers_1.BaseLLMOutputParser {
18
18
  enumerable: true,
19
19
  configurable: true,
20
20
  writable: true,
21
- value: ["langchain", "output_parsers"]
21
+ value: ["langchain", "output_parsers", "openai_functions"]
22
22
  });
23
23
  Object.defineProperty(this, "lc_serializable", {
24
24
  enumerable: true,
@@ -75,7 +75,7 @@ class JsonOutputFunctionsParser extends output_parsers_1.BaseCumulativeTransform
75
75
  enumerable: true,
76
76
  configurable: true,
77
77
  writable: true,
78
- value: ["langchain", "output_parsers"]
78
+ value: ["langchain", "output_parsers", "openai_functions"]
79
79
  });
80
80
  Object.defineProperty(this, "lc_serializable", {
81
81
  enumerable: true,
@@ -158,13 +158,18 @@ class JsonKeyOutputFunctionsParser extends output_parsers_1.BaseLLMOutputParser
158
158
  static lc_name() {
159
159
  return "JsonKeyOutputFunctionsParser";
160
160
  }
161
+ get lc_aliases() {
162
+ return {
163
+ attrName: "key_name",
164
+ };
165
+ }
161
166
  constructor(fields) {
162
167
  super(fields);
163
168
  Object.defineProperty(this, "lc_namespace", {
164
169
  enumerable: true,
165
170
  configurable: true,
166
171
  writable: true,
167
- value: ["langchain", "output_parsers"]
172
+ value: ["langchain", "output_parsers", "openai_functions"]
168
173
  });
169
174
  Object.defineProperty(this, "lc_serializable", {
170
175
  enumerable: true,
@@ -63,6 +63,9 @@ export declare class JsonKeyOutputFunctionsParser<T = object> extends BaseLLMOut
63
63
  lc_serializable: boolean;
64
64
  outputParser: JsonOutputFunctionsParser<object>;
65
65
  attrName: string;
66
+ get lc_aliases(): {
67
+ attrName: string;
68
+ };
66
69
  constructor(fields: {
67
70
  attrName: string;
68
71
  });
@@ -15,7 +15,7 @@ export class OutputFunctionsParser extends BaseLLMOutputParser {
15
15
  enumerable: true,
16
16
  configurable: true,
17
17
  writable: true,
18
- value: ["langchain", "output_parsers"]
18
+ value: ["langchain", "output_parsers", "openai_functions"]
19
19
  });
20
20
  Object.defineProperty(this, "lc_serializable", {
21
21
  enumerable: true,
@@ -71,7 +71,7 @@ export class JsonOutputFunctionsParser extends BaseCumulativeTransformOutputPars
71
71
  enumerable: true,
72
72
  configurable: true,
73
73
  writable: true,
74
- value: ["langchain", "output_parsers"]
74
+ value: ["langchain", "output_parsers", "openai_functions"]
75
75
  });
76
76
  Object.defineProperty(this, "lc_serializable", {
77
77
  enumerable: true,
@@ -153,13 +153,18 @@ export class JsonKeyOutputFunctionsParser extends BaseLLMOutputParser {
153
153
  static lc_name() {
154
154
  return "JsonKeyOutputFunctionsParser";
155
155
  }
156
+ get lc_aliases() {
157
+ return {
158
+ attrName: "key_name",
159
+ };
160
+ }
156
161
  constructor(fields) {
157
162
  super(fields);
158
163
  Object.defineProperty(this, "lc_namespace", {
159
164
  enumerable: true,
160
165
  configurable: true,
161
166
  writable: true,
162
- value: ["langchain", "output_parsers"]
167
+ value: ["langchain", "output_parsers", "openai_functions"]
163
168
  });
164
169
  Object.defineProperty(this, "lc_serializable", {
165
170
  enumerable: true,
@@ -13,7 +13,7 @@ class JsonOutputToolsParser extends output_parsers_1.BaseLLMOutputParser {
13
13
  enumerable: true,
14
14
  configurable: true,
15
15
  writable: true,
16
- value: ["langchain", "output_parsers"]
16
+ value: ["langchain", "output_parsers", "openai_tools"]
17
17
  });
18
18
  Object.defineProperty(this, "lc_serializable", {
19
19
  enumerable: true,
@@ -40,11 +40,24 @@ class JsonOutputToolsParser extends output_parsers_1.BaseLLMOutputParser {
40
40
  const parsedToolCalls = [];
41
41
  for (const toolCall of clonedToolCalls) {
42
42
  if (toolCall.function !== undefined) {
43
- const functionArgs = toolCall.function.arguments;
44
- parsedToolCalls.push({
45
- name: toolCall.function.name,
46
- arguments: JSON.parse(functionArgs),
43
+ // @ts-expect-error name and arguemnts are defined by Object.defineProperty
44
+ const parsedToolCall = {
45
+ type: toolCall.function.name,
46
+ args: JSON.parse(toolCall.function.arguments),
47
+ };
48
+ // backward-compatibility with previous
49
+ // versions of Langchain JS, which uses `name` and `arguments`
50
+ Object.defineProperty(parsedToolCall, "name", {
51
+ get() {
52
+ return this.type;
53
+ },
47
54
  });
55
+ Object.defineProperty(parsedToolCall, "arguments", {
56
+ get() {
57
+ return this.args;
58
+ },
59
+ });
60
+ parsedToolCalls.push(parsedToolCall);
48
61
  }
49
62
  }
50
63
  return parsedToolCalls;
@@ -1,7 +1,11 @@
1
1
  import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
2
2
  import type { ChatGeneration } from "@langchain/core/outputs";
3
3
  export type ParsedToolCall = {
4
+ type: string;
5
+ args: Record<string, any>;
6
+ /** @deprecated Use `type` instead. Will be removed in 0.2.0. */
4
7
  name: string;
8
+ /** @deprecated Use `args` instead. Will be removed in 0.2.0. */
5
9
  arguments: Record<string, any>;
6
10
  };
7
11
  /**
@@ -10,7 +10,7 @@ export class JsonOutputToolsParser extends BaseLLMOutputParser {
10
10
  enumerable: true,
11
11
  configurable: true,
12
12
  writable: true,
13
- value: ["langchain", "output_parsers"]
13
+ value: ["langchain", "output_parsers", "openai_tools"]
14
14
  });
15
15
  Object.defineProperty(this, "lc_serializable", {
16
16
  enumerable: true,
@@ -37,11 +37,24 @@ export class JsonOutputToolsParser extends BaseLLMOutputParser {
37
37
  const parsedToolCalls = [];
38
38
  for (const toolCall of clonedToolCalls) {
39
39
  if (toolCall.function !== undefined) {
40
- const functionArgs = toolCall.function.arguments;
41
- parsedToolCalls.push({
42
- name: toolCall.function.name,
43
- arguments: JSON.parse(functionArgs),
40
+ // @ts-expect-error name and arguemnts are defined by Object.defineProperty
41
+ const parsedToolCall = {
42
+ type: toolCall.function.name,
43
+ args: JSON.parse(toolCall.function.arguments),
44
+ };
45
+ // backward-compatibility with previous
46
+ // versions of Langchain JS, which uses `name` and `arguments`
47
+ Object.defineProperty(parsedToolCall, "name", {
48
+ get() {
49
+ return this.type;
50
+ },
44
51
  });
52
+ Object.defineProperty(parsedToolCall, "arguments", {
53
+ get() {
54
+ return this.args;
55
+ },
56
+ });
57
+ parsedToolCalls.push(parsedToolCall);
45
58
  }
46
59
  }
47
60
  return parsedToolCalls;