e726673bb1020738def817b7d07c12231ef932bf6cb1e21b435e26b907212e39.json 14 KB

1
  1. {"ast":null,"code":"import _asyncToGenerator from \"F:/workspace/202226701027/huinongbao-app/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\nimport { ImagePromptValue } from \"../prompt_values.js\";\nimport { BasePromptTemplate } from \"./base.js\";\nimport { checkValidTemplate, renderTemplate } from \"./template.js\";\n/**\n * An image prompt template for a multimodal model.\n */\nexport class ImagePromptTemplate extends BasePromptTemplate {\n static lc_name() {\n return \"ImagePromptTemplate\";\n }\n constructor(input) {\n var _input$templateFormat, _input$validateTempla;\n super(input);\n Object.defineProperty(this, \"lc_namespace\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: [\"langchain_core\", \"prompts\", \"image\"]\n });\n Object.defineProperty(this, \"template\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"templateFormat\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: \"f-string\"\n });\n Object.defineProperty(this, \"validateTemplate\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: true\n });\n /**\n * Additional fields which should be included inside\n * the message content array if using a complex message\n * content.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Object.defineProperty(this, \"additionalContentFields\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this.template = input.template;\n this.templateFormat = (_input$templateFormat = input.templateFormat) !== null && _input$templateFormat !== void 0 ? _input$templateFormat : this.templateFormat;\n this.validateTemplate = (_input$validateTempla = input.validateTemplate) !== null && _input$validateTempla !== void 0 ? _input$validateTempla : this.validateTemplate;\n this.additionalContentFields = input.additionalContentFields;\n if (this.validateTemplate) {\n let totalInputVariables = this.inputVariables;\n if (this.partialVariables) {\n totalInputVariables = totalInputVariables.concat(Object.keys(this.partialVariables));\n }\n checkValidTemplate([{\n type: \"image_url\",\n image_url: this.template\n }], this.templateFormat, totalInputVariables);\n }\n }\n _getPromptType() {\n return \"prompt\";\n }\n /**\n * Partially applies values to the prompt template.\n * @param values The values to be partially applied to the prompt template.\n * @returns A new instance of ImagePromptTemplate with the partially applied values.\n */\n partial(values) {\n var _this = this;\n return _asyncToGenerator(function* () {\n var _this$partialVariable;\n const newInputVariables = _this.inputVariables.filter(iv => !(iv in values));\n const newPartialVariables = {\n ...((_this$partialVariable = _this.partialVariables) !== null && _this$partialVariable !== void 0 ? _this$partialVariable : {}),\n ...values\n };\n const promptDict = {\n ..._this,\n inputVariables: newInputVariables,\n partialVariables: newPartialVariables\n };\n return new ImagePromptTemplate(promptDict);\n })();\n }\n /**\n * Formats the prompt template with the provided values.\n * @param values The values to be used to format the prompt template.\n * @returns A promise that resolves to a string which is the formatted prompt.\n */\n format(values) {\n var _this2 = this;\n return _asyncToGenerator(function* () {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const formatted = {};\n for (const [key, value] of Object.entries(_this2.template)) {\n if (typeof value === \"string\") {\n formatted[key] = renderTemplate(value, _this2.templateFormat, values);\n } else {\n formatted[key] = value;\n }\n }\n const url = values.url || formatted.url;\n const detail = values.detail || formatted.detail;\n if (!url) {\n throw new Error(\"Must provide either an image URL.\");\n }\n if (typeof url !== \"string\") {\n throw new Error(\"url must be a string.\");\n }\n const output = {\n url\n };\n if (detail) {\n output.detail = detail;\n }\n return output;\n })();\n }\n /**\n * Formats the prompt given the input values and returns a formatted\n * prompt value.\n * @param values The input values to format the prompt.\n * @returns A Promise that resolves to a formatted prompt value.\n */\n formatPromptValue(values) {\n var _this3 = this;\n return _asyncToGenerator(function* () {\n const formattedPrompt = yield _this3.format(values);\n return new ImagePromptValue(formattedPrompt);\n })();\n }\n}","map":{"version":3,"names":["ImagePromptValue","BasePromptTemplate","checkValidTemplate","renderTemplate","ImagePromptTemplate","lc_name","constructor","input","_input$templateFormat","_input$validateTempla","Object","defineProperty","enumerable","configurable","writable","value","template","templateFormat","validateTemplate","additionalContentFields","totalInputVariables","inputVariables","partialVariables","concat","keys","type","image_url","_getPromptType","partial","values","_this","_asyncToGenerator","_this$partialVariable","newInputVariables","filter","iv","newPartialVariables","promptDict","format","_this2","formatted","key","entries","url","detail","Error","output","formatPromptValue","_this3","formattedPrompt"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@langchain/core/dist/prompts/image.js"],"sourcesContent":["import { ImagePromptValue } from \"../prompt_values.js\";\nimport { BasePromptTemplate, } from \"./base.js\";\nimport { checkValidTemplate, renderTemplate, } from \"./template.js\";\n/**\n * An image prompt template for a multimodal model.\n */\nexport class ImagePromptTemplate extends BasePromptTemplate {\n static lc_name() {\n return \"ImagePromptTemplate\";\n }\n constructor(input) {\n super(input);\n Object.defineProperty(this, \"lc_namespace\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: [\"langchain_core\", \"prompts\", \"image\"]\n });\n Object.defineProperty(this, \"template\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"templateFormat\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: \"f-string\"\n });\n Object.defineProperty(this, \"validateTemplate\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: true\n });\n /**\n * Additional fields which should be included inside\n * the message content array if using a complex message\n * content.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Object.defineProperty(this, \"additionalContentFields\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this.template = input.template;\n this.templateFormat = input.templateFormat ?? this.templateFormat;\n this.validateTemplate = input.validateTemplate ?? this.validateTemplate;\n this.additionalContentFields = input.additionalContentFields;\n if (this.validateTemplate) {\n let totalInputVariables = this.inputVariables;\n if (this.partialVariables) {\n totalInputVariables = totalInputVariables.concat(Object.keys(this.partialVariables));\n }\n checkValidTemplate([\n { type: \"image_url\", image_url: this.template },\n ], this.templateFormat, totalInputVariables);\n }\n }\n _getPromptType() {\n return \"prompt\";\n }\n /**\n * Partially applies values to the prompt template.\n * @param values The values to be partially applied to the prompt template.\n * @returns A new instance of ImagePromptTemplate with the partially applied values.\n */\n async partial(values) {\n const newInputVariables = this.inputVariables.filter((iv) => !(iv in values));\n const newPartialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n };\n const promptDict = {\n ...this,\n inputVariables: newInputVariables,\n partialVariables: newPartialVariables,\n };\n return new ImagePromptTemplate(promptDict);\n }\n /**\n * Formats the prompt template with the provided values.\n * @param values The values to be used to format the prompt template.\n * @returns A promise that resolves to a string which is the formatted prompt.\n */\n async format(values) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const formatted = {};\n for (const [key, value] of Object.entries(this.template)) {\n if (typeof value === \"string\") {\n formatted[key] = renderTemplate(value, this.templateFormat, values);\n }\n else {\n formatted[key] = value;\n }\n }\n const url = values.url || formatted.url;\n const detail = values.detail || formatted.detail;\n if (!url) {\n throw new Error(\"Must provide either an image URL.\");\n }\n if (typeof url !== \"string\") {\n throw new Error(\"url must be a string.\");\n }\n const output = { url };\n if (detail) {\n output.detail = detail;\n }\n return output;\n }\n /**\n * Formats the prompt given the input values and returns a formatted\n * prompt value.\n * @param values The input values to format the prompt.\n * @returns A Promise that resolves to a formatted prompt value.\n */\n async formatPromptValue(values) {\n const formattedPrompt = await this.format(values);\n return new ImagePromptValue(formattedPrompt);\n }\n}\n"],"mappings":";AAAA,SAASA,gBAAgB,QAAQ,qBAAqB;AACtD,SAASC,kBAAkB,QAAS,WAAW;AAC/C,SAASC,kBAAkB,EAAEC,cAAc,QAAS,eAAe;AACnE;AACA;AACA;AACA,OAAO,MAAMC,mBAAmB,SAASH,kBAAkB,CAAC;EACxD,OAAOI,OAAOA,CAAA,EAAG;IACb,OAAO,qBAAqB;EAChC;EACAC,WAAWA,CAACC,KAAK,EAAE;IAAA,IAAAC,qBAAA,EAAAC,qBAAA;IACf,KAAK,CAACF,KAAK,CAAC;IACZG,MAAM,CAACC,cAAc,CAAC,IAAI,EAAE,cAAc,EAAE;MACxCC,UAAU,EAAE,IAAI;MAChBC,YAAY,EAAE,IAAI;MAClBC,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