2e3e489875d9f75f9d2ccff0a752124e069b7415d0354d8a5b5dfc3967f750e2.json 12 KB

1
  1. {"ast":null,"code":"import _asyncToGenerator from \"F:/workspace/202226701027/huinongbao-app/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\n// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\nimport { Runnable } from \"../runnables/base.js\";\n/**\n * Base class for prompt templates. Exposes a format method that returns a\n * string prompt given a set of input values.\n */\nexport class BasePromptTemplate extends Runnable {\n get lc_attributes() {\n return {\n partialVariables: undefined // python doesn't support this yet\n };\n }\n constructor(input) {\n super(input);\n Object.defineProperty(this, \"lc_serializable\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: true\n });\n Object.defineProperty(this, \"lc_namespace\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: [\"langchain_core\", \"prompts\", this._getPromptType()]\n });\n Object.defineProperty(this, \"inputVariables\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"outputParser\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"partialVariables\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n const {\n inputVariables\n } = input;\n if (inputVariables.includes(\"stop\")) {\n throw new Error(\"Cannot have an input variable named 'stop', as it is used internally, please rename.\");\n }\n Object.assign(this, input);\n }\n /**\n * Merges partial variables and user variables.\n * @param userVariables The user variables to merge with the partial variables.\n * @returns A Promise that resolves to an object containing the merged variables.\n */\n mergePartialAndUserVariables(userVariables) {\n var _this = this;\n return _asyncToGenerator(function* () {\n var _this$partialVariable;\n const partialVariables = (_this$partialVariable = _this.partialVariables) !== null && _this$partialVariable !== void 0 ? _this$partialVariable : {};\n const partialValues = {};\n for (const [key, value] of Object.entries(partialVariables)) {\n if (typeof value === \"string\") {\n partialValues[key] = value;\n } else {\n partialValues[key] = yield value();\n }\n }\n const allKwargs = {\n ...partialValues,\n ...userVariables\n };\n return allKwargs;\n })();\n }\n /**\n * Invokes the prompt template with the given input and options.\n * @param input The input to invoke the prompt template with.\n * @param options Optional configuration for the callback.\n * @returns A Promise that resolves to the output of the prompt template.\n */\n invoke(input, options) {\n var _this2 = this;\n return _asyncToGenerator(function* () {\n return _this2._callWithConfig(input => _this2.formatPromptValue(input), input, {\n ...options,\n runType: \"prompt\"\n });\n })();\n }\n /**\n * Return a json-like object representing this prompt template.\n * @deprecated\n */\n serialize() {\n throw new Error(\"Use .toJSON() instead\");\n }\n /**\n * @deprecated\n * Load a prompt template from a json-like object describing it.\n *\n * @remarks\n * Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can\n * reference remote resources that we read asynchronously with a web\n * request.\n */\n static deserialize(data) {\n return _asyncToGenerator(function* () {\n switch (data._type) {\n case \"prompt\":\n {\n const {\n PromptTemplate\n } = yield import(\"./prompt.js\");\n return PromptTemplate.deserialize(data);\n }\n case undefined:\n {\n const {\n PromptTemplate\n } = yield import(\"./prompt.js\");\n return PromptTemplate.deserialize({\n ...data,\n _type: \"prompt\"\n });\n }\n case \"few_shot\":\n {\n const {\n FewShotPromptTemplate\n } = yield import(\"./few_shot.js\");\n return FewShotPromptTemplate.deserialize(data);\n }\n default:\n throw new Error(`Invalid prompt type in config: ${data._type}`);\n }\n })();\n }\n}","map":{"version":3,"names":["Runnable","BasePromptTemplate","lc_attributes","partialVariables","undefined","constructor","input","Object","defineProperty","enumerable","configurable","writable","value","_getPromptType","inputVariables","includes","Error","assign","mergePartialAndUserVariables","userVariables","_this","_asyncToGenerator","_this$partialVariable","partialValues","key","entries","allKwargs","invoke","options","_this2","_callWithConfig","formatPromptValue","runType","serialize","deserialize","data","_type","PromptTemplate","FewShotPromptTemplate"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@langchain/core/dist/prompts/base.js"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\nimport { Runnable } from \"../runnables/base.js\";\n/**\n * Base class for prompt templates. Exposes a format method that returns a\n * string prompt given a set of input values.\n */\nexport class BasePromptTemplate extends Runnable {\n get lc_attributes() {\n return {\n partialVariables: undefined, // python doesn't support this yet\n };\n }\n constructor(input) {\n super(input);\n Object.defineProperty(this, \"lc_serializable\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: true\n });\n Object.defineProperty(this, \"lc_namespace\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: [\"langchain_core\", \"prompts\", this._getPromptType()]\n });\n Object.defineProperty(this, \"inputVariables\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"outputParser\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"partialVariables\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n const { inputVariables } = input;\n if (inputVariables.includes(\"stop\")) {\n throw new Error(\"Cannot have an input variable named 'stop', as it is used internally, please rename.\");\n }\n Object.assign(this, input);\n }\n /**\n * Merges partial variables and user variables.\n * @param userVariables The user variables to merge with the partial variables.\n * @returns A Promise that resolves to an object containing the merged variables.\n */\n async mergePartialAndUserVariables(userVariables) {\n const partialVariables = this.partialVariables ?? {};\n const partialValues = {};\n for (const [key, value] of Object.entries(partialVariables)) {\n if (typeof value === \"string\") {\n partialValues[key] = value;\n }\n else {\n partialValues[key] = await value();\n }\n }\n const allKwargs = {\n ...partialValues,\n ...userVariables,\n };\n return allKwargs;\n }\n /**\n * Invokes the prompt template with the given input and options.\n * @param input The input to invoke the prompt template with.\n * @param options Optional configuration for the callback.\n * @returns A Promise that resolves to the output of the prompt template.\n */\n async invoke(input, options) {\n return this._callWithConfig((input) => this.formatPromptValue(input), input, { ...options, runType: \"prompt\" });\n }\n /**\n * Return a json-like object representing this prompt template.\n * @deprecated\n */\n serialize() {\n throw new Error(\"Use .toJSON() instead\");\n }\n /**\n * @deprecated\n * Load a prompt template from a json-like object describing it.\n *\n * @remarks\n * Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can\n * reference remote resources that we read asynchronously with a web\n * request.\n */\n static async deserialize(data) {\n switch (data._type) {\n case \"prompt\": {\n const { PromptTemplate } = await import(\"./prompt.js\");\n return PromptTemplate.deserialize(data);\n }\n case undefined: {\n const { PromptTemplate } = await import(\"./prompt.js\");\n return PromptTemplate.deserialize({ ...data, _type: \"prompt\" });\n }\n case \"few_shot\": {\n const { FewShotPromptTemplate } = await import(\"./few_shot.js\");\n return FewShotPromptTemplate.deserialize(data);\n }\n default:\n throw new Error(`Invalid prompt type in config: ${data._type}`);\n }\n }\n}\n"],"mappings":";AAAA;AACA;AACA,SAASA,QAAQ,QAAQ,sBAAsB;AAC/C;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,SAASD,QAAQ,CAAC;EAC7C,IAAIE,aAAaA,CAAA,EAAG;IAChB,OAAO;MACHC,gBAAgB,EAAEC,SAAS,CAAE;IACjC,CAAC;EACL;EACAC,WAAWA,CAACC,KAAK,EAAE;IACf,KAAK,CAACA,KAAK,CAAC;IACZC,MAAM,CAACC,cAAc,CAAC,IAAI,EAAE,iBAAiB,EAAE;MAC3CC,UAAU,EAAE,IAAI;MAChBC,YAAY,EAAE,IAAI;MAClBC,QAAQ,EAAE,IAAI;MACdC,KAAK,EAAE;IACX,CAAC,CAAC;IACFL,MAAM,CAACC,cAAc,CAAC,IAAI,EAAE,cAAc,EAAE;MACxCC,UAAU,EAAE,IAAI;MAChBC,YAAY,EAAE,IAAI;MAClBC,QAAQ,EAAE,IAAI;MACdC,KAAK,EAAE,CAAC,gBAAgB,EAAE,SAAS,EAAE,IAAI,CAACC,cAAc,CAAC,CAAC;IAC9D,CAAC,CAAC;IACFN,MAAM,CAACC,cAAc,CAAC,IAAI,EAAE,gBAAgB,EAAE;MAC1CC,UAAU,EAAE,IAAI;MAChBC,YAAY,EAAE,IAAI;MAClBC,QAAQ,EAAE,IAAI;MACdC,KAAK,EAAE,KAAK;I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