langchain 0.1.0 → 0.1.2

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 (44) 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/chains/openai_functions/base.cjs +144 -0
  5. package/dist/chains/openai_functions/base.d.ts +153 -0
  6. package/dist/chains/openai_functions/base.js +139 -0
  7. package/dist/chains/openai_functions/index.cjs +4 -1
  8. package/dist/chains/openai_functions/index.d.ts +1 -0
  9. package/dist/chains/openai_functions/index.js +1 -0
  10. package/dist/evaluation/agents/trajectory.d.ts +2 -2
  11. package/dist/evaluation/base.d.ts +7 -6
  12. package/dist/evaluation/comparison/pairwise.d.ts +2 -2
  13. package/dist/evaluation/criteria/criteria.d.ts +2 -2
  14. package/dist/experimental/chat_models/ollama_functions.d.ts +1 -0
  15. package/dist/experimental/prompts/custom_format.cjs +68 -0
  16. package/dist/experimental/prompts/custom_format.d.ts +24 -0
  17. package/dist/experimental/prompts/custom_format.js +64 -0
  18. package/dist/experimental/prompts/handlebars.cjs +71 -0
  19. package/dist/experimental/prompts/handlebars.d.ts +13 -0
  20. package/dist/experimental/prompts/handlebars.js +62 -0
  21. package/dist/load/import_constants.cjs +1 -0
  22. package/dist/load/import_constants.js +1 -0
  23. package/dist/load/import_map.cjs +2 -1
  24. package/dist/load/import_map.d.ts +1 -0
  25. package/dist/load/import_map.js +1 -0
  26. package/dist/output_parsers/datetime.cjs +63 -0
  27. package/dist/output_parsers/datetime.d.ts +27 -0
  28. package/dist/output_parsers/datetime.js +59 -0
  29. package/dist/output_parsers/index.cjs +3 -1
  30. package/dist/output_parsers/index.d.ts +1 -0
  31. package/dist/output_parsers/index.js +1 -0
  32. package/dist/output_parsers/openai_functions.cjs +8 -3
  33. package/dist/output_parsers/openai_functions.d.ts +8 -5
  34. package/dist/output_parsers/openai_functions.js +8 -3
  35. package/dist/output_parsers/openai_tools.cjs +18 -5
  36. package/dist/output_parsers/openai_tools.d.ts +4 -0
  37. package/dist/output_parsers/openai_tools.js +18 -5
  38. package/experimental/prompts/custom_format.cjs +1 -0
  39. package/experimental/prompts/custom_format.d.ts +1 -0
  40. package/experimental/prompts/custom_format.js +1 -0
  41. package/experimental/prompts/handlebars.cjs +1 -0
  42. package/experimental/prompts/handlebars.d.ts +1 -0
  43. package/experimental/prompts/handlebars.js +1 -0
  44. package/package.json +24 -2
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomFormatPromptTemplate = void 0;
4
+ const prompts_1 = require("@langchain/core/prompts");
5
+ class CustomFormatPromptTemplate extends prompts_1.PromptTemplate {
6
+ static lc_name() {
7
+ return "CustomPromptTemplate";
8
+ }
9
+ constructor(input) {
10
+ super(input);
11
+ Object.defineProperty(this, "lc_serializable", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: false
16
+ });
17
+ Object.defineProperty(this, "templateValidator", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: void 0
22
+ });
23
+ Object.defineProperty(this, "renderer", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: void 0
28
+ });
29
+ Object.assign(this, input);
30
+ if (this.validateTemplate && this.templateValidator !== undefined) {
31
+ let totalInputVariables = this.inputVariables;
32
+ if (this.partialVariables) {
33
+ totalInputVariables = totalInputVariables.concat(Object.keys(this.partialVariables));
34
+ }
35
+ this.templateValidator(this.template, totalInputVariables);
36
+ }
37
+ }
38
+ /**
39
+ * Load prompt template from a template
40
+ */
41
+ static fromTemplate(template, { customParser, ...rest }) {
42
+ const names = new Set();
43
+ const nodes = customParser(template);
44
+ for (const node of nodes) {
45
+ if (node.type === "variable") {
46
+ names.add(node.name);
47
+ }
48
+ }
49
+ // eslint-disable-next-line @typescript-eslint/ban-types
50
+ return new this({
51
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
+ inputVariables: [...names],
53
+ template,
54
+ customParser,
55
+ ...rest,
56
+ });
57
+ }
58
+ /**
59
+ * Formats the prompt template with the provided values.
60
+ * @param values The values to be used to format the prompt template.
61
+ * @returns A promise that resolves to a string which is the formatted prompt.
62
+ */
63
+ async format(values) {
64
+ const allValues = await this.mergePartialAndUserVariables(values);
65
+ return this.renderer(this.template, allValues);
66
+ }
67
+ }
68
+ exports.CustomFormatPromptTemplate = CustomFormatPromptTemplate;
@@ -0,0 +1,24 @@
1
+ import type { InputValues } from "@langchain/core/utils/types";
2
+ import { type ParsedFStringNode, PromptTemplate, type PromptTemplateInput, TypedPromptInputValues } from "@langchain/core/prompts";
3
+ export type CustomFormatPromptTemplateInput<RunInput extends InputValues> = Omit<PromptTemplateInput<RunInput, string>, "templateFormat"> & {
4
+ customParser: (template: string) => ParsedFStringNode[];
5
+ templateValidator?: (template: string, inputVariables: string[]) => boolean;
6
+ renderer: (template: string, values: InputValues) => string;
7
+ };
8
+ export declare class CustomFormatPromptTemplate<RunInput extends InputValues = any, PartialVariableName extends string = any> extends PromptTemplate<RunInput, PartialVariableName> {
9
+ static lc_name(): string;
10
+ lc_serializable: boolean;
11
+ templateValidator?: (template: string, inputVariables: string[]) => boolean;
12
+ renderer: (template: string, values: InputValues) => string;
13
+ constructor(input: CustomFormatPromptTemplateInput<RunInput>);
14
+ /**
15
+ * Load prompt template from a template
16
+ */
17
+ static fromTemplate<RunInput extends InputValues = Record<string, any>>(template: string, { customParser, ...rest }: Omit<CustomFormatPromptTemplateInput<RunInput>, "template" | "inputVariables">): CustomFormatPromptTemplate<RunInput extends Symbol ? never : RunInput, any>;
18
+ /**
19
+ * Formats the prompt template with the provided values.
20
+ * @param values The values to be used to format the prompt template.
21
+ * @returns A promise that resolves to a string which is the formatted prompt.
22
+ */
23
+ format(values: TypedPromptInputValues<RunInput>): Promise<string>;
24
+ }
@@ -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
+ }
@@ -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,
@@ -31,7 +31,7 @@ export declare class OutputFunctionsParser extends BaseLLMOutputParser<string> {
31
31
  * Class for parsing the output of an LLM into a JSON object. Uses an
32
32
  * instance of `OutputFunctionsParser` to parse the output.
33
33
  */
34
- export declare class JsonOutputFunctionsParser extends BaseCumulativeTransformOutputParser<object> {
34
+ export declare class JsonOutputFunctionsParser<Output extends object = object> extends BaseCumulativeTransformOutputParser<Output> {
35
35
  static lc_name(): string;
36
36
  lc_namespace: string[];
37
37
  lc_serializable: boolean;
@@ -41,15 +41,15 @@ export declare class JsonOutputFunctionsParser extends BaseCumulativeTransformOu
41
41
  argsOnly?: boolean;
42
42
  } & BaseCumulativeTransformOutputParserInput);
43
43
  protected _diff(prev: unknown | undefined, next: unknown): JSONPatchOperation[] | undefined;
44
- parsePartialResult(generations: ChatGeneration[]): Promise<object | undefined>;
44
+ parsePartialResult(generations: ChatGeneration[]): Promise<Output | undefined>;
45
45
  /**
46
46
  * Parses the output and returns a JSON object. If `argsOnly` is true,
47
47
  * only the arguments of the function call are returned.
48
48
  * @param generations The output of the LLM to parse.
49
49
  * @returns A JSON object representation of the function call or its arguments.
50
50
  */
51
- parseResult(generations: Generation[] | ChatGeneration[]): Promise<object>;
52
- parse(text: string): Promise<object>;
51
+ parseResult(generations: Generation[] | ChatGeneration[]): Promise<Output>;
52
+ parse(text: string): Promise<Output>;
53
53
  getFormatInstructions(): string;
54
54
  }
55
55
  /**
@@ -61,8 +61,11 @@ export declare class JsonKeyOutputFunctionsParser<T = object> extends BaseLLMOut
61
61
  static lc_name(): string;
62
62
  lc_namespace: string[];
63
63
  lc_serializable: boolean;
64
- outputParser: JsonOutputFunctionsParser;
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
  });