@langchain/core 1.0.0-alpha.3 → 1.0.0-alpha.4

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 (486) hide show
  1. package/README.md +3 -19
  2. package/dist/caches/base.cjs +2 -2
  3. package/dist/caches/base.cjs.map +1 -1
  4. package/dist/callbacks/base.d.ts.map +1 -1
  5. package/dist/document_loaders/langsmith.cjs +1 -1
  6. package/dist/document_loaders/langsmith.cjs.map +1 -1
  7. package/dist/document_loaders/langsmith.js +1 -1
  8. package/dist/document_loaders/langsmith.js.map +1 -1
  9. package/dist/embeddings.cjs.map +1 -1
  10. package/dist/embeddings.d.cts +6 -6
  11. package/dist/embeddings.d.cts.map +1 -1
  12. package/dist/embeddings.d.ts +6 -6
  13. package/dist/embeddings.d.ts.map +1 -1
  14. package/dist/embeddings.js.map +1 -1
  15. package/dist/errors/index.cjs.map +1 -1
  16. package/dist/errors/index.js.map +1 -1
  17. package/dist/indexing/base.cjs +2 -2
  18. package/dist/indexing/base.cjs.map +1 -1
  19. package/dist/indexing/base.d.cts +0 -3
  20. package/dist/indexing/base.d.cts.map +1 -1
  21. package/dist/indexing/base.d.ts +0 -3
  22. package/dist/indexing/base.d.ts.map +1 -1
  23. package/dist/indexing/base.js +2 -2
  24. package/dist/indexing/base.js.map +1 -1
  25. package/dist/language_models/base.cjs +1 -1
  26. package/dist/language_models/base.cjs.map +1 -1
  27. package/dist/language_models/base.d.cts +3 -3
  28. package/dist/language_models/base.d.cts.map +1 -1
  29. package/dist/language_models/base.d.ts +3 -3
  30. package/dist/language_models/base.d.ts.map +1 -1
  31. package/dist/language_models/base.js +1 -1
  32. package/dist/language_models/base.js.map +1 -1
  33. package/dist/language_models/chat_models.cjs.map +1 -1
  34. package/dist/language_models/chat_models.d.ts.map +1 -1
  35. package/dist/language_models/chat_models.js.map +1 -1
  36. package/dist/language_models/llms.cjs.map +1 -1
  37. package/dist/language_models/llms.js.map +1 -1
  38. package/dist/load/import_map.cjs +1 -5
  39. package/dist/load/import_map.cjs.map +1 -1
  40. package/dist/load/import_map.js +3 -7
  41. package/dist/load/import_map.js.map +1 -1
  42. package/dist/load/index.cjs.map +1 -1
  43. package/dist/load/index.js.map +1 -1
  44. package/dist/load/serializable.cjs.map +1 -1
  45. package/dist/load/serializable.d.cts +1 -3
  46. package/dist/load/serializable.d.cts.map +1 -1
  47. package/dist/load/serializable.d.ts +1 -3
  48. package/dist/load/serializable.d.ts.map +1 -1
  49. package/dist/load/serializable.js.map +1 -1
  50. package/dist/messages/ai.cjs +2 -2
  51. package/dist/messages/ai.cjs.map +1 -1
  52. package/dist/messages/ai.js +2 -2
  53. package/dist/messages/ai.js.map +1 -1
  54. package/dist/messages/base.cjs +5 -5
  55. package/dist/messages/base.cjs.map +1 -1
  56. package/dist/messages/base.d.cts +1 -2
  57. package/dist/messages/base.d.cts.map +1 -1
  58. package/dist/messages/base.d.ts +1 -2
  59. package/dist/messages/base.d.ts.map +1 -1
  60. package/dist/messages/base.js +5 -5
  61. package/dist/messages/base.js.map +1 -1
  62. package/dist/messages/block_translators/utils.cjs +1 -1
  63. package/dist/messages/block_translators/utils.cjs.map +1 -1
  64. package/dist/messages/block_translators/utils.js +1 -1
  65. package/dist/messages/block_translators/utils.js.map +1 -1
  66. package/dist/messages/index.cjs +1 -1
  67. package/dist/messages/index.js +1 -1
  68. package/dist/messages/modifier.cjs +4 -1
  69. package/dist/messages/modifier.cjs.map +1 -1
  70. package/dist/messages/modifier.js +4 -1
  71. package/dist/messages/modifier.js.map +1 -1
  72. package/dist/messages/tool.cjs +7 -7
  73. package/dist/messages/tool.cjs.map +1 -1
  74. package/dist/messages/tool.js +7 -7
  75. package/dist/messages/tool.js.map +1 -1
  76. package/dist/messages/transformers.cjs +2 -2
  77. package/dist/messages/transformers.cjs.map +1 -1
  78. package/dist/messages/transformers.js +2 -2
  79. package/dist/messages/transformers.js.map +1 -1
  80. package/dist/messages/utils.cjs +5 -0
  81. package/dist/messages/utils.cjs.map +1 -1
  82. package/dist/messages/utils.js +5 -0
  83. package/dist/messages/utils.js.map +1 -1
  84. package/dist/output_parsers/list.cjs +1 -1
  85. package/dist/output_parsers/list.cjs.map +1 -1
  86. package/dist/output_parsers/list.js +1 -1
  87. package/dist/output_parsers/list.js.map +1 -1
  88. package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.cts +1 -1
  89. package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts +1 -1
  90. package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs +1 -1
  91. package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs.map +1 -1
  92. package/dist/output_parsers/openai_tools/json_output_tools_parsers.js +1 -1
  93. package/dist/output_parsers/openai_tools/json_output_tools_parsers.js.map +1 -1
  94. package/dist/output_parsers/structured.cjs +2 -1
  95. package/dist/output_parsers/structured.cjs.map +1 -1
  96. package/dist/output_parsers/structured.js +2 -1
  97. package/dist/output_parsers/structured.js.map +1 -1
  98. package/dist/prompts/chat.cjs +3 -1
  99. package/dist/prompts/chat.cjs.map +1 -1
  100. package/dist/prompts/chat.d.cts +4 -12
  101. package/dist/prompts/chat.d.cts.map +1 -1
  102. package/dist/prompts/chat.d.ts +4 -12
  103. package/dist/prompts/chat.d.ts.map +1 -1
  104. package/dist/prompts/chat.js +3 -1
  105. package/dist/prompts/chat.js.map +1 -1
  106. package/dist/prompts/image.cjs.map +1 -1
  107. package/dist/prompts/image.d.cts +0 -2
  108. package/dist/prompts/image.d.cts.map +1 -1
  109. package/dist/prompts/image.d.ts +0 -2
  110. package/dist/prompts/image.d.ts.map +1 -1
  111. package/dist/prompts/image.js.map +1 -1
  112. package/dist/prompts/pipeline.cjs.map +1 -1
  113. package/dist/prompts/pipeline.js.map +1 -1
  114. package/dist/prompts/prompt.cjs.map +1 -1
  115. package/dist/prompts/prompt.d.cts +4 -16
  116. package/dist/prompts/prompt.d.cts.map +1 -1
  117. package/dist/prompts/prompt.d.ts +4 -16
  118. package/dist/prompts/prompt.d.ts.map +1 -1
  119. package/dist/prompts/prompt.js.map +1 -1
  120. package/dist/prompts/structured.cjs.map +1 -1
  121. package/dist/prompts/structured.js.map +1 -1
  122. package/dist/prompts/template.cjs +4 -2
  123. package/dist/prompts/template.cjs.map +1 -1
  124. package/dist/prompts/template.js +4 -2
  125. package/dist/prompts/template.js.map +1 -1
  126. package/dist/runnables/base.cjs +6 -6
  127. package/dist/runnables/base.cjs.map +1 -1
  128. package/dist/runnables/base.d.cts +0 -3
  129. package/dist/runnables/base.d.cts.map +1 -1
  130. package/dist/runnables/base.d.ts +0 -3
  131. package/dist/runnables/base.d.ts.map +1 -1
  132. package/dist/runnables/base.js +6 -6
  133. package/dist/runnables/base.js.map +1 -1
  134. package/dist/runnables/branch.cjs +2 -2
  135. package/dist/runnables/branch.cjs.map +1 -1
  136. package/dist/runnables/branch.js +2 -2
  137. package/dist/runnables/branch.js.map +1 -1
  138. package/dist/runnables/config.cjs.map +1 -1
  139. package/dist/runnables/config.js.map +1 -1
  140. package/dist/runnables/graph.cjs +1 -1
  141. package/dist/runnables/graph.cjs.map +1 -1
  142. package/dist/runnables/graph.js +1 -1
  143. package/dist/runnables/graph.js.map +1 -1
  144. package/dist/runnables/graph_mermaid.cjs +26 -3
  145. package/dist/runnables/graph_mermaid.cjs.map +1 -1
  146. package/dist/runnables/graph_mermaid.js +26 -3
  147. package/dist/runnables/graph_mermaid.js.map +1 -1
  148. package/dist/runnables/remote.cjs.map +1 -1
  149. package/dist/runnables/remote.js.map +1 -1
  150. package/dist/runnables/types.d.cts +0 -1
  151. package/dist/runnables/types.d.cts.map +1 -1
  152. package/dist/runnables/types.d.ts +0 -1
  153. package/dist/runnables/types.d.ts.map +1 -1
  154. package/dist/singletons/async_local_storage/context.cjs.map +1 -1
  155. package/dist/singletons/async_local_storage/context.d.cts +0 -1
  156. package/dist/singletons/async_local_storage/context.d.cts.map +1 -1
  157. package/dist/singletons/async_local_storage/context.d.ts +0 -1
  158. package/dist/singletons/async_local_storage/context.d.ts.map +1 -1
  159. package/dist/singletons/async_local_storage/context.js.map +1 -1
  160. package/dist/singletons/callbacks.cjs.map +1 -1
  161. package/dist/singletons/callbacks.js.map +1 -1
  162. package/dist/tools/index.cjs.map +1 -1
  163. package/dist/tools/index.d.cts +2 -2
  164. package/dist/tools/index.d.cts.map +1 -1
  165. package/dist/tools/index.d.ts +2 -2
  166. package/dist/tools/index.d.ts.map +1 -1
  167. package/dist/tools/index.js.map +1 -1
  168. package/dist/tools/types.d.cts +5 -5
  169. package/dist/tools/types.d.cts.map +1 -1
  170. package/dist/tools/types.d.ts +5 -5
  171. package/dist/tools/types.d.ts.map +1 -1
  172. package/dist/tracers/base.cjs.map +1 -1
  173. package/dist/tracers/base.js.map +1 -1
  174. package/dist/tracers/console.cjs +1 -1
  175. package/dist/tracers/console.cjs.map +1 -1
  176. package/dist/tracers/console.js +1 -1
  177. package/dist/tracers/console.js.map +1 -1
  178. package/dist/tracers/event_stream.cjs +1 -1
  179. package/dist/tracers/event_stream.cjs.map +1 -1
  180. package/dist/tracers/event_stream.d.cts +0 -1
  181. package/dist/tracers/event_stream.d.cts.map +1 -1
  182. package/dist/tracers/event_stream.d.ts +0 -1
  183. package/dist/tracers/event_stream.d.ts.map +1 -1
  184. package/dist/tracers/event_stream.js +1 -1
  185. package/dist/tracers/event_stream.js.map +1 -1
  186. package/dist/tracers/log_stream.cjs.map +1 -1
  187. package/dist/tracers/log_stream.js.map +1 -1
  188. package/dist/tracers/tracer_langchain.cjs.map +1 -1
  189. package/dist/tracers/tracer_langchain.js.map +1 -1
  190. package/dist/utils/chunk_array.cjs.map +1 -1
  191. package/dist/utils/chunk_array.js.map +1 -1
  192. package/dist/utils/env.cjs +1 -1
  193. package/dist/utils/env.cjs.map +1 -1
  194. package/dist/utils/env.js +1 -1
  195. package/dist/utils/env.js.map +1 -1
  196. package/dist/utils/event_source_parse.cjs.map +1 -1
  197. package/dist/utils/event_source_parse.d.cts.map +1 -1
  198. package/dist/utils/event_source_parse.d.ts.map +1 -1
  199. package/dist/utils/event_source_parse.js.map +1 -1
  200. package/dist/utils/hash.cjs +3 -8
  201. package/dist/utils/hash.cjs.map +1 -1
  202. package/dist/utils/hash.d.cts +1 -2
  203. package/dist/utils/hash.d.cts.map +1 -1
  204. package/dist/utils/hash.d.ts +1 -2
  205. package/dist/utils/hash.d.ts.map +1 -1
  206. package/dist/utils/hash.js +2 -6
  207. package/dist/utils/hash.js.map +1 -1
  208. package/dist/utils/js-sha256/hash.cjs +0 -9
  209. package/dist/utils/js-sha256/hash.cjs.map +1 -1
  210. package/dist/utils/js-sha256/hash.js +1 -5
  211. package/dist/utils/js-sha256/hash.js.map +1 -1
  212. package/dist/utils/json.cjs +2 -2
  213. package/dist/utils/json.cjs.map +1 -1
  214. package/dist/utils/json.js +2 -2
  215. package/dist/utils/json.js.map +1 -1
  216. package/dist/utils/json_schema.cjs +3 -2
  217. package/dist/utils/json_schema.cjs.map +1 -1
  218. package/dist/utils/json_schema.d.cts +8 -4
  219. package/dist/utils/json_schema.d.cts.map +1 -1
  220. package/dist/utils/json_schema.d.ts +8 -4
  221. package/dist/utils/json_schema.d.ts.map +1 -1
  222. package/dist/utils/json_schema.js +2 -1
  223. package/dist/utils/json_schema.js.map +1 -1
  224. package/dist/utils/stream.cjs.map +1 -1
  225. package/dist/utils/stream.js.map +1 -1
  226. package/dist/utils/testing/index.cjs.map +1 -1
  227. package/dist/utils/testing/index.d.cts +4 -9
  228. package/dist/utils/testing/index.d.cts.map +1 -1
  229. package/dist/utils/testing/index.d.ts +4 -9
  230. package/dist/utils/testing/index.d.ts.map +1 -1
  231. package/dist/utils/testing/index.js.map +1 -1
  232. package/dist/utils/zod-to-json-schema/Options.cjs +40 -0
  233. package/dist/utils/zod-to-json-schema/Options.cjs.map +1 -0
  234. package/dist/utils/zod-to-json-schema/Options.js +37 -0
  235. package/dist/utils/zod-to-json-schema/Options.js.map +1 -0
  236. package/dist/utils/zod-to-json-schema/Refs.cjs +30 -0
  237. package/dist/utils/zod-to-json-schema/Refs.cjs.map +1 -0
  238. package/dist/utils/zod-to-json-schema/Refs.js +30 -0
  239. package/dist/utils/zod-to-json-schema/Refs.js.map +1 -0
  240. package/dist/utils/zod-to-json-schema/errorMessages.cjs +18 -0
  241. package/dist/utils/zod-to-json-schema/errorMessages.cjs.map +1 -0
  242. package/dist/utils/zod-to-json-schema/errorMessages.d.cts +11 -0
  243. package/dist/utils/zod-to-json-schema/errorMessages.d.cts.map +1 -0
  244. package/dist/utils/zod-to-json-schema/errorMessages.d.ts +11 -0
  245. package/dist/utils/zod-to-json-schema/errorMessages.d.ts.map +1 -0
  246. package/dist/utils/zod-to-json-schema/errorMessages.js +16 -0
  247. package/dist/utils/zod-to-json-schema/errorMessages.js.map +1 -0
  248. package/dist/utils/zod-to-json-schema/getRelativePath.cjs +11 -0
  249. package/dist/utils/zod-to-json-schema/getRelativePath.cjs.map +1 -0
  250. package/dist/utils/zod-to-json-schema/getRelativePath.js +10 -0
  251. package/dist/utils/zod-to-json-schema/getRelativePath.js.map +1 -0
  252. package/dist/utils/zod-to-json-schema/index.cjs +37 -0
  253. package/dist/utils/zod-to-json-schema/index.js +37 -0
  254. package/dist/utils/zod-to-json-schema/parseDef.cjs +57 -0
  255. package/dist/utils/zod-to-json-schema/parseDef.cjs.map +1 -0
  256. package/dist/utils/zod-to-json-schema/parseDef.js +57 -0
  257. package/dist/utils/zod-to-json-schema/parseDef.js.map +1 -0
  258. package/dist/utils/zod-to-json-schema/parseTypes.d.cts +38 -0
  259. package/dist/utils/zod-to-json-schema/parseTypes.d.cts.map +1 -0
  260. package/dist/utils/zod-to-json-schema/parseTypes.d.ts +38 -0
  261. package/dist/utils/zod-to-json-schema/parseTypes.d.ts.map +1 -0
  262. package/dist/utils/zod-to-json-schema/parsers/any.cjs +17 -0
  263. package/dist/utils/zod-to-json-schema/parsers/any.cjs.map +1 -0
  264. package/dist/utils/zod-to-json-schema/parsers/any.d.cts +7 -0
  265. package/dist/utils/zod-to-json-schema/parsers/any.d.cts.map +1 -0
  266. package/dist/utils/zod-to-json-schema/parsers/any.d.ts +7 -0
  267. package/dist/utils/zod-to-json-schema/parsers/any.d.ts.map +1 -0
  268. package/dist/utils/zod-to-json-schema/parsers/any.js +17 -0
  269. package/dist/utils/zod-to-json-schema/parsers/any.js.map +1 -0
  270. package/dist/utils/zod-to-json-schema/parsers/array.cjs +24 -0
  271. package/dist/utils/zod-to-json-schema/parsers/array.cjs.map +1 -0
  272. package/dist/utils/zod-to-json-schema/parsers/array.d.cts +14 -0
  273. package/dist/utils/zod-to-json-schema/parsers/array.d.cts.map +1 -0
  274. package/dist/utils/zod-to-json-schema/parsers/array.d.ts +15 -0
  275. package/dist/utils/zod-to-json-schema/parsers/array.d.ts.map +1 -0
  276. package/dist/utils/zod-to-json-schema/parsers/array.js +23 -0
  277. package/dist/utils/zod-to-json-schema/parsers/array.js.map +1 -0
  278. package/dist/utils/zod-to-json-schema/parsers/bigint.cjs +36 -0
  279. package/dist/utils/zod-to-json-schema/parsers/bigint.cjs.map +1 -0
  280. package/dist/utils/zod-to-json-schema/parsers/bigint.d.cts +16 -0
  281. package/dist/utils/zod-to-json-schema/parsers/bigint.d.cts.map +1 -0
  282. package/dist/utils/zod-to-json-schema/parsers/bigint.d.ts +17 -0
  283. package/dist/utils/zod-to-json-schema/parsers/bigint.d.ts.map +1 -0
  284. package/dist/utils/zod-to-json-schema/parsers/bigint.js +36 -0
  285. package/dist/utils/zod-to-json-schema/parsers/bigint.js.map +1 -0
  286. package/dist/utils/zod-to-json-schema/parsers/boolean.cjs +9 -0
  287. package/dist/utils/zod-to-json-schema/parsers/boolean.cjs.map +1 -0
  288. package/dist/utils/zod-to-json-schema/parsers/boolean.d.cts +7 -0
  289. package/dist/utils/zod-to-json-schema/parsers/boolean.d.cts.map +1 -0
  290. package/dist/utils/zod-to-json-schema/parsers/boolean.d.ts +7 -0
  291. package/dist/utils/zod-to-json-schema/parsers/boolean.d.ts.map +1 -0
  292. package/dist/utils/zod-to-json-schema/parsers/boolean.js +8 -0
  293. package/dist/utils/zod-to-json-schema/parsers/boolean.js.map +1 -0
  294. package/dist/utils/zod-to-json-schema/parsers/branded.cjs +10 -0
  295. package/dist/utils/zod-to-json-schema/parsers/branded.cjs.map +1 -0
  296. package/dist/utils/zod-to-json-schema/parsers/branded.js +10 -0
  297. package/dist/utils/zod-to-json-schema/parsers/branded.js.map +1 -0
  298. package/dist/utils/zod-to-json-schema/parsers/catch.cjs +10 -0
  299. package/dist/utils/zod-to-json-schema/parsers/catch.cjs.map +1 -0
  300. package/dist/utils/zod-to-json-schema/parsers/catch.js +10 -0
  301. package/dist/utils/zod-to-json-schema/parsers/catch.js.map +1 -0
  302. package/dist/utils/zod-to-json-schema/parsers/date.cjs +39 -0
  303. package/dist/utils/zod-to-json-schema/parsers/date.cjs.map +1 -0
  304. package/dist/utils/zod-to-json-schema/parsers/date.d.cts +17 -0
  305. package/dist/utils/zod-to-json-schema/parsers/date.d.cts.map +1 -0
  306. package/dist/utils/zod-to-json-schema/parsers/date.d.ts +17 -0
  307. package/dist/utils/zod-to-json-schema/parsers/date.d.ts.map +1 -0
  308. package/dist/utils/zod-to-json-schema/parsers/date.js +39 -0
  309. package/dist/utils/zod-to-json-schema/parsers/date.js.map +1 -0
  310. package/dist/utils/zod-to-json-schema/parsers/default.cjs +13 -0
  311. package/dist/utils/zod-to-json-schema/parsers/default.cjs.map +1 -0
  312. package/dist/utils/zod-to-json-schema/parsers/default.js +13 -0
  313. package/dist/utils/zod-to-json-schema/parsers/default.js.map +1 -0
  314. package/dist/utils/zod-to-json-schema/parsers/effects.cjs +11 -0
  315. package/dist/utils/zod-to-json-schema/parsers/effects.cjs.map +1 -0
  316. package/dist/utils/zod-to-json-schema/parsers/effects.js +11 -0
  317. package/dist/utils/zod-to-json-schema/parsers/effects.js.map +1 -0
  318. package/dist/utils/zod-to-json-schema/parsers/enum.cjs +12 -0
  319. package/dist/utils/zod-to-json-schema/parsers/enum.cjs.map +1 -0
  320. package/dist/utils/zod-to-json-schema/parsers/enum.d.cts +8 -0
  321. package/dist/utils/zod-to-json-schema/parsers/enum.d.cts.map +1 -0
  322. package/dist/utils/zod-to-json-schema/parsers/enum.d.ts +10 -0
  323. package/dist/utils/zod-to-json-schema/parsers/enum.d.ts.map +1 -0
  324. package/dist/utils/zod-to-json-schema/parsers/enum.js +11 -0
  325. package/dist/utils/zod-to-json-schema/parsers/enum.js.map +1 -0
  326. package/dist/utils/zod-to-json-schema/parsers/intersection.cjs +47 -0
  327. package/dist/utils/zod-to-json-schema/parsers/intersection.cjs.map +1 -0
  328. package/dist/utils/zod-to-json-schema/parsers/intersection.d.cts +10 -0
  329. package/dist/utils/zod-to-json-schema/parsers/intersection.d.cts.map +1 -0
  330. package/dist/utils/zod-to-json-schema/parsers/intersection.d.ts +11 -0
  331. package/dist/utils/zod-to-json-schema/parsers/intersection.d.ts.map +1 -0
  332. package/dist/utils/zod-to-json-schema/parsers/intersection.js +47 -0
  333. package/dist/utils/zod-to-json-schema/parsers/intersection.js.map +1 -0
  334. package/dist/utils/zod-to-json-schema/parsers/literal.cjs +18 -0
  335. package/dist/utils/zod-to-json-schema/parsers/literal.cjs.map +1 -0
  336. package/dist/utils/zod-to-json-schema/parsers/literal.d.cts +11 -0
  337. package/dist/utils/zod-to-json-schema/parsers/literal.d.cts.map +1 -0
  338. package/dist/utils/zod-to-json-schema/parsers/literal.d.ts +12 -0
  339. package/dist/utils/zod-to-json-schema/parsers/literal.d.ts.map +1 -0
  340. package/dist/utils/zod-to-json-schema/parsers/literal.js +17 -0
  341. package/dist/utils/zod-to-json-schema/parsers/literal.js.map +1 -0
  342. package/dist/utils/zod-to-json-schema/parsers/map.cjs +40 -0
  343. package/dist/utils/zod-to-json-schema/parsers/map.cjs.map +1 -0
  344. package/dist/utils/zod-to-json-schema/parsers/map.d.cts +17 -0
  345. package/dist/utils/zod-to-json-schema/parsers/map.d.cts.map +1 -0
  346. package/dist/utils/zod-to-json-schema/parsers/map.d.ts +17 -0
  347. package/dist/utils/zod-to-json-schema/parsers/map.d.ts.map +1 -0
  348. package/dist/utils/zod-to-json-schema/parsers/map.js +40 -0
  349. package/dist/utils/zod-to-json-schema/parsers/map.js.map +1 -0
  350. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs +18 -0
  351. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs.map +1 -0
  352. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.cts +8 -0
  353. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.cts.map +1 -0
  354. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.ts +10 -0
  355. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.ts.map +1 -0
  356. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.js +17 -0
  357. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.js.map +1 -0
  358. package/dist/utils/zod-to-json-schema/parsers/never.cjs +13 -0
  359. package/dist/utils/zod-to-json-schema/parsers/never.cjs.map +1 -0
  360. package/dist/utils/zod-to-json-schema/parsers/never.d.cts +9 -0
  361. package/dist/utils/zod-to-json-schema/parsers/never.d.cts.map +1 -0
  362. package/dist/utils/zod-to-json-schema/parsers/never.d.ts +9 -0
  363. package/dist/utils/zod-to-json-schema/parsers/never.d.ts.map +1 -0
  364. package/dist/utils/zod-to-json-schema/parsers/never.js +13 -0
  365. package/dist/utils/zod-to-json-schema/parsers/never.js.map +1 -0
  366. package/dist/utils/zod-to-json-schema/parsers/null.cjs +12 -0
  367. package/dist/utils/zod-to-json-schema/parsers/null.cjs.map +1 -0
  368. package/dist/utils/zod-to-json-schema/parsers/null.d.cts +7 -0
  369. package/dist/utils/zod-to-json-schema/parsers/null.d.cts.map +1 -0
  370. package/dist/utils/zod-to-json-schema/parsers/null.d.ts +7 -0
  371. package/dist/utils/zod-to-json-schema/parsers/null.d.ts.map +1 -0
  372. package/dist/utils/zod-to-json-schema/parsers/null.js +11 -0
  373. package/dist/utils/zod-to-json-schema/parsers/null.js.map +1 -0
  374. package/dist/utils/zod-to-json-schema/parsers/nullable.cjs +46 -0
  375. package/dist/utils/zod-to-json-schema/parsers/nullable.cjs.map +1 -0
  376. package/dist/utils/zod-to-json-schema/parsers/nullable.d.cts +12 -0
  377. package/dist/utils/zod-to-json-schema/parsers/nullable.d.cts.map +1 -0
  378. package/dist/utils/zod-to-json-schema/parsers/nullable.d.ts +13 -0
  379. package/dist/utils/zod-to-json-schema/parsers/nullable.d.ts.map +1 -0
  380. package/dist/utils/zod-to-json-schema/parsers/nullable.js +46 -0
  381. package/dist/utils/zod-to-json-schema/parsers/nullable.js.map +1 -0
  382. package/dist/utils/zod-to-json-schema/parsers/number.cjs +37 -0
  383. package/dist/utils/zod-to-json-schema/parsers/number.cjs.map +1 -0
  384. package/dist/utils/zod-to-json-schema/parsers/number.d.cts +15 -0
  385. package/dist/utils/zod-to-json-schema/parsers/number.d.cts.map +1 -0
  386. package/dist/utils/zod-to-json-schema/parsers/number.d.ts +16 -0
  387. package/dist/utils/zod-to-json-schema/parsers/number.d.ts.map +1 -0
  388. package/dist/utils/zod-to-json-schema/parsers/number.js +37 -0
  389. package/dist/utils/zod-to-json-schema/parsers/number.js.map +1 -0
  390. package/dist/utils/zod-to-json-schema/parsers/object.cjs +64 -0
  391. package/dist/utils/zod-to-json-schema/parsers/object.cjs.map +1 -0
  392. package/dist/utils/zod-to-json-schema/parsers/object.d.cts +12 -0
  393. package/dist/utils/zod-to-json-schema/parsers/object.d.cts.map +1 -0
  394. package/dist/utils/zod-to-json-schema/parsers/object.d.ts +13 -0
  395. package/dist/utils/zod-to-json-schema/parsers/object.d.ts.map +1 -0
  396. package/dist/utils/zod-to-json-schema/parsers/object.js +64 -0
  397. package/dist/utils/zod-to-json-schema/parsers/object.js.map +1 -0
  398. package/dist/utils/zod-to-json-schema/parsers/optional.cjs +20 -0
  399. package/dist/utils/zod-to-json-schema/parsers/optional.cjs.map +1 -0
  400. package/dist/utils/zod-to-json-schema/parsers/optional.js +20 -0
  401. package/dist/utils/zod-to-json-schema/parsers/optional.js.map +1 -0
  402. package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs +28 -0
  403. package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs.map +1 -0
  404. package/dist/utils/zod-to-json-schema/parsers/pipeline.js +28 -0
  405. package/dist/utils/zod-to-json-schema/parsers/pipeline.js.map +1 -0
  406. package/dist/utils/zod-to-json-schema/parsers/promise.cjs +10 -0
  407. package/dist/utils/zod-to-json-schema/parsers/promise.cjs.map +1 -0
  408. package/dist/utils/zod-to-json-schema/parsers/promise.js +10 -0
  409. package/dist/utils/zod-to-json-schema/parsers/promise.js.map +1 -0
  410. package/dist/utils/zod-to-json-schema/parsers/readonly.cjs +10 -0
  411. package/dist/utils/zod-to-json-schema/parsers/readonly.cjs.map +1 -0
  412. package/dist/utils/zod-to-json-schema/parsers/readonly.js +10 -0
  413. package/dist/utils/zod-to-json-schema/parsers/readonly.js.map +1 -0
  414. package/dist/utils/zod-to-json-schema/parsers/record.cjs +57 -0
  415. package/dist/utils/zod-to-json-schema/parsers/record.cjs.map +1 -0
  416. package/dist/utils/zod-to-json-schema/parsers/record.d.cts +14 -0
  417. package/dist/utils/zod-to-json-schema/parsers/record.d.cts.map +1 -0
  418. package/dist/utils/zod-to-json-schema/parsers/record.d.ts +15 -0
  419. package/dist/utils/zod-to-json-schema/parsers/record.d.ts.map +1 -0
  420. package/dist/utils/zod-to-json-schema/parsers/record.js +56 -0
  421. package/dist/utils/zod-to-json-schema/parsers/record.js.map +1 -0
  422. package/dist/utils/zod-to-json-schema/parsers/set.cjs +22 -0
  423. package/dist/utils/zod-to-json-schema/parsers/set.cjs.map +1 -0
  424. package/dist/utils/zod-to-json-schema/parsers/set.d.cts +15 -0
  425. package/dist/utils/zod-to-json-schema/parsers/set.d.cts.map +1 -0
  426. package/dist/utils/zod-to-json-schema/parsers/set.d.ts +16 -0
  427. package/dist/utils/zod-to-json-schema/parsers/set.d.ts.map +1 -0
  428. package/dist/utils/zod-to-json-schema/parsers/set.js +22 -0
  429. package/dist/utils/zod-to-json-schema/parsers/set.js.map +1 -0
  430. package/dist/utils/zod-to-json-schema/parsers/string.cjs +255 -0
  431. package/dist/utils/zod-to-json-schema/parsers/string.cjs.map +1 -0
  432. package/dist/utils/zod-to-json-schema/parsers/string.d.cts +28 -0
  433. package/dist/utils/zod-to-json-schema/parsers/string.d.cts.map +1 -0
  434. package/dist/utils/zod-to-json-schema/parsers/string.d.ts +29 -0
  435. package/dist/utils/zod-to-json-schema/parsers/string.d.ts.map +1 -0
  436. package/dist/utils/zod-to-json-schema/parsers/string.js +254 -0
  437. package/dist/utils/zod-to-json-schema/parsers/string.js.map +1 -0
  438. package/dist/utils/zod-to-json-schema/parsers/tuple.cjs +38 -0
  439. package/dist/utils/zod-to-json-schema/parsers/tuple.cjs.map +1 -0
  440. package/dist/utils/zod-to-json-schema/parsers/tuple.d.cts +15 -0
  441. package/dist/utils/zod-to-json-schema/parsers/tuple.d.cts.map +1 -0
  442. package/dist/utils/zod-to-json-schema/parsers/tuple.d.ts +16 -0
  443. package/dist/utils/zod-to-json-schema/parsers/tuple.d.ts.map +1 -0
  444. package/dist/utils/zod-to-json-schema/parsers/tuple.js +38 -0
  445. package/dist/utils/zod-to-json-schema/parsers/tuple.js.map +1 -0
  446. package/dist/utils/zod-to-json-schema/parsers/undefined.cjs +10 -0
  447. package/dist/utils/zod-to-json-schema/parsers/undefined.cjs.map +1 -0
  448. package/dist/utils/zod-to-json-schema/parsers/undefined.d.cts +9 -0
  449. package/dist/utils/zod-to-json-schema/parsers/undefined.d.cts.map +1 -0
  450. package/dist/utils/zod-to-json-schema/parsers/undefined.d.ts +9 -0
  451. package/dist/utils/zod-to-json-schema/parsers/undefined.d.ts.map +1 -0
  452. package/dist/utils/zod-to-json-schema/parsers/undefined.js +10 -0
  453. package/dist/utils/zod-to-json-schema/parsers/undefined.js.map +1 -0
  454. package/dist/utils/zod-to-json-schema/parsers/union.cjs +67 -0
  455. package/dist/utils/zod-to-json-schema/parsers/union.cjs.map +1 -0
  456. package/dist/utils/zod-to-json-schema/parsers/union.d.cts +24 -0
  457. package/dist/utils/zod-to-json-schema/parsers/union.d.cts.map +1 -0
  458. package/dist/utils/zod-to-json-schema/parsers/union.d.ts +25 -0
  459. package/dist/utils/zod-to-json-schema/parsers/union.d.ts.map +1 -0
  460. package/dist/utils/zod-to-json-schema/parsers/union.js +66 -0
  461. package/dist/utils/zod-to-json-schema/parsers/union.js.map +1 -0
  462. package/dist/utils/zod-to-json-schema/parsers/unknown.cjs +10 -0
  463. package/dist/utils/zod-to-json-schema/parsers/unknown.cjs.map +1 -0
  464. package/dist/utils/zod-to-json-schema/parsers/unknown.d.cts +7 -0
  465. package/dist/utils/zod-to-json-schema/parsers/unknown.d.cts.map +1 -0
  466. package/dist/utils/zod-to-json-schema/parsers/unknown.d.ts +7 -0
  467. package/dist/utils/zod-to-json-schema/parsers/unknown.d.ts.map +1 -0
  468. package/dist/utils/zod-to-json-schema/parsers/unknown.js +10 -0
  469. package/dist/utils/zod-to-json-schema/parsers/unknown.js.map +1 -0
  470. package/dist/utils/zod-to-json-schema/selectParser.cjs +81 -0
  471. package/dist/utils/zod-to-json-schema/selectParser.cjs.map +1 -0
  472. package/dist/utils/zod-to-json-schema/selectParser.js +80 -0
  473. package/dist/utils/zod-to-json-schema/selectParser.js.map +1 -0
  474. package/dist/utils/zod-to-json-schema/zodToJsonSchema.cjs +70 -0
  475. package/dist/utils/zod-to-json-schema/zodToJsonSchema.cjs.map +1 -0
  476. package/dist/utils/zod-to-json-schema/zodToJsonSchema.js +70 -0
  477. package/dist/utils/zod-to-json-schema/zodToJsonSchema.js.map +1 -0
  478. package/package.json +7 -36
  479. package/dist/utils/js-sha1/hash.cjs +0 -291
  480. package/dist/utils/js-sha1/hash.cjs.map +0 -1
  481. package/dist/utils/js-sha1/hash.d.cts +0 -9
  482. package/dist/utils/js-sha1/hash.d.cts.map +0 -1
  483. package/dist/utils/js-sha1/hash.d.ts +0 -9
  484. package/dist/utils/js-sha1/hash.d.ts.map +0 -1
  485. package/dist/utils/js-sha1/hash.js +0 -284
  486. package/dist/utils/js-sha1/hash.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"image.js","names":["input: ImagePromptTemplateInput<RunInput, PartialVariableName>","totalInputVariables: string[]","values: PartialValues<NewPartialVariableName>","values: TypedPromptInputValues<RunInput>","formatted: Record<string, any>","output: ImageContent"],"sources":["../../src/prompts/image.ts"],"sourcesContent":["import { MessageContent, ContentBlock } from \"../messages/index.js\";\nimport { ImagePromptValue, ImageContent } from \"../prompt_values.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport {\n BasePromptTemplate,\n BasePromptTemplateInput,\n TypedPromptInputValues,\n} from \"./base.js\";\nimport {\n TemplateFormat,\n checkValidTemplate,\n renderTemplate,\n} from \"./template.js\";\n\n/**\n * Inputs to create a {@link ImagePromptTemplate}\n * @augments BasePromptTemplateInput\n */\nexport interface ImagePromptTemplateInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n> extends BasePromptTemplateInput<RunInput, PartialVariableName> {\n /**\n * The prompt template\n */\n template: Record<string, unknown>;\n\n /**\n * The format of the prompt template. Options are 'f-string'\n *\n * @defaultValue 'f-string'\n */\n templateFormat?: TemplateFormat;\n\n /**\n * Whether or not to try validating the template on initialization\n *\n * @defaultValue `true`\n */\n validateTemplate?: boolean;\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 additionalContentFields?: ContentBlock;\n}\n\n/**\n * An image prompt template for a multimodal model.\n */\nexport class ImagePromptTemplate<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n> extends BasePromptTemplate<RunInput, ImagePromptValue, PartialVariableName> {\n static lc_name() {\n return \"ImagePromptTemplate\";\n }\n\n lc_namespace = [\"langchain_core\", \"prompts\", \"image\"];\n\n template: Record<string, unknown>;\n\n templateFormat: TemplateFormat = \"f-string\";\n\n validateTemplate = 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 additionalContentFields?: ContentBlock;\n\n constructor(input: ImagePromptTemplateInput<RunInput, PartialVariableName>) {\n super(input);\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\n if (this.validateTemplate) {\n let totalInputVariables: string[] = this.inputVariables;\n if (this.partialVariables) {\n totalInputVariables = totalInputVariables.concat(\n Object.keys(this.partialVariables)\n );\n }\n checkValidTemplate(\n [\n { type: \"image_url\", image_url: this.template },\n ] as unknown as MessageContent,\n this.templateFormat,\n totalInputVariables\n );\n }\n }\n\n _getPromptType(): \"prompt\" {\n return \"prompt\";\n }\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<NewPartialVariableName extends string>(\n values: PartialValues<NewPartialVariableName>\n ) {\n const newInputVariables = this.inputVariables.filter(\n (iv) => !(iv in values)\n ) as Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>[];\n const newPartialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n } as PartialValues<PartialVariableName | NewPartialVariableName>;\n const promptDict = {\n ...this,\n inputVariables: newInputVariables,\n partialVariables: newPartialVariables,\n };\n return new ImagePromptTemplate<\n InputValues<\n Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>\n >\n >(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 async format<FormatOutput = ImageContent>(\n values: TypedPromptInputValues<RunInput>\n ): Promise<FormatOutput> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const formatted: Record<string, any> = {};\n for (const [key, value] of Object.entries(this.template)) {\n if (typeof value === \"string\") {\n formatted[key] = renderTemplate(value, this.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: ImageContent = { url };\n if (detail) {\n output.detail = detail;\n }\n return output as FormatOutput;\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 async formatPromptValue(\n values: TypedPromptInputValues<RunInput>\n ): Promise<ImagePromptValue> {\n const formattedPrompt = await this.format(values);\n return new ImagePromptValue(formattedPrompt);\n }\n}\n"],"mappings":";;;;;;;;AAuDA,IAAa,sBAAb,MAAa,4BAKH,mBAAoE;CAC5E,OAAO,UAAU;AACf,SAAO;CACR;CAED,eAAe;EAAC;EAAkB;EAAW;CAAQ;CAErD;CAEA,iBAAiC;CAEjC,mBAAmB;;;;;;CAQnB;CAEA,YAAYA,OAAgE;EAC1E,MAAM,MAAM;EACZ,KAAK,WAAW,MAAM;EACtB,KAAK,iBAAiB,MAAM,kBAAkB,KAAK;EACnD,KAAK,mBAAmB,MAAM,oBAAoB,KAAK;EACvD,KAAK,0BAA0B,MAAM;AAErC,MAAI,KAAK,kBAAkB;GACzB,IAAIC,sBAAgC,KAAK;AACzC,OAAI,KAAK,kBACP,sBAAsB,oBAAoB,OACxC,OAAO,KAAK,KAAK,iBAAiB,CACnC;GAEH,mBACE,CACE;IAAE,MAAM;IAAa,WAAW,KAAK;GAAU,CAChD,GACD,KAAK,gBACL,oBACD;EACF;CACF;CAED,iBAA2B;AACzB,SAAO;CACR;;;;;;CAOD,MAAM,QACJC,QACA;EACA,MAAM,oBAAoB,KAAK,eAAe,OAC5C,CAAC,OAAO,EAAE,MAAM,QACjB;EACD,MAAM,sBAAsB;GAC1B,GAAI,KAAK,oBAAoB,CAAE;GAC/B,GAAG;EACJ;EACD,MAAM,aAAa;GACjB,GAAG;GACH,gBAAgB;GAChB,kBAAkB;EACnB;AACD,SAAO,IAAI,oBAIT;CACH;;;;;;CAOD,MAAM,OACJC,QACuB;EAEvB,MAAMC,YAAiC,CAAE;AACzC,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,KAAK,SAAS,CACtD,KAAI,OAAO,UAAU,UACnB,UAAU,OAAO,eAAe,OAAO,KAAK,gBAAgB,OAAO;OAEnE,UAAU,OAAO;EAGrB,MAAM,MAAM,OAAO,OAAO,UAAU;EACpC,MAAM,SAAS,OAAO,UAAU,UAAU;AAC1C,MAAI,CAAC,IACH,OAAM,IAAI,MAAM;AAElB,MAAI,OAAO,QAAQ,SACjB,OAAM,IAAI,MAAM;EAElB,MAAMC,SAAuB,EAAE,IAAK;AACpC,MAAI,QACF,OAAO,SAAS;AAElB,SAAO;CACR;;;;;;;CAQD,MAAM,kBACJF,QAC2B;EAC3B,MAAM,kBAAkB,MAAM,KAAK,OAAO,OAAO;AACjD,SAAO,IAAI,iBAAiB;CAC7B;AACF"}
1
+ {"version":3,"file":"image.js","names":["input: ImagePromptTemplateInput<RunInput, PartialVariableName>","totalInputVariables: string[]","values: PartialValues<NewPartialVariableName>","values: TypedPromptInputValues<RunInput>","formatted: Record<string, any>","output: ImageContent"],"sources":["../../src/prompts/image.ts"],"sourcesContent":["import { MessageContent, ContentBlock } from \"../messages/index.js\";\nimport { ImagePromptValue, ImageContent } from \"../prompt_values.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport {\n BasePromptTemplate,\n BasePromptTemplateInput,\n TypedPromptInputValues,\n} from \"./base.js\";\nimport {\n TemplateFormat,\n checkValidTemplate,\n renderTemplate,\n} from \"./template.js\";\n\n/**\n * Inputs to create a {@link ImagePromptTemplate}\n * @augments BasePromptTemplateInput\n */\nexport interface ImagePromptTemplateInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n> extends BasePromptTemplateInput<RunInput, PartialVariableName> {\n /**\n * The prompt template\n */\n template: Record<string, unknown>;\n\n /**\n * The format of the prompt template. Options are 'f-string'\n *\n * @defaultValue 'f-string'\n */\n templateFormat?: TemplateFormat;\n\n /**\n * Whether or not to try validating the template on initialization\n *\n * @defaultValue `true`\n */\n validateTemplate?: boolean;\n\n /**\n * Additional fields which should be included inside\n * the message content array if using a complex message\n * content.\n */\n additionalContentFields?: ContentBlock;\n}\n\n/**\n * An image prompt template for a multimodal model.\n */\nexport class ImagePromptTemplate<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n> extends BasePromptTemplate<RunInput, ImagePromptValue, PartialVariableName> {\n static lc_name() {\n return \"ImagePromptTemplate\";\n }\n\n lc_namespace = [\"langchain_core\", \"prompts\", \"image\"];\n\n template: Record<string, unknown>;\n\n templateFormat: TemplateFormat = \"f-string\";\n\n validateTemplate = 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 additionalContentFields?: ContentBlock;\n\n constructor(input: ImagePromptTemplateInput<RunInput, PartialVariableName>) {\n super(input);\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\n if (this.validateTemplate) {\n let totalInputVariables: string[] = this.inputVariables;\n if (this.partialVariables) {\n totalInputVariables = totalInputVariables.concat(\n Object.keys(this.partialVariables)\n );\n }\n checkValidTemplate(\n [\n { type: \"image_url\", image_url: this.template },\n ] as unknown as MessageContent,\n this.templateFormat,\n totalInputVariables\n );\n }\n }\n\n _getPromptType(): \"prompt\" {\n return \"prompt\";\n }\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<NewPartialVariableName extends string>(\n values: PartialValues<NewPartialVariableName>\n ) {\n const newInputVariables = this.inputVariables.filter(\n (iv) => !(iv in values)\n ) as Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>[];\n const newPartialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n } as PartialValues<PartialVariableName | NewPartialVariableName>;\n const promptDict = {\n ...this,\n inputVariables: newInputVariables,\n partialVariables: newPartialVariables,\n };\n return new ImagePromptTemplate<\n InputValues<\n Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>\n >\n >(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 async format<FormatOutput = ImageContent>(\n values: TypedPromptInputValues<RunInput>\n ): Promise<FormatOutput> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const formatted: Record<string, any> = {};\n for (const [key, value] of Object.entries(this.template)) {\n if (typeof value === \"string\") {\n formatted[key] = renderTemplate(value, this.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: ImageContent = { url };\n if (detail) {\n output.detail = detail;\n }\n return output as FormatOutput;\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 async formatPromptValue(\n values: TypedPromptInputValues<RunInput>\n ): Promise<ImagePromptValue> {\n const formattedPrompt = await this.format(values);\n return new ImagePromptValue(form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I,OAAO,QAAQ,SACjB,OAAM,IAAI,MAAM;EAElB,MAAMC,SAAuB,EAAE,IAAK;AACpC,MAAI,QACF,OAAO,SAAS;AAElB,SAAO;CACR;;;;;;;CAQD,MAAM,kBACJF,QAC2B;EAC3B,MAAM,kBAAkB,MAAM,KAAK,OAAO,OAAO;AACjD,SAAO,IAAI,iBAAiB;CAC7B;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"pipeline.cjs","names":["BasePromptTemplate","input: PipelinePromptTemplateInput<PromptTemplateType>","allValues: InputValues","requiredValueNames: string[]","values: InputValues","ChatPromptTemplate","values: PartialValues"],"sources":["../../src/prompts/pipeline.ts"],"sourcesContent":["import type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport type { SerializedBasePromptTemplate } from \"./serde.js\";\nimport { BasePromptTemplate, type BasePromptTemplateInput } from \"./base.js\";\nimport { ChatPromptTemplate } from \"./chat.js\";\n\n/**\n * Type that includes the name of the prompt and the prompt itself.\n */\nexport type PipelinePromptParams<\n PromptTemplateType extends BasePromptTemplate\n> = {\n name: string;\n prompt: PromptTemplateType;\n};\n\n/**\n * Type that extends the BasePromptTemplateInput type, excluding the\n * inputVariables property. It includes an array of pipelinePrompts and a\n * finalPrompt.\n */\nexport type PipelinePromptTemplateInput<\n PromptTemplateType extends BasePromptTemplate\n> = Omit<BasePromptTemplateInput, \"inputVariables\"> & {\n pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];\n finalPrompt: PromptTemplateType;\n};\n\n/**\n * Class that handles a sequence of prompts, each of which may require\n * different input variables. Includes methods for formatting these\n * prompts, extracting required input values, and handling partial\n * prompts.\n * @example\n * ```typescript\n * const composedPrompt = new PipelinePromptTemplate({\n * pipelinePrompts: [\n * {\n * name: \"introduction\",\n * prompt: PromptTemplate.fromTemplate(`You are impersonating {person}.`),\n * },\n * {\n * name: \"example\",\n * prompt: PromptTemplate.fromTemplate(\n * `Here's an example of an interaction:\n * Q: {example_q}\n * A: {example_a}`,\n * ),\n * },\n * {\n * name: \"start\",\n * prompt: PromptTemplate.fromTemplate(\n * `Now, do this for real!\n * Q: {input}\n * A:`,\n * ),\n * },\n * ],\n * finalPrompt: PromptTemplate.fromTemplate(\n * `{introduction}\n * {example}\n * {start}`,\n * ),\n * });\n *\n * const formattedPrompt = await composedPrompt.format({\n * person: \"Elon Musk\",\n * example_q: `What's your favorite car?`,\n * example_a: \"Tesla\",\n * input: `What's your favorite social media site?`,\n * });\n * ```\n */\nexport class PipelinePromptTemplate<\n PromptTemplateType extends BasePromptTemplate\n> extends BasePromptTemplate {\n static lc_name() {\n return \"PipelinePromptTemplate\";\n }\n\n pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];\n\n finalPrompt: PromptTemplateType;\n\n constructor(input: PipelinePromptTemplateInput<PromptTemplateType>) {\n super({ ...input, inputVariables: [] });\n this.pipelinePrompts = input.pipelinePrompts;\n this.finalPrompt = input.finalPrompt;\n this.inputVariables = this.computeInputValues();\n }\n\n /**\n * Computes the input values required by the pipeline prompts.\n * @returns Array of input values required by the pipeline prompts.\n */\n protected computeInputValues() {\n const intermediateValues = this.pipelinePrompts.map(\n (pipelinePrompt) => pipelinePrompt.name\n );\n const inputValues = this.pipelinePrompts\n .map((pipelinePrompt) =>\n pipelinePrompt.prompt.inputVariables.filter(\n (inputValue) => !intermediateValues.includes(inputValue)\n )\n )\n .flat();\n return [...new Set(inputValues)];\n }\n\n protected static extractRequiredInputValues(\n allValues: InputValues,\n requiredValueNames: string[]\n ) {\n return requiredValueNames.reduce((requiredValues, valueName) => {\n // eslint-disable-next-line no-param-reassign\n requiredValues[valueName] = allValues[valueName];\n return requiredValues;\n }, {} as InputValues);\n }\n\n /**\n * Formats the pipeline prompts based on the provided input values.\n * @param values Input values to format the pipeline prompts.\n * @returns Promise that resolves with the formatted input values.\n */\n protected async formatPipelinePrompts(\n values: InputValues\n ): Promise<InputValues> {\n const allValues = await this.mergePartialAndUserVariables(values);\n for (const { name: pipelinePromptName, prompt: pipelinePrompt } of this\n .pipelinePrompts) {\n const pipelinePromptInputValues =\n PipelinePromptTemplate.extractRequiredInputValues(\n allValues,\n pipelinePrompt.inputVariables\n );\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (pipelinePrompt instanceof ChatPromptTemplate) {\n allValues[pipelinePromptName] = await pipelinePrompt.formatMessages(\n pipelinePromptInputValues\n );\n } else {\n allValues[pipelinePromptName] = await pipelinePrompt.format(\n pipelinePromptInputValues\n );\n }\n }\n return PipelinePromptTemplate.extractRequiredInputValues(\n allValues,\n this.finalPrompt.inputVariables\n );\n }\n\n /**\n * Formats the final prompt value based on the provided input values.\n * @param values Input values to format the final prompt value.\n * @returns Promise that resolves with the formatted final prompt value.\n */\n async formatPromptValue(\n values: InputValues\n ): Promise<PromptTemplateType[\"PromptValueReturnType\"]> {\n return this.finalPrompt.formatPromptValue(\n await this.formatPipelinePrompts(values)\n );\n }\n\n async format(values: InputValues): Promise<string> {\n return this.finalPrompt.format(await this.formatPipelinePrompts(values));\n }\n\n /**\n * Handles partial prompts, which are prompts that have been partially\n * filled with input values.\n * @param values Partial input values.\n * @returns Promise that resolves with a new PipelinePromptTemplate instance with updated input variables.\n */\n async partial(\n values: PartialValues\n ): Promise<PipelinePromptTemplate<PromptTemplateType>> {\n const promptDict = { ...this };\n promptDict.inputVariables = this.inputVariables.filter(\n (iv) => !(iv in values)\n );\n promptDict.partialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n };\n return new PipelinePromptTemplate<PromptTemplateType>(promptDict);\n }\n\n serialize(): SerializedBasePromptTemplate {\n throw new Error(\"Not implemented.\");\n }\n\n _getPromptType(): string {\n return \"pipeline\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,IAAa,yBAAb,MAAa,+BAEHA,gCAAmB;CAC3B,OAAO,UAAU;AACf,SAAO;CACR;CAED;CAEA;CAEA,YAAYC,OAAwD;EAClE,MAAM;GAAE,GAAG;GAAO,g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AE,MAAM,QACjB;EACD,WAAW,mBAAmB;GAC5B,GAAI,KAAK,oBAAoB,CAAE;GAC/B,GAAG;EACJ;AACD,SAAO,IAAI,uBAA2C;CACvD;CAED,YAA0C;AACxC,QAAM,IAAI,MAAM;CACjB;CAED,iBAAyB;AACvB,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"pipeline.cjs","names":["BasePromptTemplate","input: PipelinePromptTemplateInput<PromptTemplateType>","allValues: InputValues","requiredValueNames: string[]","values: InputValues","ChatPromptTemplate","values: PartialValues"],"sources":["../../src/prompts/pipeline.ts"],"sourcesContent":["import type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport type { SerializedBasePromptTemplate } from \"./serde.js\";\nimport { BasePromptTemplate, type BasePromptTemplateInput } from \"./base.js\";\nimport { ChatPromptTemplate } from \"./chat.js\";\n\n/**\n * Type that includes the name of the prompt and the prompt itself.\n */\nexport type PipelinePromptParams<\n PromptTemplateType extends BasePromptTemplate\n> = {\n name: string;\n prompt: PromptTemplateType;\n};\n\n/**\n * Type that extends the BasePromptTemplateInput type, excluding the\n * inputVariables property. It includes an array of pipelinePrompts and a\n * finalPrompt.\n */\nexport type PipelinePromptTemplateInput<\n PromptTemplateType extends BasePromptTemplate\n> = Omit<BasePromptTemplateInput, \"inputVariables\"> & {\n pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];\n finalPrompt: PromptTemplateType;\n};\n\n/**\n * Class that handles a sequence of prompts, each of which may require\n * different input variables. Includes methods for formatting these\n * prompts, extracting required input values, and handling partial\n * prompts.\n * @example\n * ```typescript\n * const composedPrompt = new PipelinePromptTemplate({\n * pipelinePrompts: [\n * {\n * name: \"introduction\",\n * prompt: PromptTemplate.fromTemplate(`You are impersonating {person}.`),\n * },\n * {\n * name: \"example\",\n * prompt: PromptTemplate.fromTemplate(\n * `Here's an example of an interaction:\n * Q: {example_q}\n * A: {example_a}`,\n * ),\n * },\n * {\n * name: \"start\",\n * prompt: PromptTemplate.fromTemplate(\n * `Now, do this for real!\n * Q: {input}\n * A:`,\n * ),\n * },\n * ],\n * finalPrompt: PromptTemplate.fromTemplate(\n * `{introduction}\n * {example}\n * {start}`,\n * ),\n * });\n *\n * const formattedPrompt = await composedPrompt.format({\n * person: \"Elon Musk\",\n * example_q: `What's your favorite car?`,\n * example_a: \"Tesla\",\n * input: `What's your favorite social media site?`,\n * });\n * ```\n */\nexport class PipelinePromptTemplate<\n PromptTemplateType extends BasePromptTemplate\n> extends BasePromptTemplate {\n static lc_name() {\n return \"PipelinePromptTemplate\";\n }\n\n pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];\n\n finalPrompt: PromptTemplateType;\n\n constructor(input: PipelinePromptTemplateInput<PromptTemplateType>) {\n super({ ...input, inputVariables: [] });\n this.pipelinePrompts = input.pipelinePrompts;\n this.finalPrompt = input.finalPrompt;\n this.inputVariables = this.computeInputValues();\n }\n\n /**\n * Computes the input values required by the pipeline prompts.\n * @returns Array of input values required by the pipeline prompts.\n */\n protected computeInputValues() {\n const intermediateValues = this.pipelinePrompts.map(\n (pipelinePrompt) => pipelinePrompt.name\n );\n const inputValues = this.pipelinePrompts\n .map((pipelinePrompt) =>\n pipelinePrompt.prompt.inputVariables.filter(\n (inputValue) => !intermediateValues.includes(inputValue)\n )\n )\n .flat();\n return [...new Set(inputValues)];\n }\n\n protected static extractRequiredInputValues(\n allValues: InputValues,\n requiredValueNames: string[]\n ) {\n return requiredValueNames.reduce((requiredValues, valueName) => {\n requiredValues[valueName] = allValues[valueName];\n return requiredValues;\n }, {} as InputValues);\n }\n\n /**\n * Formats the pipeline prompts based on the provided input values.\n * @param values Input values to format the pipeline prompts.\n * @returns Promise that resolves with the formatted input values.\n */\n protected async formatPipelinePrompts(\n values: InputValues\n ): Promise<InputValues> {\n const allValues = await this.mergePartialAndUserVariables(values);\n for (const { name: pipelinePromptName, prompt: pipelinePrompt } of this\n .pipelinePrompts) {\n const pipelinePromptInputValues =\n PipelinePromptTemplate.extractRequiredInputValues(\n allValues,\n pipelinePrompt.inputVariables\n );\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (pipelinePrompt instanceof ChatPromptTemplate) {\n allValues[pipelinePromptName] = await pipelinePrompt.formatMessages(\n pipelinePromptInputValues\n );\n } else {\n allValues[pipelinePromptName] = await pipelinePrompt.format(\n pipelinePromptInputValues\n );\n }\n }\n return PipelinePromptTemplate.extractRequiredInputValues(\n allValues,\n this.finalPrompt.inputVariables\n );\n }\n\n /**\n * Formats the final prompt value based on the provided input values.\n * @param values Input values to format the final prompt value.\n * @returns Promise that resolves with the formatted final prompt value.\n */\n async formatPromptValue(\n values: InputValues\n ): Promise<PromptTemplateType[\"PromptValueReturnType\"]> {\n return this.finalPrompt.formatPromptValue(\n await this.formatPipelinePrompts(values)\n );\n }\n\n async format(values: InputValues): Promise<string> {\n return this.finalPrompt.format(await this.formatPipelinePrompts(values));\n }\n\n /**\n * Handles partial prompts, which are prompts that have been partially\n * filled with input values.\n * @param values Partial input values.\n * @returns Promise that resolves with a new PipelinePromptTemplate instance with updated input variables.\n */\n async partial(\n values: PartialValues\n ): Promise<PipelinePromptTemplate<PromptTemplateType>> {\n const promptDict = { ...this };\n promptDict.inputVariables = this.inputVariables.filter(\n (iv) => !(iv in values)\n );\n promptDict.partialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n };\n return new PipelinePromptTemplate<PromptTemplateType>(promptDict);\n }\n\n serialize(): SerializedBasePromptTemplate {\n throw new Error(\"Not implemented.\");\n }\n\n _getPromptType(): string {\n return \"pipeline\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,IAAa,yBAAb,MAAa,+BAEHA,gCAAmB;CAC3B,OAAO,UAAU;AACf,SAAO;CACR;CAED;CAEA;CAEA,YAAYC,OAAwD;EAClE,MAAM;GAAE,GAAG;GAAO,gBAAgB,CAAE;EAAE,EAAC;EACvC,KAAK,kBAAkB,MAAM;EAC7B,KAAK,cAAc,MAAM;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AAG;EACJ;AACD,SAAO,IAAI,uBAA2C;CACvD;CAED,YAA0C;AACxC,QAAM,IAAI,MAAM;CACjB;CAED,iBAAyB;AACvB,SAAO;CACR;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"pipeline.js","names":["input: PipelinePromptTemplateInput<PromptTemplateType>","allValues: InputValues","requiredValueNames: string[]","values: InputValues","values: PartialValues"],"sources":["../../src/prompts/pipeline.ts"],"sourcesContent":["import type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport type { SerializedBasePromptTemplate } from \"./serde.js\";\nimport { BasePromptTemplate, type BasePromptTemplateInput } from \"./base.js\";\nimport { ChatPromptTemplate } from \"./chat.js\";\n\n/**\n * Type that includes the name of the prompt and the prompt itself.\n */\nexport type PipelinePromptParams<\n PromptTemplateType extends BasePromptTemplate\n> = {\n name: string;\n prompt: PromptTemplateType;\n};\n\n/**\n * Type that extends the BasePromptTemplateInput type, excluding the\n * inputVariables property. It includes an array of pipelinePrompts and a\n * finalPrompt.\n */\nexport type PipelinePromptTemplateInput<\n PromptTemplateType extends BasePromptTemplate\n> = Omit<BasePromptTemplateInput, \"inputVariables\"> & {\n pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];\n finalPrompt: PromptTemplateType;\n};\n\n/**\n * Class that handles a sequence of prompts, each of which may require\n * different input variables. Includes methods for formatting these\n * prompts, extracting required input values, and handling partial\n * prompts.\n * @example\n * ```typescript\n * const composedPrompt = new PipelinePromptTemplate({\n * pipelinePrompts: [\n * {\n * name: \"introduction\",\n * prompt: PromptTemplate.fromTemplate(`You are impersonating {person}.`),\n * },\n * {\n * name: \"example\",\n * prompt: PromptTemplate.fromTemplate(\n * `Here's an example of an interaction:\n * Q: {example_q}\n * A: {example_a}`,\n * ),\n * },\n * {\n * name: \"start\",\n * prompt: PromptTemplate.fromTemplate(\n * `Now, do this for real!\n * Q: {input}\n * A:`,\n * ),\n * },\n * ],\n * finalPrompt: PromptTemplate.fromTemplate(\n * `{introduction}\n * {example}\n * {start}`,\n * ),\n * });\n *\n * const formattedPrompt = await composedPrompt.format({\n * person: \"Elon Musk\",\n * example_q: `What's your favorite car?`,\n * example_a: \"Tesla\",\n * input: `What's your favorite social media site?`,\n * });\n * ```\n */\nexport class PipelinePromptTemplate<\n PromptTemplateType extends BasePromptTemplate\n> extends BasePromptTemplate {\n static lc_name() {\n return \"PipelinePromptTemplate\";\n }\n\n pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];\n\n finalPrompt: PromptTemplateType;\n\n constructor(input: PipelinePromptTemplateInput<PromptTemplateType>) {\n super({ ...input, inputVariables: [] });\n this.pipelinePrompts = input.pipelinePrompts;\n this.finalPrompt = input.finalPrompt;\n this.inputVariables = this.computeInputValues();\n }\n\n /**\n * Computes the input values required by the pipeline prompts.\n * @returns Array of input values required by the pipeline prompts.\n */\n protected computeInputValues() {\n const intermediateValues = this.pipelinePrompts.map(\n (pipelinePrompt) => pipelinePrompt.name\n );\n const inputValues = this.pipelinePrompts\n .map((pipelinePrompt) =>\n pipelinePrompt.prompt.inputVariables.filter(\n (inputValue) => !intermediateValues.includes(inputValue)\n )\n )\n .flat();\n return [...new Set(inputValues)];\n }\n\n protected static extractRequiredInputValues(\n allValues: InputValues,\n requiredValueNames: string[]\n ) {\n return requiredValueNames.reduce((requiredValues, valueName) => {\n // eslint-disable-next-line no-param-reassign\n requiredValues[valueName] = allValues[valueName];\n return requiredValues;\n }, {} as InputValues);\n }\n\n /**\n * Formats the pipeline prompts based on the provided input values.\n * @param values Input values to format the pipeline prompts.\n * @returns Promise that resolves with the formatted input values.\n */\n protected async formatPipelinePrompts(\n values: InputValues\n ): Promise<InputValues> {\n const allValues = await this.mergePartialAndUserVariables(values);\n for (const { name: pipelinePromptName, prompt: pipelinePrompt } of this\n .pipelinePrompts) {\n const pipelinePromptInputValues =\n PipelinePromptTemplate.extractRequiredInputValues(\n allValues,\n pipelinePrompt.inputVariables\n );\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (pipelinePrompt instanceof ChatPromptTemplate) {\n allValues[pipelinePromptName] = await pipelinePrompt.formatMessages(\n pipelinePromptInputValues\n );\n } else {\n allValues[pipelinePromptName] = await pipelinePrompt.format(\n pipelinePromptInputValues\n );\n }\n }\n return PipelinePromptTemplate.extractRequiredInputValues(\n allValues,\n this.finalPrompt.inputVariables\n );\n }\n\n /**\n * Formats the final prompt value based on the provided input values.\n * @param values Input values to format the final prompt value.\n * @returns Promise that resolves with the formatted final prompt value.\n */\n async formatPromptValue(\n values: InputValues\n ): Promise<PromptTemplateType[\"PromptValueReturnType\"]> {\n return this.finalPrompt.formatPromptValue(\n await this.formatPipelinePrompts(values)\n );\n }\n\n async format(values: InputValues): Promise<string> {\n return this.finalPrompt.format(await this.formatPipelinePrompts(values));\n }\n\n /**\n * Handles partial prompts, which are prompts that have been partially\n * filled with input values.\n * @param values Partial input values.\n * @returns Promise that resolves with a new PipelinePromptTemplate instance with updated input variables.\n */\n async partial(\n values: PartialValues\n ): Promise<PipelinePromptTemplate<PromptTemplateType>> {\n const promptDict = { ...this };\n promptDict.inputVariables = this.inputVariables.filter(\n (iv) => !(iv in values)\n );\n promptDict.partialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n };\n return new PipelinePromptTemplate<PromptTemplateType>(promptDict);\n }\n\n serialize(): SerializedBasePromptTemplate {\n throw new Error(\"Not implemented.\");\n }\n\n _getPromptType(): string {\n return \"pipeline\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,IAAa,yBAAb,MAAa,+BAEH,mBAAmB;CAC3B,OAAO,UAAU;AACf,SAAO;CACR;CAED;CAEA;CAEA,YAAYA,OAAwD;EAClE,MAAM;GAAE,GAAG;GAAO,gBAAgB,CAAE;EAAE,EAAC;EACvC,KAAK,kBAAkB,MAAM;EAC7B,KAAK,cAAc,MAAM;EACzB,KAAK,iBAAiB,KAAK,oBAAoB;CAChD;;;;;CAMD,AAAU,qBAAqB;EA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I,MAAM;CACjB;CAED,iBAAyB;AACvB,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"pipeline.js","names":["input: PipelinePromptTemplateInput<PromptTemplateType>","allValues: InputValues","requiredValueNames: string[]","values: InputValues","values: PartialValues"],"sources":["../../src/prompts/pipeline.ts"],"sourcesContent":["import type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport type { SerializedBasePromptTemplate } from \"./serde.js\";\nimport { BasePromptTemplate, type BasePromptTemplateInput } from \"./base.js\";\nimport { ChatPromptTemplate } from \"./chat.js\";\n\n/**\n * Type that includes the name of the prompt and the prompt itself.\n */\nexport type PipelinePromptParams<\n PromptTemplateType extends BasePromptTemplate\n> = {\n name: string;\n prompt: PromptTemplateType;\n};\n\n/**\n * Type that extends the BasePromptTemplateInput type, excluding the\n * inputVariables property. It includes an array of pipelinePrompts and a\n * finalPrompt.\n */\nexport type PipelinePromptTemplateInput<\n PromptTemplateType extends BasePromptTemplate\n> = Omit<BasePromptTemplateInput, \"inputVariables\"> & {\n pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];\n finalPrompt: PromptTemplateType;\n};\n\n/**\n * Class that handles a sequence of prompts, each of which may require\n * different input variables. Includes methods for formatting these\n * prompts, extracting required input values, and handling partial\n * prompts.\n * @example\n * ```typescript\n * const composedPrompt = new PipelinePromptTemplate({\n * pipelinePrompts: [\n * {\n * name: \"introduction\",\n * prompt: PromptTemplate.fromTemplate(`You are impersonating {person}.`),\n * },\n * {\n * name: \"example\",\n * prompt: PromptTemplate.fromTemplate(\n * `Here's an example of an interaction:\n * Q: {example_q}\n * A: {example_a}`,\n * ),\n * },\n * {\n * name: \"start\",\n * prompt: PromptTemplate.fromTemplate(\n * `Now, do this for real!\n * Q: {input}\n * A:`,\n * ),\n * },\n * ],\n * finalPrompt: PromptTemplate.fromTemplate(\n * `{introduction}\n * {example}\n * {start}`,\n * ),\n * });\n *\n * const formattedPrompt = await composedPrompt.format({\n * person: \"Elon Musk\",\n * example_q: `What's your favorite car?`,\n * example_a: \"Tesla\",\n * input: `What's your favorite social media site?`,\n * });\n * ```\n */\nexport class PipelinePromptTemplate<\n PromptTemplateType extends BasePromptTemplate\n> extends BasePromptTemplate {\n static lc_name() {\n return \"PipelinePromptTemplate\";\n }\n\n pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];\n\n finalPrompt: PromptTemplateType;\n\n constructor(input: PipelinePromptTemplateInput<PromptTemplateType>) {\n super({ ...input, inputVariables: [] });\n this.pipelinePrompts = input.pipelinePrompts;\n this.finalPrompt = input.finalPrompt;\n this.inputVariables = this.computeInputValues();\n }\n\n /**\n * Computes the input values required by the pipeline prompts.\n * @returns Array of input values required by the pipeline prompts.\n */\n protected computeInputValues() {\n const intermediateValues = this.pipelinePrompts.map(\n (pipelinePrompt) => pipelinePrompt.name\n );\n const inputValues = this.pipelinePrompts\n .map((pipelinePrompt) =>\n pipelinePrompt.prompt.inputVariables.filter(\n (inputValue) => !intermediateValues.includes(inputValue)\n )\n )\n .flat();\n return [...new Set(inputValues)];\n }\n\n protected static extractRequiredInputValues(\n allValues: InputValues,\n requiredValueNames: string[]\n ) {\n return requiredValueNames.reduce((requiredValues, valueName) => {\n requiredValues[valueName] = allValues[valueName];\n return requiredValues;\n }, {} as InputValues);\n }\n\n /**\n * Formats the pipeline prompts based on the provided input values.\n * @param values Input values to format the pipeline prompts.\n * @returns Promise that resolves with the formatted input values.\n */\n protected async formatPipelinePrompts(\n values: InputValues\n ): Promise<InputValues> {\n const allValues = await this.mergePartialAndUserVariables(values);\n for (const { name: pipelinePromptName, prompt: pipelinePrompt } of this\n .pipelinePrompts) {\n const pipelinePromptInputValues =\n PipelinePromptTemplate.extractRequiredInputValues(\n allValues,\n pipelinePrompt.inputVariables\n );\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (pipelinePrompt instanceof ChatPromptTemplate) {\n allValues[pipelinePromptName] = await pipelinePrompt.formatMessages(\n pipelinePromptInputValues\n );\n } else {\n allValues[pipelinePromptName] = await pipelinePrompt.format(\n pipelinePromptInputValues\n );\n }\n }\n return PipelinePromptTemplate.extractRequiredInputValues(\n allValues,\n this.finalPrompt.inputVariables\n );\n }\n\n /**\n * Formats the final prompt value based on the provided input values.\n * @param values Input values to format the final prompt value.\n * @returns Promise that resolves with the formatted final prompt value.\n */\n async formatPromptValue(\n values: InputValues\n ): Promise<PromptTemplateType[\"PromptValueReturnType\"]> {\n return this.finalPrompt.formatPromptValue(\n await this.formatPipelinePrompts(values)\n );\n }\n\n async format(values: InputValues): Promise<string> {\n return this.finalPrompt.format(await this.formatPipelinePrompts(values));\n }\n\n /**\n * Handles partial prompts, which are prompts that have been partially\n * filled with input values.\n * @param values Partial input values.\n * @returns Promise that resolves with a new PipelinePromptTemplate instance with updated input variables.\n */\n async partial(\n values: PartialValues\n ): Promise<PipelinePromptTemplate<PromptTemplateType>> {\n const promptDict = { ...this };\n promptDict.inputVariables = this.inputVariables.filter(\n (iv) => !(iv in values)\n );\n promptDict.partialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n };\n return new PipelinePromptTemplate<PromptTemplateType>(promptDict);\n }\n\n serialize(): SerializedBasePromptTemplate {\n throw new Error(\"Not implemented.\");\n }\n\n _getPromptType(): string {\n return \"pipeline\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,IAAa,yBAAb,MAAa,+BAEH,mBAAmB;CAC3B,OAAO,UAAU;AACf,SAAO;CACR;CAED;CAEA;CAEA,YAAYA,OAAwD;EAClE,MAAM;GAAE,GAAG;GAAO,gBAAgB,CAAE;EAAE,EAAC;EACvC,KAAK,kBAAkB,MAAM;EAC7B,KAAK,cAAc,MAAM;EACzB,KAAK,iBAAiB,KAAK,oBAAoB;CAChD;;;;;CAMD,AAAU,qBAAqB;EAC7B,MAAM,qBAAqB,KAAK,gBAAgB,IAC9C,CAAC,mBAAmB,eAAe,KACpC;EACD,MAAM,cAAc,KAAK,gBACtB,IAAI,CAA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plate","input: PromptTemplateInput<RunInput, PartialVariableName>","totalInputVariables: string[]","checkValidTemplate","values: TypedPromptInputValues<RunInput>","renderTemplate","examples: string[]","suffix: string","inputVariables: string[]","template: T","options?: Omit<\n PromptTemplateInput<RunInput, string, TemplateFormat>,\n \"template\" | \"inputVariables\"\n >","parseTemplate","values: PartialValues<NewPartialVariableName>","data: SerializedPromptTemplate"],"sources":["../../src/prompts/prompt.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\n\nimport { BaseStringPromptTemplate } from \"./string.js\";\nimport type {\n BasePromptTemplateInput,\n TypedPromptInputValues,\n} from \"./base.js\";\nimport {\n checkValidTemplate,\n parseTemplate,\n renderTemplate,\n type TemplateFormat,\n} from \"./template.js\";\nimport type { SerializedPromptTemplate } from \"./serde.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport { MessageContent, ContentBlock } from \"../messages/index.js\";\n\n/**\n * Inputs to create a {@link PromptTemplate}\n * @augments BasePromptTemplateInput\n */\nexport interface PromptTemplateInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any,\n Format extends TemplateFormat = TemplateFormat\n> extends BasePromptTemplateInput<RunInput, PartialVariableName> {\n /**\n * The prompt template\n */\n template: MessageContent;\n\n /**\n * The format of the prompt template. Options are \"f-string\" and \"mustache\"\n */\n templateFormat?: Format;\n\n /**\n * Whether or not to try validating the template on initialization\n *\n * @defaultValue `true`\n */\n validateTemplate?: boolean;\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 additionalContentFields?: ContentBlock;\n}\n\ntype NonAlphanumeric =\n | \" \"\n | \"\\t\"\n | \"\\n\"\n | \"\\r\"\n | '\"'\n | \"'\"\n | \"{\"\n | \"[\"\n | \"(\"\n | \"`\"\n | \":\"\n | \";\";\n\n/**\n * Recursive type to extract template parameters from a string.\n * @template T - The input string.\n * @template Result - The resulting array of extracted template parameters.\n */\ntype ExtractTemplateParamsRecursive<\n T extends string,\n Result extends string[] = []\n> = T extends `${string}{${infer Param}}${infer Rest}`\n ? Param extends `${NonAlphanumeric}${string}`\n ? ExtractTemplateParamsRecursive<Rest, Result> // for non-template variables that look like template variables e.g. see https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/chains/query_constructor/prompt.ts\n : ExtractTemplateParamsRecursive<Rest, [...Result, Param]>\n : Result;\n\nexport type ParamsFromFString<T extends string> = {\n [Key in\n | ExtractTemplateParamsRecursive<T>[number]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | (string & Record<never, never>)]: any;\n};\n\nexport type ExtractedFStringParams<\n T extends string,\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol\n // eslint-disable-next-line @typescript-eslint/ban-types\n> = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;\n\n/**\n * Schema to represent a basic prompt for an LLM.\n * @augments BasePromptTemplate\n * @augments PromptTemplateInput\n *\n * @example\n * ```ts\n * import { PromptTemplate } from \"langchain/prompts\";\n *\n * const prompt = new PromptTemplate({\n * inputVariables: [\"foo\"],\n * template: \"Say {foo}\",\n * });\n * ```\n */\nexport class PromptTemplate<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n >\n extends BaseStringPromptTemplate<RunInput, PartialVariableName>\n implements PromptTemplateInput<RunInput, PartialVariableName>\n{\n static lc_name() {\n return \"PromptTemplate\";\n }\n\n template: MessageContent;\n\n templateFormat: TemplateFormat = \"f-string\";\n\n validateTemplate = 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 additionalContentFields?: ContentBlock;\n\n constructor(input: PromptTemplateInput<RunInput, PartialVariableName>) {\n super(input);\n // If input is mustache and validateTemplate is not defined, set it to false\n if (\n input.templateFormat === \"mustache\" &&\n input.validateTemplate === undefined\n ) {\n this.validateTemplate = false;\n }\n Object.assign(this, input);\n\n if (this.validateTemplate) {\n if (this.templateFormat === \"mustache\") {\n throw new Error(\"Mustache templates cannot be validated.\");\n }\n let totalInputVariables: string[] = this.inputVariables;\n if (this.partialVariables) {\n totalInputVariables = totalInputVariables.concat(\n Object.keys(this.partialVariables)\n );\n }\n checkValidTemplate(\n this.template,\n this.templateFormat,\n totalInputVariables\n );\n }\n }\n\n _getPromptType(): \"prompt\" {\n return \"prompt\";\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 async format(values: TypedPromptInputValues<RunInput>): Promise<string> {\n const allValues = await this.mergePartialAndUserVariables(values);\n return renderTemplate(\n this.template as string,\n this.templateFormat,\n allValues\n );\n }\n\n /**\n * Take examples in list format with prefix and suffix to create a prompt.\n *\n * Intended to be used a a way to dynamically create a prompt from examples.\n *\n * @param examples - List of examples to use in the prompt.\n * @param suffix - String to go after the list of examples. Should generally set up the user's input.\n * @param inputVariables - A list of variable names the final prompt template will expect\n * @param exampleSeparator - The separator to use in between examples\n * @param prefix - String that should go before any examples. Generally includes examples.\n *\n * @returns The final prompt template generated.\n */\n static fromExamples(\n examples: string[],\n suffix: string,\n inputVariables: string[],\n exampleSeparator = \"\\n\\n\",\n prefix = \"\"\n ) {\n const template = [prefix, ...examples, suffix].join(exampleSeparator);\n return new PromptTemplate({\n inputVariables,\n template,\n });\n }\n\n /**\n * Load prompt template from a template f-string\n */\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string, \"f-string\">,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string>,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string, \"mustache\">,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<InputValues>;\n\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string, TemplateFormat>,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<ExtractedFStringParams<T, RunInput> | InputValues> {\n const { templateFormat = \"f-string\", ...rest } = options ?? {};\n const names = new Set<string>();\n parseTemplate(template, templateFormat).forEach((node) => {\n if (node.type === \"variable\") {\n names.add(node.name);\n }\n });\n\n return new PromptTemplate({\n // Rely on extracted types\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n inputVariables: [...names] as any[],\n templateFormat,\n template,\n ...rest,\n });\n }\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 PromptTemplate with the partially applied values.\n */\n async partial<NewPartialVariableName extends string>(\n values: PartialValues<NewPartialVariableName>\n ) {\n const newInputVariables = this.inputVariables.filter(\n (iv) => !(iv in values)\n ) as Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>[];\n const newPartialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n } as PartialValues<PartialVariableName | NewPartialVariableName>;\n const promptDict = {\n ...this,\n inputVariables: newInputVariables,\n partialVariables: newPartialVariables,\n };\n return new PromptTemplate<\n InputValues<\n Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>\n >\n >(promptDict);\n }\n\n serialize(): SerializedPromptTemplate {\n if (this.outputParser !== undefined) {\n throw new Error(\n \"Cannot serialize a prompt template with an output parser\"\n );\n }\n return {\n _type: this._getPromptType(),\n input_variables: this.inputVariables,\n template: this.template,\n template_format: this.templateFormat,\n };\n }\n\n static async deserialize(\n data: SerializedPromptTemplate\n ): Promise<PromptTemplate> {\n if (!data.template) {\n throw new Error(\"Prompt template must have a template\");\n }\n const res = new PromptTemplate({\n inputVariables: data.input_variables,\n template: data.template,\n templateFormat: data.template_format,\n });\n return res;\n }\n\n // TODO(from file)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgHA,IAAa,iBAAb,MAAa,uBAMHA,wCAEV;CACE,OAAO,UAAU;AACf,SAAO;CACR;CAED;CAEA,iBAAiC;CAEjC,mBAAmB;;;;;;CAQnB;CAEA,YAAYC,OAA2D;EACrE,MAAM,MAAM;AAEZ,MACE,MAAM,mBAAmB,cACzB,MAAM,qBAAqB,QAE3B,KAAK,mBAAmB;EAE1B,OAAO,OAAO,MAAM,MAAM;AAE1B,MAAI,KAAK,kBAAkB;AACzB,OAAI,KAAK,mBAAmB,WAC1B,OAAM,IAAI,MAAM;GAElB,IAAIC,sBAAgC,KAAK;AACzC,OAAI,KAAK,kBACP,sBAAsB,oBAAoB,OACxC,OAAO,KAAK,KAAK,iBAAiB,CACnC;GAEHC,oCACE,KAAK,UACL,KAAK,gBACL,oBACD;EACF;CACF;CAED,iBAA2B;AACzB,SAAO;CACR;;;;;;CAOD,MAAM,OAAOC,QAA2D;EACtE,MAAM,YAAY,MAAM,KAAK,6BAA6B,OAAO;AACjE,SAAOC,gCACL,KAAK,UACL,KAAK,gBACL,UACD;CACF;;;;;;;;;;;;;;CAeD,OAAO,aACLC,UACAC,QACAC,gBACA,mBAAmB,QACnB,SAAS,IACT;EACA,MAAM,WAAW;GAAC;GAAQ,GAAG;GAAU;EAAO,EAAC,KAAK,iBAAiB;AACrE,SAAO,IAAI,eAAe;GACxB;GACA;EACD;CACF;CAyCD,OAAO,aAKLC,UACAC,SAImE;EACnE,MAAM,EAAE,iBAAiB,WAAY,GAAG,MAAM,GAAG,WAAW,CAAE;EAC9D,MAAM,wBAAQ,IAAI;EAClBC,+BAAc,UAAU,eAAe,CAAC,QAAQ,CAAC,SAAS;AACxD,OAAI,KAAK,SAAS,YAChB,MAAM,IAAI,KAAK,KAAK;EAEvB,EAAC;AAEF,SAAO,IAAI,eAAe;GAGxB,gBAAgB,CAAC,GAAG,KAAM;GAC1B;GACA;GACA,GAAG;EACJ;CACF;;;;;;CAOD,MAAM,QACJC,QACA;EACA,MAAM,oBAAoB,KAAK,eAAe,OAC5C,CAAC,OAAO,EAAE,MAAM,QACjB;EACD,MAAM,sBAAsB;GAC1B,GAAI,KAAK,oBAAoB,CAAE;GAC/B,GAAG;EACJ;EACD,MAAM,aAAa;GACjB,GAAG;GACH,gBAAgB;GAChB,kBAAkB;EACnB;AACD,SAAO,IAAI,eAIT;CACH;CAED,YAAsC;AACpC,MAAI,KAAK,iBAAiB,OACxB,OAAM,IAAI,MACR;AAGJ,SAAO;GACL,OAAO,KAAK,gBAAgB;GAC5B,iBAAiB,KAAK;GACtB,UAAU,KAAK;GACf,iBAAiB,KAAK;EACvB;CACF;CAED,aAAa,YACXC,MACyB;AACzB,MAAI,CAAC,KAAK,SACR,OAAM,IAAI,MAAM;EAElB,MAAM,MAAM,IAAI,eAAe;GAC7B,gBAAgB,KAAK;GACrB,UAAU,KAAK;GACf,gBAAgB,KAAK;EACtB;AACD,SAAO;CACR;AAGF"}
1
+ {"version":3,"file":"prompt.cjs","names":["BaseStringPromptTemplate","input: PromptTemplateInput<RunInput, PartialVariableName>","totalInputVariables: string[]","checkValidTemplate","values: TypedPromptInputValues<RunInput>","renderTemplate","examples: string[]","suffix: string","inputVariables: string[]","template: T","options?: Omit<\n PromptTemplateInput<RunInput, string, TemplateFormat>,\n \"template\" | \"inputVariables\"\n >","parseTemplate","values: PartialValues<NewPartialVariableName>","data: SerializedPromptTemplate"],"sources":["../../src/prompts/prompt.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\n\nimport { BaseStringPromptTemplate } from \"./string.js\";\nimport type {\n BasePromptTemplateInput,\n TypedPromptInputValues,\n} from \"./base.js\";\nimport {\n checkValidTemplate,\n parseTemplate,\n renderTemplate,\n type TemplateFormat,\n} from \"./template.js\";\nimport type { SerializedPromptTemplate } from \"./serde.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport { MessageContent, ContentBlock } from \"../messages/index.js\";\n\n/**\n * Inputs to create a {@link PromptTemplate}\n * @augments BasePromptTemplateInput\n */\nexport interface PromptTemplateInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any,\n Format extends TemplateFormat = TemplateFormat\n> extends BasePromptTemplateInput<RunInput, PartialVariableName> {\n /**\n * The prompt template\n */\n template: MessageContent;\n\n /**\n * The format of the prompt template. Options are \"f-string\" and \"mustache\"\n */\n templateFormat?: Format;\n\n /**\n * Whether or not to try validating the template on initialization\n *\n * @defaultValue `true`\n */\n validateTemplate?: boolean;\n\n /**\n * Additional fields which should be included inside\n * the message content array if using a complex message\n * content.\n */\n additionalContentFields?: ContentBlock;\n}\n\ntype NonAlphanumeric =\n | \" \"\n | \"\\t\"\n | \"\\n\"\n | \"\\r\"\n | '\"'\n | \"'\"\n | \"{\"\n | \"[\"\n | \"(\"\n | \"`\"\n | \":\"\n | \";\";\n\n/**\n * Recursive type to extract template parameters from a string.\n * @template T - The input string.\n * @template Result - The resulting array of extracted template parameters.\n */\ntype ExtractTemplateParamsRecursive<\n T extends string,\n Result extends string[] = []\n> = T extends `${string}{${infer Param}}${infer Rest}`\n ? Param extends `${NonAlphanumeric}${string}`\n ? ExtractTemplateParamsRecursive<Rest, Result> // for non-template variables that look like template variables e.g. see https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/chains/query_constructor/prompt.ts\n : ExtractTemplateParamsRecursive<Rest, [...Result, Param]>\n : Result;\n\nexport type ParamsFromFString<T extends string> = {\n [Key in\n | ExtractTemplateParamsRecursive<T>[number]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | (string & Record<never, never>)]: any;\n};\n\nexport type ExtractedFStringParams<\n T extends string,\n RunInput extends InputValues = Symbol\n> = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;\n\n/**\n * Schema to represent a basic prompt for an LLM.\n * @augments BasePromptTemplate\n * @augments PromptTemplateInput\n *\n * @example\n * ```ts\n * import { PromptTemplate } from \"langchain/prompts\";\n *\n * const prompt = new PromptTemplate({\n * inputVariables: [\"foo\"],\n * template: \"Say {foo}\",\n * });\n * ```\n */\nexport class PromptTemplate<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n >\n extends BaseStringPromptTemplate<RunInput, PartialVariableName>\n implements PromptTemplateInput<RunInput, PartialVariableName>\n{\n static lc_name() {\n return \"PromptTemplate\";\n }\n\n template: MessageContent;\n\n templateFormat: TemplateFormat = \"f-string\";\n\n validateTemplate = 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 additionalContentFields?: ContentBlock;\n\n constructor(input: PromptTemplateInput<RunInput, PartialVariableName>) {\n super(input);\n // If input is mustache and validateTemplate is not defined, set it to false\n if (\n input.templateFormat === \"mustache\" &&\n input.validateTemplate === undefined\n ) {\n this.validateTemplate = false;\n }\n Object.assign(this, input);\n\n if (this.validateTemplate) {\n if (this.templateFormat === \"mustache\") {\n throw new Error(\"Mustache templates cannot be validated.\");\n }\n let totalInputVariables: string[] = this.inputVariables;\n if (this.partialVariables) {\n totalInputVariables = totalInputVariables.concat(\n Object.keys(this.partialVariables)\n );\n }\n checkValidTemplate(\n this.template,\n this.templateFormat,\n totalInputVariables\n );\n }\n }\n\n _getPromptType(): \"prompt\" {\n return \"prompt\";\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 async format(values: TypedPromptInputValues<RunInput>): Promise<string> {\n const allValues = await this.mergePartialAndUserVariables(values);\n return renderTemplate(\n this.template as string,\n this.templateFormat,\n allValues\n );\n }\n\n /**\n * Take examples in list format with prefix and suffix to create a prompt.\n *\n * Intended to be used a a way to dynamically create a prompt from examples.\n *\n * @param examples - List of examples to use in the prompt.\n * @param suffix - String to go after the list of examples. Should generally set up the user's input.\n * @param inputVariables - A list of variable names the final prompt template will expect\n * @param exampleSeparator - The separator to use in between examples\n * @param prefix - String that should go before any examples. Generally includes examples.\n *\n * @returns The final prompt template generated.\n */\n static fromExamples(\n examples: string[],\n suffix: string,\n inputVariables: string[],\n exampleSeparator = \"\\n\\n\",\n prefix = \"\"\n ) {\n const template = [prefix, ...examples, suffix].join(exampleSeparator);\n return new PromptTemplate({\n inputVariables,\n template,\n });\n }\n\n /**\n * Load prompt template from a template f-string\n */\n static fromTemplate<\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string, \"f-string\">,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n\n static fromTemplate<\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string>,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n\n static fromTemplate<\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string, \"mustache\">,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<InputValues>;\n\n static fromTemplate<\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string, TemplateFormat>,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<ExtractedFStringParams<T, RunInput> | InputValues> {\n const { templateFormat = \"f-string\", ...rest } = options ?? {};\n const names = new Set<string>();\n parseTemplate(template, templateFormat).forEach((node) => {\n if (node.type === \"variable\") {\n names.add(node.name);\n }\n });\n\n return new PromptTemplate({\n // Rely on extracted types\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n inputVariables: [...names] as any[],\n templateFormat,\n template,\n ...rest,\n });\n }\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 PromptTemplate with the partially applied values.\n */\n async partial<NewPartialVariableName extends string>(\n values: PartialValues<NewPartialVariableName>\n ) {\n const newInputVariables = this.inputVariables.filter(\n (iv) => !(iv in values)\n ) as Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>[];\n const newPartialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n } as PartialValues<PartialVariableName | NewPartialVariableName>;\n const promptDict = {\n ...this,\n inputVariables: newInputVariables,\n partialVariables: newPartialVariables,\n };\n return new PromptTemplate<\n InputValues<\n Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>\n >\n >(promptDict);\n }\n\n serialize(): SerializedPromptTemplate {\n if (this.outputParser !== undefined) {\n throw new Error(\n \"Cannot serialize a prompt template with an output parser\"\n );\n }\n return {\n _type: this._getPromptType(),\n input_variables: this.inputVariables,\n template: this.template,\n template_format: this.templateFormat,\n };\n }\n\n static async deserialize(\n data: SerializedPromptTemplate\n ): Promise<PromptTemplate> {\n if (!data.template) {\n throw new Error(\"Prompt template must have a template\");\n }\n const res = new PromptTemplate({\n inputVariables: data.input_variables,\n template: data.template,\n templateFormat: data.template_format,\n });\n return res;\n }\n\n // TODO(from file)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA6GA,IAAa,iBAAb,MAAa,uBAMHA,wCAEV;CACE,OAAO,UAAU;AACf,SAAO;CACR;CAED;C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AK,oBAAoB,CAAE;GAC/B,GAAG;EACJ;EACD,MAAM,aAAa;GACjB,GAAG;GACH,gBAAgB;GAChB,kBAAkB;EACnB;AACD,SAAO,IAAI,eAIT;CACH;CAED,YAAsC;AACpC,MAAI,KAAK,iBAAiB,OACxB,OAAM,IAAI,MACR;AAGJ,SAAO;GACL,OAAO,KAAK,gBAAgB;GAC5B,iBAAiB,KAAK;GACtB,UAAU,KAAK;GACf,iBAAiB,KAAK;EACvB;CACF;CAED,aAAa,YACXC,MACyB;AACzB,MAAI,CAAC,KAAK,SACR,OAAM,IAAI,MAAM;EAElB,MAAM,MAAM,IAAI,eAAe;GAC7B,gBAAgB,KAAK;GACrB,UAAU,KAAK;GACf,gBAAgB,KAAK;EACtB;AACD,SAAO;CACR;AAGF"}
@@ -36,7 +36,6 @@ PartialVariableName extends string = any, Format extends TemplateFormat = Templa
36
36
  * the message content array if using a complex message
37
37
  * content.
38
38
  */
39
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
39
  additionalContentFields?: ContentBlock;
41
40
  }
42
41
  type NonAlphanumeric = " " | "\t" | "\n" | "\r" | '"' | "'" | "{" | "[" | "(" | "`" | ":" | ";";
@@ -50,11 +49,7 @@ type ExtractTemplateParamsRecursive<T extends string, Result extends string[] =
50
49
  type ParamsFromFString<T extends string> = { [Key in ExtractTemplateParamsRecursive<T>[number]
51
50
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
51
  | (string & Record<never, never>)]: any };
53
- type ExtractedFStringParams<T extends string,
54
- // eslint-disable-next-line @typescript-eslint/ban-types
55
- RunInput extends InputValues = Symbol
56
- // eslint-disable-next-line @typescript-eslint/ban-types
57
- > = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;
52
+ type ExtractedFStringParams<T extends string, RunInput extends InputValues = Symbol> = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;
58
53
  /**
59
54
  * Schema to represent a basic prompt for an LLM.
60
55
  * @augments BasePromptTemplate
@@ -84,7 +79,6 @@ PartialVariableName extends string = any> extends BaseStringPromptTemplate<RunIn
84
79
  * the message content array if using a complex message
85
80
  * content.
86
81
  */
87
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
82
  additionalContentFields?: ContentBlock;
89
83
  constructor(input: PromptTemplateInput<RunInput, PartialVariableName>);
90
84
  _getPromptType(): "prompt";
@@ -111,15 +105,9 @@ PartialVariableName extends string = any> extends BaseStringPromptTemplate<RunIn
111
105
  /**
112
106
  * Load prompt template from a template f-string
113
107
  */
114
- static fromTemplate<
115
- // eslint-disable-next-line @typescript-eslint/ban-types
116
- RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, "f-string">, "template" | "inputVariables">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;
117
- static fromTemplate<
118
- // eslint-disable-next-line @typescript-eslint/ban-types
119
- RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string>, "template" | "inputVariables">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;
120
- static fromTemplate<
121
- // eslint-disable-next-line @typescript-eslint/ban-types
122
- RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, "mustache">, "template" | "inputVariables">): PromptTemplate<InputValues>;
108
+ static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, "f-string">, "template" | "inputVariables">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;
109
+ static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string>, "template" | "inputVariables">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;
110
+ static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, "mustache">, "template" | "inputVariables">): PromptTemplate<InputValues>;
123
111
  /**
124
112
  * Partially applies values to the prompt template.
125
113
  * @param values The values to be partially applied to the prompt template.
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.d.cts","names":["BaseStringPromptTemplate","BasePromptTemplateInput","TypedPromptInputValues","TemplateFormat","SerializedPromptTemplate","InputValues","PartialValues","MessageContent","ContentBlock","PromptTemplateInput","RunInput","PartialVariableName","Format","NonAlphanumeric","ExtractTemplateParamsRecursive","T","Param","Rest","Result","ParamsFromFString","Record","ExtractedFStringParams","Symbol","PromptTemplate","Promise","Omit","NewPartialVariableName","Extract","Exclude"],"sources":["../../src/prompts/prompt.d.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\nimport { BaseStringPromptTemplate } from \"./string.js\";\nimport type { BasePromptTemplateInput, TypedPromptInputValues } from \"./base.js\";\nimport { type TemplateFormat } from \"./template.js\";\nimport type { SerializedPromptTemplate } from \"./serde.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport { MessageContent, ContentBlock } from \"../messages/index.js\";\n/**\n * Inputs to create a {@link PromptTemplate}\n * @augments BasePromptTemplateInput\n */\nexport interface PromptTemplateInput<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any, Format extends TemplateFormat = TemplateFormat> extends BasePromptTemplateInput<RunInput, PartialVariableName> {\n /**\n * The prompt template\n */\n template: MessageContent;\n /**\n * The format of the prompt template. Options are \"f-string\" and \"mustache\"\n */\n templateFormat?: Format;\n /**\n * Whether or not to try validating the template on initialization\n *\n * @defaultValue `true`\n */\n validateTemplate?: boolean;\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 additionalContentFields?: ContentBlock;\n}\ntype NonAlphanumeric = \" \" | \"\\t\" | \"\\n\" | \"\\r\" | '\"' | \"'\" | \"{\" | \"[\" | \"(\" | \"`\" | \":\" | \";\";\n/**\n * Recursive type to extract template parameters from a string.\n * @template T - The input string.\n * @template Result - The resulting array of extracted template parameters.\n */\ntype ExtractTemplateParamsRecursive<T extends string, Result extends string[] = []> = T extends `${string}{${infer Param}}${infer Rest}` ? Param extends `${NonAlphanumeric}${string}` ? ExtractTemplateParamsRecursive<Rest, Result> // for non-template variables that look like template variables e.g. see https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/chains/query_constructor/prompt.ts\n : ExtractTemplateParamsRecursive<Rest, [...Result, Param]> : Result;\nexport type ParamsFromFString<T extends string> = {\n [Key in ExtractTemplateParamsRecursive<T>[number]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | (string & Record<never, never>)]: any;\n};\nexport type ExtractedFStringParams<T extends string, \n// eslint-disable-next-line @typescript-eslint/ban-types\nRunInput extends InputValues = Symbol\n// eslint-disable-next-line @typescript-eslint/ban-types\n> = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;\n/**\n * Schema to represent a basic prompt for an LLM.\n * @augments BasePromptTemplate\n * @augments PromptTemplateInput\n *\n * @example\n * ```ts\n * import { PromptTemplate } from \"langchain/prompts\";\n *\n * const prompt = new PromptTemplate({\n * inputVariables: [\"foo\"],\n * template: \"Say {foo}\",\n * });\n * ```\n */\nexport declare class PromptTemplate<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any> extends BaseStringPromptTemplate<RunInput, PartialVariableName> implements PromptTemplateInput<RunInput, PartialVariableName> {\n static lc_name(): string;\n template: MessageContent;\n templateFormat: TemplateFormat;\n validateTemplate: boolean;\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 additionalContentFields?: ContentBlock;\n constructor(input: PromptTemplateInput<RunInput, PartialVariableName>);\n _getPromptType(): \"prompt\";\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: TypedPromptInputValues<RunInput>): Promise<string>;\n /**\n * Take examples in list format with prefix and suffix to create a prompt.\n *\n * Intended to be used a a way to dynamically create a prompt from examples.\n *\n * @param examples - List of examples to use in the prompt.\n * @param suffix - String to go after the list of examples. Should generally set up the user's input.\n * @param inputVariables - A list of variable names the final prompt template will expect\n * @param exampleSeparator - The separator to use in between examples\n * @param prefix - String that should go before any examples. Generally includes examples.\n *\n * @returns The final prompt template generated.\n */\n static fromExamples(examples: string[], suffix: string, inputVariables: string[], exampleSeparator?: string, prefix?: string): PromptTemplate<any, any>;\n /**\n * Load prompt template from a template f-string\n */\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, \"f-string\">, \"template\" | \"inputVariables\">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string>, \"template\" | \"inputVariables\">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, \"mustache\">, \"template\" | \"inputVariables\">): PromptTemplate<InputValues>;\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 PromptTemplate with the partially applied values.\n */\n partial<NewPartialVariableName extends string>(values: PartialValues<NewPartialVariableName>): Promise<PromptTemplate<InputValues<Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>>, any>>;\n serialize(): SerializedPromptTemplate;\n static deserialize(data: SerializedPromptTemplate): Promise<PromptTemplate>;\n}\nexport {};\n"],"mappings":";;;;;;;;;;;AAYA;;;AAIyDG,UAJxCM,mBAIwCN;;iBAFxCE,W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;;AArDyE;;;mBAuCnHnB,cAAciB,6CAA6CP,aAAaU,KAAKhB,oBAAoBC,gEAAgEa,eAAeF,uBAAuBN,GAAGL;;;mBAG1ML,cAAciB,6CAA6CP,aAAaU,KAAKhB,oBAAoBC,oDAAoDa,eAAeF,uBAAuBN,GAAGL;;;mBAG9LL,cAAciB,6CAA6CP,aAAaU,KAAKhB,oBAAoBC,gEAAgEa,eAAelB;;;;;;yDAM1IC,cAAcoB,0BAA0BF,QAAQD,eAAelB,YAAYuB,QAAQD,cAAcjB,mBAAmBgB;eAC9JtB;2BACYA,2BAA2BoB,QAAQD"}
1
+ {"version":3,"file":"prompt.d.cts","names":["BaseStringPromptTemplate","BasePromptTemplateInput","TypedPromptInputValues","TemplateFormat","SerializedPromptTemplate","InputValues","PartialValues","MessageContent","ContentBlock","PromptTemplateInput","RunInput","PartialVariableName","Format","NonAlphanumeric","ExtractTemplateParamsRecursive","T","Param","Rest","Result","ParamsFromFString","Record","ExtractedFStringParams","Symbol","PromptTemplate","Promise","Omit","NewPartialVariableName","Extract","Exclude"],"sources":["../../src/prompts/prompt.d.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\nimport { BaseStringPromptTemplate } from \"./string.js\";\nimport type { BasePromptTemplateInput, TypedPromptInputValues } from \"./base.js\";\nimport { type TemplateFormat } from \"./template.js\";\nimport type { SerializedPromptTemplate } from \"./serde.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport { MessageContent, ContentBlock } from \"../messages/index.js\";\n/**\n * Inputs to create a {@link PromptTemplate}\n * @augments BasePromptTemplateInput\n */\nexport interface PromptTemplateInput<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any, Format extends TemplateFormat = TemplateFormat> extends BasePromptTemplateInput<RunInput, PartialVariableName> {\n /**\n * The prompt template\n */\n template: MessageContent;\n /**\n * The format of the prompt template. Options are \"f-string\" and \"mustache\"\n */\n templateFormat?: Format;\n /**\n * Whether or not to try validating the template on initialization\n *\n * @defaultValue `true`\n */\n validateTemplate?: boolean;\n /**\n * Additional fields which should be included inside\n * the message content array if using a complex message\n * content.\n */\n additionalContentFields?: ContentBlock;\n}\ntype NonAlphanumeric = \" \" | \"\\t\" | \"\\n\" | \"\\r\" | '\"' | \"'\" | \"{\" | \"[\" | \"(\" | \"`\" | \":\" | \";\";\n/**\n * Recursive type to extract template parameters from a string.\n * @template T - The input string.\n * @template Result - The resulting array of extracted template parameters.\n */\ntype ExtractTemplateParamsRecursive<T extends string, Result extends string[] = []> = T extends `${string}{${infer Param}}${infer Rest}` ? Param extends `${NonAlphanumeric}${string}` ? ExtractTemplateParamsRecursive<Rest, Result> // for non-template variables that look like template variables e.g. see https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/chains/query_constructor/prompt.ts\n : ExtractTemplateParamsRecursive<Rest, [...Result, Param]> : Result;\nexport type ParamsFromFString<T extends string> = {\n [Key in ExtractTemplateParamsRecursive<T>[number]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | (string & Record<never, never>)]: any;\n};\nexport type ExtractedFStringParams<T extends string, RunInput extends InputValues = Symbol> = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;\n/**\n * Schema to represent a basic prompt for an LLM.\n * @augments BasePromptTemplate\n * @augments PromptTemplateInput\n *\n * @example\n * ```ts\n * import { PromptTemplate } from \"langchain/prompts\";\n *\n * const prompt = new PromptTemplate({\n * inputVariables: [\"foo\"],\n * template: \"Say {foo}\",\n * });\n * ```\n */\nexport declare class PromptTemplate<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any> extends BaseStringPromptTemplate<RunInput, PartialVariableName> implements PromptTemplateInput<RunInput, PartialVariableName> {\n static lc_name(): string;\n template: MessageContent;\n templateFormat: TemplateFormat;\n validateTemplate: boolean;\n /**\n * Additional fields which should be included inside\n * the message content array if using a complex message\n * content.\n */\n additionalContentFields?: ContentBlock;\n constructor(input: PromptTemplateInput<RunInput, PartialVariableName>);\n _getPromptType(): \"prompt\";\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: TypedPromptInputValues<RunInput>): Promise<string>;\n /**\n * Take examples in list format with prefix and suffix to create a prompt.\n *\n * Intended to be used a a way to dynamically create a prompt from examples.\n *\n * @param examples - List of examples to use in the prompt.\n * @param suffix - String to go after the list of examples. Should generally set up the user's input.\n * @param inputVariables - A list of variable names the final prompt template will expect\n * @param exampleSeparator - The separator to use in between examples\n * @param prefix - String that should go before any examples. Generally includes examples.\n *\n * @returns The final prompt template generated.\n */\n static fromExamples(examples: string[], suffix: string, inputVariables: string[], exampleSeparator?: string, prefix?: string): PromptTemplate<any, any>;\n /**\n * Load prompt template from a template f-string\n */\n static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, \"f-string\">, \"template\" | \"inputVariables\">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string>, \"template\" | \"inputVariables\">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, \"mustache\">, \"template\" | \"inputVariables\">): PromptTemplate<InputValues>;\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 PromptTemplate with the partially applied values.\n */\n partial<NewPartialVariableName extends string>(values: PartialValues<NewPartialVariableName>): Promise<PromptTemplate<InputValues<Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>>, any>>;\n serialize(): SerializedPromptTemplate;\n static deser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jB,mBAAmBgB;eAC9JtB;2BACYA,2BAA2BoB,QAAQD"}
@@ -36,7 +36,6 @@ PartialVariableName extends string = any, Format extends TemplateFormat = Templa
36
36
  * the message content array if using a complex message
37
37
  * content.
38
38
  */
39
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
39
  additionalContentFields?: ContentBlock;
41
40
  }
42
41
  type NonAlphanumeric = " " | "\t" | "\n" | "\r" | '"' | "'" | "{" | "[" | "(" | "`" | ":" | ";";
@@ -50,11 +49,7 @@ type ExtractTemplateParamsRecursive<T extends string, Result extends string[] =
50
49
  type ParamsFromFString<T extends string> = { [Key in ExtractTemplateParamsRecursive<T>[number]
51
50
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
51
  | (string & Record<never, never>)]: any };
53
- type ExtractedFStringParams<T extends string,
54
- // eslint-disable-next-line @typescript-eslint/ban-types
55
- RunInput extends InputValues = Symbol
56
- // eslint-disable-next-line @typescript-eslint/ban-types
57
- > = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;
52
+ type ExtractedFStringParams<T extends string, RunInput extends InputValues = Symbol> = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;
58
53
  /**
59
54
  * Schema to represent a basic prompt for an LLM.
60
55
  * @augments BasePromptTemplate
@@ -84,7 +79,6 @@ PartialVariableName extends string = any> extends BaseStringPromptTemplate<RunIn
84
79
  * the message content array if using a complex message
85
80
  * content.
86
81
  */
87
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
82
  additionalContentFields?: ContentBlock;
89
83
  constructor(input: PromptTemplateInput<RunInput, PartialVariableName>);
90
84
  _getPromptType(): "prompt";
@@ -111,15 +105,9 @@ PartialVariableName extends string = any> extends BaseStringPromptTemplate<RunIn
111
105
  /**
112
106
  * Load prompt template from a template f-string
113
107
  */
114
- static fromTemplate<
115
- // eslint-disable-next-line @typescript-eslint/ban-types
116
- RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, "f-string">, "template" | "inputVariables">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;
117
- static fromTemplate<
118
- // eslint-disable-next-line @typescript-eslint/ban-types
119
- RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string>, "template" | "inputVariables">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;
120
- static fromTemplate<
121
- // eslint-disable-next-line @typescript-eslint/ban-types
122
- RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, "mustache">, "template" | "inputVariables">): PromptTemplate<InputValues>;
108
+ static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, "f-string">, "template" | "inputVariables">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;
109
+ static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string>, "template" | "inputVariables">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;
110
+ static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, "mustache">, "template" | "inputVariables">): PromptTemplate<InputValues>;
123
111
  /**
124
112
  * Partially applies values to the prompt template.
125
113
  * @param values The values to be partially applied to the prompt template.
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.d.ts","names":["BaseStringPromptTemplate","BasePromptTemplateInput","TypedPromptInputValues","TemplateFormat","SerializedPromptTemplate","InputValues","PartialValues","MessageContent","ContentBlock","PromptTemplateInput","RunInput","PartialVariableName","Format","NonAlphanumeric","ExtractTemplateParamsRecursive","T","Param","Rest","Result","ParamsFromFString","Record","ExtractedFStringParams","Symbol","PromptTemplate","Promise","Omit","NewPartialVariableName","Extract","Exclude"],"sources":["../../src/prompts/prompt.d.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\nimport { BaseStringPromptTemplate } from \"./string.js\";\nimport type { BasePromptTemplateInput, TypedPromptInputValues } from \"./base.js\";\nimport { type TemplateFormat } from \"./template.js\";\nimport type { SerializedPromptTemplate } from \"./serde.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport { MessageContent, ContentBlock } from \"../messages/index.js\";\n/**\n * Inputs to create a {@link PromptTemplate}\n * @augments BasePromptTemplateInput\n */\nexport interface PromptTemplateInput<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any, Format extends TemplateFormat = TemplateFormat> extends BasePromptTemplateInput<RunInput, PartialVariableName> {\n /**\n * The prompt template\n */\n template: MessageContent;\n /**\n * The format of the prompt template. Options are \"f-string\" and \"mustache\"\n */\n templateFormat?: Format;\n /**\n * Whether or not to try validating the template on initialization\n *\n * @defaultValue `true`\n */\n validateTemplate?: boolean;\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 additionalContentFields?: ContentBlock;\n}\ntype NonAlphanumeric = \" \" | \"\\t\" | \"\\n\" | \"\\r\" | '\"' | \"'\" | \"{\" | \"[\" | \"(\" | \"`\" | \":\" | \";\";\n/**\n * Recursive type to extract template parameters from a string.\n * @template T - The input string.\n * @template Result - The resulting array of extracted template parameters.\n */\ntype ExtractTemplateParamsRecursive<T extends string, Result extends string[] = []> = T extends `${string}{${infer Param}}${infer Rest}` ? Param extends `${NonAlphanumeric}${string}` ? ExtractTemplateParamsRecursive<Rest, Result> // for non-template variables that look like template variables e.g. see https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/chains/query_constructor/prompt.ts\n : ExtractTemplateParamsRecursive<Rest, [...Result, Param]> : Result;\nexport type ParamsFromFString<T extends string> = {\n [Key in ExtractTemplateParamsRecursive<T>[number]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | (string & Record<never, never>)]: any;\n};\nexport type ExtractedFStringParams<T extends string, \n// eslint-disable-next-line @typescript-eslint/ban-types\nRunInput extends InputValues = Symbol\n// eslint-disable-next-line @typescript-eslint/ban-types\n> = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;\n/**\n * Schema to represent a basic prompt for an LLM.\n * @augments BasePromptTemplate\n * @augments PromptTemplateInput\n *\n * @example\n * ```ts\n * import { PromptTemplate } from \"langchain/prompts\";\n *\n * const prompt = new PromptTemplate({\n * inputVariables: [\"foo\"],\n * template: \"Say {foo}\",\n * });\n * ```\n */\nexport declare class PromptTemplate<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any> extends BaseStringPromptTemplate<RunInput, PartialVariableName> implements PromptTemplateInput<RunInput, PartialVariableName> {\n static lc_name(): string;\n template: MessageContent;\n templateFormat: TemplateFormat;\n validateTemplate: boolean;\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 additionalContentFields?: ContentBlock;\n constructor(input: PromptTemplateInput<RunInput, PartialVariableName>);\n _getPromptType(): \"prompt\";\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: TypedPromptInputValues<RunInput>): Promise<string>;\n /**\n * Take examples in list format with prefix and suffix to create a prompt.\n *\n * Intended to be used a a way to dynamically create a prompt from examples.\n *\n * @param examples - List of examples to use in the prompt.\n * @param suffix - String to go after the list of examples. Should generally set up the user's input.\n * @param inputVariables - A list of variable names the final prompt template will expect\n * @param exampleSeparator - The separator to use in between examples\n * @param prefix - String that should go before any examples. Generally includes examples.\n *\n * @returns The final prompt template generated.\n */\n static fromExamples(examples: string[], suffix: string, inputVariables: string[], exampleSeparator?: string, prefix?: string): PromptTemplate<any, any>;\n /**\n * Load prompt template from a template f-string\n */\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, \"f-string\">, \"template\" | \"inputVariables\">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string>, \"template\" | \"inputVariables\">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, \"mustache\">, \"template\" | \"inputVariables\">): PromptTemplate<InputValues>;\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 PromptTemplate with the partially applied values.\n */\n partial<NewPartialVariableName extends string>(values: PartialValues<NewPartialVariableName>): Promise<PromptTemplate<InputValues<Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>>, any>>;\n serialize(): SerializedPromptTemplate;\n static deserialize(data: SerializedPromptTemplate): Promise<PromptTemplate>;\n}\nexport {};\n"],"mappings":";;;;;;;;;;;AAYA;;;AAIyDG,UAJxCM,mBAIwCN;;iBAFxCE,WAEyGK,GAAAA,GAAAA;;4BAI5GH,MAAAA,GAAAA,GAAAA,EAAAA,eAJ2CJ,cAI3CI,GAJ4DJ,cAI5DI,CAAAA,SAJoFN,uBAIpFM,CAJ4GG,QAI5GH,EAJsHI,mBAItHJ,CAAAA,CAAAA;EAAc;;;EAJ6F,QAAA,EAI3GA,cAJ2G;EAuBpHM;AAAe;;EAMe,cAAmDE,CAAAA,EArBjEH,MAqBiEG;EAAC;;;;;EAAgI,gBACrLE,CAAAA,EAAAA,OAAAA;EAAI;;;;AAA8B;EACxDE;EAAiB,uBAAA,CAAA,EAVCX,YAUD;;KARxBK,eAAAA,GASOC,GAAAA,GAAAA,IAAAA,GAAAA,IAAAA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plateInput","TypedPromptInputValues","TemplateFormat","SerializedPromptTemplate","InputValues","PartialValues","MessageContent","ContentBlock","PromptTemplateInput","RunInput","PartialVariableName","Format","NonAlphanumeric","ExtractTemplateParamsRecursive","T","Param","Rest","Result","ParamsFromFString","Record","ExtractedFStringParams","Symbol","PromptTemplate","Promise","Omit","NewPartialVariableName","Extract","Exclude"],"sources":["../../src/prompts/prompt.d.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\nimport { BaseStringPromptTemplate } from \"./string.js\";\nimport type { BasePromptTemplateInput, TypedPromptInputValues } from \"./base.js\";\nimport { type TemplateFormat } from \"./template.js\";\nimport type { SerializedPromptTemplate } from \"./serde.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport { MessageContent, ContentBlock } from \"../messages/index.js\";\n/**\n * Inputs to create a {@link PromptTemplate}\n * @augments BasePromptTemplateInput\n */\nexport interface PromptTemplateInput<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any, Format extends TemplateFormat = TemplateFormat> extends BasePromptTemplateInput<RunInput, PartialVariableName> {\n /**\n * The prompt template\n */\n template: MessageContent;\n /**\n * The format of the prompt template. Options are \"f-string\" and \"mustache\"\n */\n templateFormat?: Format;\n /**\n * Whether or not to try validating the template on initialization\n *\n * @defaultValue `true`\n */\n validateTemplate?: boolean;\n /**\n * Additional fields which should be included inside\n * the message content array if using a complex message\n * content.\n */\n additionalContentFields?: ContentBlock;\n}\ntype NonAlphanumeric = \" \" | \"\\t\" | \"\\n\" | \"\\r\" | '\"' | \"'\" | \"{\" | \"[\" | \"(\" | \"`\" | \":\" | \";\";\n/**\n * Recursive type to extract template parameters from a string.\n * @template T - The input string.\n * @template Result - The resulting array of extracted template parameters.\n */\ntype ExtractTemplateParamsRecursive<T extends string, Result extends string[] = []> = T extends `${string}{${infer Param}}${infer Rest}` ? Param extends `${NonAlphanumeric}${string}` ? ExtractTemplateParamsRecursive<Rest, Result> // for non-template variables that look like template variables e.g. see https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/chains/query_constructor/prompt.ts\n : ExtractTemplateParamsRecursive<Rest, [...Result, Param]> : Result;\nexport type ParamsFromFString<T extends string> = {\n [Key in ExtractTemplateParamsRecursive<T>[number]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | (string & Record<never, never>)]: any;\n};\nexport type ExtractedFStringParams<T extends string, RunInput extends InputValues = Symbol> = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;\n/**\n * Schema to represent a basic prompt for an LLM.\n * @augments BasePromptTemplate\n * @augments PromptTemplateInput\n *\n * @example\n * ```ts\n * import { PromptTemplate } from \"langchain/prompts\";\n *\n * const prompt = new PromptTemplate({\n * inputVariables: [\"foo\"],\n * template: \"Say {foo}\",\n * });\n * ```\n */\nexport declare class PromptTemplate<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any> extends BaseStringPromptTemplate<RunInput, PartialVariableName> implements PromptTemplateInput<RunInput, PartialVariableName> {\n static lc_name(): string;\n template: MessageContent;\n templateFormat: TemplateFormat;\n validateTemplate: boolean;\n /**\n * Additional fields which should be included inside\n * the message content array if using a complex message\n * content.\n */\n additionalContentFields?: ContentBlock;\n constructor(input: PromptTemplateInput<RunInput, PartialVariableName>);\n _getPromptType(): \"prompt\";\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: TypedPromptInputValues<RunInput>): Promise<string>;\n /**\n * Take examples in list format with prefix and suffix to create a prompt.\n *\n * Intended to be used a a way to dynamically create a prompt from examples.\n *\n * @param examples - List of examples to use in the prompt.\n * @param suffix - String to go after the list of examples. Should generally set up the user's input.\n * @param inputVariables - A list of variable names the final prompt template will expect\n * @param exampleSeparator - The separator to use in between examples\n * @param prefix - String that should go before any examples. Generally includes examples.\n *\n * @returns The final prompt template generated.\n */\n static fromExamples(examples: string[], suffix: string, inputVariables: string[], exampleSeparator?: string, prefix?: string): PromptTemplate<any, any>;\n /**\n * Load prompt template from a template f-string\n */\n static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, \"f-string\">, \"template\" | \"inputVariables\">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string>, \"template\" | \"inputVariables\">): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n static fromTemplate<RunInput extends InputValues = Symbol, T extends string = string>(template: T, options?: Omit<PromptTemplateInput<RunInput, string, \"mustache\">, \"template\" | \"inputVariables\">): PromptTemplate<InputValues>;\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 PromptTemplate with the partially applied values.\n */\n partial<NewPartialVariableName extends string>(values: PartialValues<NewPartialVariableName>): Promise<PromptTemplate<InputValues<Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>>, any>>;\n serialize(): SerializedPromptTemplate;\n static deserialize(data: SerializedPromptTemplate): Promise<PromptTemplate>;\n}\nexport {};\n"],"mappings":";;;;;;;;;;;AAYA;;;AAIyDG,UAJxCM,mBAIwCN;;iBAFxCE,WAEyGK,GAAAA,GAAAA;;4BAI5GH,MAAAA,GAAAA,GAAAA,EAAAA,eAJ2CJ,cAI3CI,GAJ4DJ,cAI5DI,CAAAA,SAJoFN,uBAIpFM,CAJ4GG,QAI5GH,EAJsHI,mBAItHJ,CAAAA,CAAAA;EAAc;;;EAJ6F,QAAA,EAI3GA,cAJ2G;EAsBpHM;AAAe;;EAMe,cAAmDE,CAAAA,EApBjEH,MAoBiEG;EAAC;;;;;EAAgI,gBACrLE,CAAAA,EAAAA,OAA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AUnNX,EAVsNM,QAUtNN,CAAAA,CAAAA;EAAwB,OAAWmB,YAAAA,CAAAA,iBATvBlB,WASuBkB,GATTD,MASSC,EAAAA,UAAAA,MAAAA,GAAAA,MAAAA,CAAAA,CAAAA,QAAAA,EAToCR,CASpCQ,EAAAA,OAAAA,CAAAA,EATiDE,IASjDF,CATsDd,mBAStDc,CAT0Eb,QAS1Ea,EAAAA,MAAAA,CAAAA,EAAAA,UAAAA,GAAAA,gBAAAA,CAAAA,CAAAA,EAT8HA,cAS9HA,CAT6IF,sBAS7IE,CAToKR,CASpKQ,EATuKb,QASvKa,CAAAA,CAAAA;EAAc,OAAtBC,YAAAA,CAAAA,iBARfnB,WAQemB,GARDF,MAQCE,EAAAA,UAAAA,MAAAA,GAAAA,MAAAA,CAAAA,CAAAA,QAAAA,EAR4CT,CAQ5CS,EAAAA,OAAAA,CAAAA,EARyDC,IAQzDD,CAR8Df,mBAQ9De,CARkFd,QAQlFc,EAAAA,MAAAA,EAAAA,UAAAA,CAAAA,EAAAA,UAAAA,GAAAA,gBAAAA,CAAAA,CAAAA,EARkJD,cAQlJC,CARiKnB,WAQjKmB,CAAAA;EAAO;;AA9CyE;;;yDA4C7ElB,cAAcoB,0BAA0BF,QAAQD,eAAelB,YAAYuB,QAAQD,cAAcjB,mBAAmBgB;eAC9JtB;2BACYA,2BAA2BoB,QAAQD"}
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.js","names":["input: PromptTemplateInput<RunInput, PartialVariableName>","totalInputVariables: string[]","values: TypedPromptInputValues<RunInput>","examples: string[]","suffix: string","inputVariables: string[]","template: T","options?: Omit<\n PromptTemplateInput<RunInput, string, TemplateFormat>,\n \"template\" | \"inputVariables\"\n >","values: PartialValues<NewPartialVariableName>","data: SerializedPromptTemplate"],"sources":["../../src/prompts/prompt.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\n\nimport { BaseStringPromptTemplate } from \"./string.js\";\nimport type {\n BasePromptTemplateInput,\n TypedPromptInputValues,\n} from \"./base.js\";\nimport {\n checkValidTemplate,\n parseTemplate,\n renderTemplate,\n type TemplateFormat,\n} from \"./template.js\";\nimport type { SerializedPromptTemplate } from \"./serde.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport { MessageContent, ContentBlock } from \"../messages/index.js\";\n\n/**\n * Inputs to create a {@link PromptTemplate}\n * @augments BasePromptTemplateInput\n */\nexport interface PromptTemplateInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any,\n Format extends TemplateFormat = TemplateFormat\n> extends BasePromptTemplateInput<RunInput, PartialVariableName> {\n /**\n * The prompt template\n */\n template: MessageContent;\n\n /**\n * The format of the prompt template. Options are \"f-string\" and \"mustache\"\n */\n templateFormat?: Format;\n\n /**\n * Whether or not to try validating the template on initialization\n *\n * @defaultValue `true`\n */\n validateTemplate?: boolean;\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 additionalContentFields?: ContentBlock;\n}\n\ntype NonAlphanumeric =\n | \" \"\n | \"\\t\"\n | \"\\n\"\n | \"\\r\"\n | '\"'\n | \"'\"\n | \"{\"\n | \"[\"\n | \"(\"\n | \"`\"\n | \":\"\n | \";\";\n\n/**\n * Recursive type to extract template parameters from a string.\n * @template T - The input string.\n * @template Result - The resulting array of extracted template parameters.\n */\ntype ExtractTemplateParamsRecursive<\n T extends string,\n Result extends string[] = []\n> = T extends `${string}{${infer Param}}${infer Rest}`\n ? Param extends `${NonAlphanumeric}${string}`\n ? ExtractTemplateParamsRecursive<Rest, Result> // for non-template variables that look like template variables e.g. see https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/chains/query_constructor/prompt.ts\n : ExtractTemplateParamsRecursive<Rest, [...Result, Param]>\n : Result;\n\nexport type ParamsFromFString<T extends string> = {\n [Key in\n | ExtractTemplateParamsRecursive<T>[number]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | (string & Record<never, never>)]: any;\n};\n\nexport type ExtractedFStringParams<\n T extends string,\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol\n // eslint-disable-next-line @typescript-eslint/ban-types\n> = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;\n\n/**\n * Schema to represent a basic prompt for an LLM.\n * @augments BasePromptTemplate\n * @augments PromptTemplateInput\n *\n * @example\n * ```ts\n * import { PromptTemplate } from \"langchain/prompts\";\n *\n * const prompt = new PromptTemplate({\n * inputVariables: [\"foo\"],\n * template: \"Say {foo}\",\n * });\n * ```\n */\nexport class PromptTemplate<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n >\n extends BaseStringPromptTemplate<RunInput, PartialVariableName>\n implements PromptTemplateInput<RunInput, PartialVariableName>\n{\n static lc_name() {\n return \"PromptTemplate\";\n }\n\n template: MessageContent;\n\n templateFormat: TemplateFormat = \"f-string\";\n\n validateTemplate = 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 additionalContentFields?: ContentBlock;\n\n constructor(input: PromptTemplateInput<RunInput, PartialVariableName>) {\n super(input);\n // If input is mustache and validateTemplate is not defined, set it to false\n if (\n input.templateFormat === \"mustache\" &&\n input.validateTemplate === undefined\n ) {\n this.validateTemplate = false;\n }\n Object.assign(this, input);\n\n if (this.validateTemplate) {\n if (this.templateFormat === \"mustache\") {\n throw new Error(\"Mustache templates cannot be validated.\");\n }\n let totalInputVariables: string[] = this.inputVariables;\n if (this.partialVariables) {\n totalInputVariables = totalInputVariables.concat(\n Object.keys(this.partialVariables)\n );\n }\n checkValidTemplate(\n this.template,\n this.templateFormat,\n totalInputVariables\n );\n }\n }\n\n _getPromptType(): \"prompt\" {\n return \"prompt\";\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 async format(values: TypedPromptInputValues<RunInput>): Promise<string> {\n const allValues = await this.mergePartialAndUserVariables(values);\n return renderTemplate(\n this.template as string,\n this.templateFormat,\n allValues\n );\n }\n\n /**\n * Take examples in list format with prefix and suffix to create a prompt.\n *\n * Intended to be used a a way to dynamically create a prompt from examples.\n *\n * @param examples - List of examples to use in the prompt.\n * @param suffix - String to go after the list of examples. Should generally set up the user's input.\n * @param inputVariables - A list of variable names the final prompt template will expect\n * @param exampleSeparator - The separator to use in between examples\n * @param prefix - String that should go before any examples. Generally includes examples.\n *\n * @returns The final prompt template generated.\n */\n static fromExamples(\n examples: string[],\n suffix: string,\n inputVariables: string[],\n exampleSeparator = \"\\n\\n\",\n prefix = \"\"\n ) {\n const template = [prefix, ...examples, suffix].join(exampleSeparator);\n return new PromptTemplate({\n inputVariables,\n template,\n });\n }\n\n /**\n * Load prompt template from a template f-string\n */\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string, \"f-string\">,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string>,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string, \"mustache\">,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<InputValues>;\n\n static fromTemplate<\n // eslint-disable-next-line @typescript-eslint/ban-types\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string, TemplateFormat>,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<ExtractedFStringParams<T, RunInput> | InputValues> {\n const { templateFormat = \"f-string\", ...rest } = options ?? {};\n const names = new Set<string>();\n parseTemplate(template, templateFormat).forEach((node) => {\n if (node.type === \"variable\") {\n names.add(node.name);\n }\n });\n\n return new PromptTemplate({\n // Rely on extracted types\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n inputVariables: [...names] as any[],\n templateFormat,\n template,\n ...rest,\n });\n }\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 PromptTemplate with the partially applied values.\n */\n async partial<NewPartialVariableName extends string>(\n values: PartialValues<NewPartialVariableName>\n ) {\n const newInputVariables = this.inputVariables.filter(\n (iv) => !(iv in values)\n ) as Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>[];\n const newPartialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n } as PartialValues<PartialVariableName | NewPartialVariableName>;\n const promptDict = {\n ...this,\n inputVariables: newInputVariables,\n partialVariables: newPartialVariables,\n };\n return new PromptTemplate<\n InputValues<\n Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>\n >\n >(promptDict);\n }\n\n serialize(): SerializedPromptTemplate {\n if (this.outputParser !== undefined) {\n throw new Error(\n \"Cannot serialize a prompt template with an output parser\"\n );\n }\n return {\n _type: this._getPromptType(),\n input_variables: this.inputVariables,\n template: this.template,\n template_format: this.templateFormat,\n };\n }\n\n static async deserialize(\n data: SerializedPromptTemplate\n ): Promise<PromptTemplate> {\n if (!data.template) {\n throw new Error(\"Prompt template must have a template\");\n }\n const res = new PromptTemplate({\n inputVariables: data.input_variables,\n template: data.template,\n templateFormat: data.template_format,\n });\n return res;\n }\n\n // TODO(from file)\n}\n"],"m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A,MAAM,oBAAoB,KAAK,eAAe,OAC5C,CAAC,OAAO,EAAE,MAAM,QACjB;EACD,MAAM,sBAAsB;GAC1B,GAAI,KAAK,oBAAoB,CAAE;GAC/B,GAAG;EACJ;EACD,MAAM,aAAa;GACjB,GAAG;GACH,gBAAgB;GAChB,kBAAkB;EACnB;AACD,SAAO,IAAI,eAIT;CACH;CAED,YAAsC;AACpC,MAAI,KAAK,iBAAiB,OACxB,OAAM,IAAI,MACR;AAGJ,SAAO;GACL,OAAO,KAAK,gBAAgB;GAC5B,iBAAiB,KAAK;GACtB,UAAU,KAAK;GACf,iBAAiB,KAAK;EACvB;CACF;CAED,aAAa,YACXC,MACyB;AACzB,MAAI,CAAC,KAAK,SACR,OAAM,IAAI,MAAM;EAElB,MAAM,MAAM,IAAI,eAAe;GAC7B,gBAAgB,KAAK;GACrB,UAAU,KAAK;GACf,gBAAgB,KAAK;EACtB;AACD,SAAO;CACR;AAGF"}
1
+ {"version":3,"file":"prompt.js","names":["input: PromptTemplateInput<RunInput, PartialVariableName>","totalInputVariables: string[]","values: TypedPromptInputValues<RunInput>","examples: string[]","suffix: string","inputVariables: string[]","template: T","options?: Omit<\n PromptTemplateInput<RunInput, string, TemplateFormat>,\n \"template\" | \"inputVariables\"\n >","values: PartialValues<NewPartialVariableName>","data: SerializedPromptTemplate"],"sources":["../../src/prompts/prompt.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\n\nimport { BaseStringPromptTemplate } from \"./string.js\";\nimport type {\n BasePromptTemplateInput,\n TypedPromptInputValues,\n} from \"./base.js\";\nimport {\n checkValidTemplate,\n parseTemplate,\n renderTemplate,\n type TemplateFormat,\n} from \"./template.js\";\nimport type { SerializedPromptTemplate } from \"./serde.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport { MessageContent, ContentBlock } from \"../messages/index.js\";\n\n/**\n * Inputs to create a {@link PromptTemplate}\n * @augments BasePromptTemplateInput\n */\nexport interface PromptTemplateInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any,\n Format extends TemplateFormat = TemplateFormat\n> extends BasePromptTemplateInput<RunInput, PartialVariableName> {\n /**\n * The prompt template\n */\n template: MessageContent;\n\n /**\n * The format of the prompt template. Options are \"f-string\" and \"mustache\"\n */\n templateFormat?: Format;\n\n /**\n * Whether or not to try validating the template on initialization\n *\n * @defaultValue `true`\n */\n validateTemplate?: boolean;\n\n /**\n * Additional fields which should be included inside\n * the message content array if using a complex message\n * content.\n */\n additionalContentFields?: ContentBlock;\n}\n\ntype NonAlphanumeric =\n | \" \"\n | \"\\t\"\n | \"\\n\"\n | \"\\r\"\n | '\"'\n | \"'\"\n | \"{\"\n | \"[\"\n | \"(\"\n | \"`\"\n | \":\"\n | \";\";\n\n/**\n * Recursive type to extract template parameters from a string.\n * @template T - The input string.\n * @template Result - The resulting array of extracted template parameters.\n */\ntype ExtractTemplateParamsRecursive<\n T extends string,\n Result extends string[] = []\n> = T extends `${string}{${infer Param}}${infer Rest}`\n ? Param extends `${NonAlphanumeric}${string}`\n ? ExtractTemplateParamsRecursive<Rest, Result> // for non-template variables that look like template variables e.g. see https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/chains/query_constructor/prompt.ts\n : ExtractTemplateParamsRecursive<Rest, [...Result, Param]>\n : Result;\n\nexport type ParamsFromFString<T extends string> = {\n [Key in\n | ExtractTemplateParamsRecursive<T>[number]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | (string & Record<never, never>)]: any;\n};\n\nexport type ExtractedFStringParams<\n T extends string,\n RunInput extends InputValues = Symbol\n> = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;\n\n/**\n * Schema to represent a basic prompt for an LLM.\n * @augments BasePromptTemplate\n * @augments PromptTemplateInput\n *\n * @example\n * ```ts\n * import { PromptTemplate } from \"langchain/prompts\";\n *\n * const prompt = new PromptTemplate({\n * inputVariables: [\"foo\"],\n * template: \"Say {foo}\",\n * });\n * ```\n */\nexport class PromptTemplate<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n >\n extends BaseStringPromptTemplate<RunInput, PartialVariableName>\n implements PromptTemplateInput<RunInput, PartialVariableName>\n{\n static lc_name() {\n return \"PromptTemplate\";\n }\n\n template: MessageContent;\n\n templateFormat: TemplateFormat = \"f-string\";\n\n validateTemplate = 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 additionalContentFields?: ContentBlock;\n\n constructor(input: PromptTemplateInput<RunInput, PartialVariableName>) {\n super(input);\n // If input is mustache and validateTemplate is not defined, set it to false\n if (\n input.templateFormat === \"mustache\" &&\n input.validateTemplate === undefined\n ) {\n this.validateTemplate = false;\n }\n Object.assign(this, input);\n\n if (this.validateTemplate) {\n if (this.templateFormat === \"mustache\") {\n throw new Error(\"Mustache templates cannot be validated.\");\n }\n let totalInputVariables: string[] = this.inputVariables;\n if (this.partialVariables) {\n totalInputVariables = totalInputVariables.concat(\n Object.keys(this.partialVariables)\n );\n }\n checkValidTemplate(\n this.template,\n this.templateFormat,\n totalInputVariables\n );\n }\n }\n\n _getPromptType(): \"prompt\" {\n return \"prompt\";\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 async format(values: TypedPromptInputValues<RunInput>): Promise<string> {\n const allValues = await this.mergePartialAndUserVariables(values);\n return renderTemplate(\n this.template as string,\n this.templateFormat,\n allValues\n );\n }\n\n /**\n * Take examples in list format with prefix and suffix to create a prompt.\n *\n * Intended to be used a a way to dynamically create a prompt from examples.\n *\n * @param examples - List of examples to use in the prompt.\n * @param suffix - String to go after the list of examples. Should generally set up the user's input.\n * @param inputVariables - A list of variable names the final prompt template will expect\n * @param exampleSeparator - The separator to use in between examples\n * @param prefix - String that should go before any examples. Generally includes examples.\n *\n * @returns The final prompt template generated.\n */\n static fromExamples(\n examples: string[],\n suffix: string,\n inputVariables: string[],\n exampleSeparator = \"\\n\\n\",\n prefix = \"\"\n ) {\n const template = [prefix, ...examples, suffix].join(exampleSeparator);\n return new PromptTemplate({\n inputVariables,\n template,\n });\n }\n\n /**\n * Load prompt template from a template f-string\n */\n static fromTemplate<\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string, \"f-string\">,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n\n static fromTemplate<\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string>,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<ExtractedFStringParams<T, RunInput>>;\n\n static fromTemplate<\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string, \"mustache\">,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<InputValues>;\n\n static fromTemplate<\n RunInput extends InputValues = Symbol,\n T extends string = string\n >(\n template: T,\n options?: Omit<\n PromptTemplateInput<RunInput, string, TemplateFormat>,\n \"template\" | \"inputVariables\"\n >\n ): PromptTemplate<ExtractedFStringParams<T, RunInput> | InputValues> {\n const { templateFormat = \"f-string\", ...rest } = options ?? {};\n const names = new Set<string>();\n parseTemplate(template, templateFormat).forEach((node) => {\n if (node.type === \"variable\") {\n names.add(node.name);\n }\n });\n\n return new PromptTemplate({\n // Rely on extracted types\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n inputVariables: [...names] as any[],\n templateFormat,\n template,\n ...rest,\n });\n }\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 PromptTemplate with the partially applied values.\n */\n async partial<NewPartialVariableName extends string>(\n values: PartialValues<NewPartialVariableName>\n ) {\n const newInputVariables = this.inputVariables.filter(\n (iv) => !(iv in values)\n ) as Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>[];\n const newPartialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n } as PartialValues<PartialVariableName | NewPartialVariableName>;\n const promptDict = {\n ...this,\n inputVariables: newInputVariables,\n partialVariables: newPartialVariables,\n };\n return new PromptTemplate<\n InputValues<\n Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>\n >\n >(promptDict);\n }\n\n serialize(): SerializedPromptTemplate {\n if (this.outputParser !== undefined) {\n throw new Error(\n \"Cannot serialize a prompt template with an output parser\"\n );\n }\n return {\n _type: this._getPromptType(),\n input_variables: this.inputVariables,\n template: this.template,\n template_format: this.templateFormat,\n };\n }\n\n static async deserialize(\n data: SerializedPromptTemplate\n ): Promise<PromptTemplate> {\n if (!data.template) {\n throw new Error(\"Prompt template must have a template\");\n }\n const res = new PromptTemplate({\n inputVariables: data.input_variables,\n template: data.template,\n templateFormat: data.template_format,\n });\n return res;\n }\n\n // TODO(from file)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA6GA,IAAa,iBAAb,MAAa,uBAMH,yBAEV;CACE,OAAO,UAAU;AACf,SAAO;CACR;CAED;CAEA,iBAAiC;CAEjC,mBAAmB;;;;;;CAOnB;CAEA,YAAYA,OAA2D;EACrE,MAAM,MAAM;AAEZ,MACE,MAAM,mBAAmB,cACzB,MAAM,qBAAqB,QAE3B,KAAK,mBAAmB;EAE1B,OAAO,OAAO,MAAM,MAAM;AAE1B,MAAI,KAAK,kBAAkB;AACzB,OAAI,KAAK,mBAAmB,WAC1B,OAAM,IAAI,MAAM;GAElB,IAAIC,sBAAgC,KAAK;AACzC,OAAI,KAAK,kBACP,sBAAsB,oBAAoB,OACxC,OAAO,KAAK,KAAK,iBAAiB,CACnC;GAEH,mBACE,KAAK,UACL,KAAK,gBACL,oBACD;EACF;CACF;CAED,iBAA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AK;GACf,gBAAgB,KAAK;EACtB;AACD,SAAO;CACR;AAGF"}
@@ -1 +1 @@
1
- {"version":3,"file":"structured.cjs","names":["x: unknown","ChatPromptTemplate","input: StructuredPromptInput<RunInput, PartialVariableName>","coerceable: RunnableLike<ChatPromptValueInterface, NewRunOutput>","RunnableBinding","promptMessages: (\n | ChatPromptTemplate<InputValues, string>\n | BaseMessagePromptTemplateLike\n )[]","schema: StructuredPromptInput[\"schema\"]","method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\""],"sources":["../../src/prompts/structured.ts"],"sourcesContent":["import { ChatPromptValueInterface } from \"../prompt_values.js\";\nimport { RunnableLike, Runnable, RunnableBinding } from \"../runnables/base.js\";\nimport { RunnableConfig } from \"../runnables/config.js\";\nimport { InputValues } from \"../utils/types/index.js\";\nimport {\n BaseMessagePromptTemplateLike,\n ChatPromptTemplate,\n ChatPromptTemplateInput,\n} from \"./chat.js\";\n\nfunction isWithStructuredOutput(\n x: unknown\n // eslint-disable-next-line @typescript-eslint/ban-types\n): x is {\n withStructuredOutput: (...arg: unknown[]) => Runnable;\n} {\n return (\n typeof x === \"object\" &&\n x != null &&\n \"withStructuredOutput\" in x &&\n typeof x.withStructuredOutput === \"function\"\n );\n}\n\nfunction isRunnableBinding(x: unknown): x is RunnableBinding<unknown, unknown> {\n return (\n typeof x === \"object\" &&\n x != null &&\n \"lc_id\" in x &&\n Array.isArray(x.lc_id) &&\n x.lc_id.join(\"/\") === \"langchain_core/runnables/RunnableBinding\"\n );\n}\n\n/**\n * Interface for the input of a ChatPromptTemplate.\n */\nexport interface StructuredPromptInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n> extends ChatPromptTemplateInput<RunInput, PartialVariableName> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: Record<string, any>;\n method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\";\n}\n\nexport class StructuredPrompt<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n >\n extends ChatPromptTemplate<RunInput, PartialVariableName>\n implements StructuredPromptInput<RunInput, PartialVariableName>\n{\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: Record<string, any>;\n\n method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\";\n\n lc_namespace = [\"langchain_core\", \"prompts\", \"structured\"];\n\n get lc_aliases(): Record<string, string> {\n return {\n ...super.lc_aliases,\n schema: \"schema_\",\n };\n }\n\n constructor(input: StructuredPromptInput<RunInput, PartialVariableName>) {\n super(input);\n this.schema = input.schema;\n this.method = input.method;\n }\n\n pipe<NewRunOutput>(\n coerceable: RunnableLike<ChatPromptValueInterface, NewRunOutput>\n ): Runnable<RunInput, Exclude<NewRunOutput, Error>, RunnableConfig> {\n if (isWithStructuredOutput(coerceable)) {\n return super.pipe(coerceable.withStructuredOutput(this.schema));\n }\n\n if (\n isRunnableBinding(coerceable) &&\n isWithStructuredOutput(coerceable.bound)\n ) {\n return super.pipe(\n new RunnableBinding({\n bound: coerceable.bound.withStructuredOutput(\n this.schema,\n ...(this.method ? [{ method: this.method }] : [])\n ),\n kwargs: coerceable.kwargs ?? {},\n config: coerceable.config,\n configFactories: coerceable.configFactories,\n })\n );\n }\n\n throw new Error(\n `Structured prompts need to be piped to a language model that supports the \"withStructuredOutput()\" method.`\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static fromMessagesAndSchema<RunInput extends InputValues = any>(\n promptMessages: (\n | ChatPromptTemplate<InputValues, string>\n | BaseMessagePromptTemplateLike\n )[],\n schema: StructuredPromptInput[\"schema\"],\n method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\"\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): ChatPromptTemplate<RunInput, any> {\n return StructuredPrompt.fromMessages<\n RunInput,\n StructuredPromptInput<RunInput>\n >(promptMessages, { schema, method });\n }\n}\n"],"mappings":";;;;AAUA,SAAS,uBACPA,GAIA;AACA,QACE,OAAO,MAAM,YACb,KAAK,QACL,0BAA0B,KAC1B,OAAO,EAAE,yBAAyB;AAErC;AAED,SAAS,kBAAkBA,GAAoD;AAC7E,QACE,OAAO,MAAM,YACb,KAAK,QACL,WAAW,KACX,MAAM,QAAQ,EAAE,MAAM,IACtB,EAAE,MAAM,KAAK,IAAI,KAAK;AAEzB;AAgBD,IAAa,mBAAb,MAAa,yBAMHC,gCAEV;CAEE;CAEA;CAEA,eAAe;EAAC;EAAkB;EAAW;CAAa;CAE1D,IAAI,aAAqC;AACvC,SAAO;GACL,GAAG,MAAM;GACT,QAAQ;EACT;CACF;CAED,YAAYC,OAA6D;EACvE,MAAM,MAAM;EACZ,KAAK,SAAS,MAAM;EACpB,KAAK,SAAS,MAAM;CACrB;CAED,KACEC,YACkE;AAClE,MAAI,uBAAuB,WAAW,CACpC,QAAO,MAAM,KAAK,WAAW,qBAAqB,KAAK,OAAO,CAAC;AAGjE,MACE,kBAAkB,WAAW,IAC7B,uBAAuB,WAAW,MAAM,CAExC,QAAO,MAAM,KACX,IAAIC,6BAAgB;GAClB,OAAO,WAAW,MAAM,qBACtB,KAAK,QACL,GAAI,KAAK,SAAS,CAAC,EAAE,QAAQ,KAAK,OAAQ,CAAC,IAAG,CAAE,EACjD;GACD,QAAQ,WAAW,UAAU,CAAE;GAC/B,QAAQ,WAAW;GACnB,iBAAiB,WAAW;EAC7B,GACF;AAGH,QAAM,IAAI,MACR,CAAC,0GAA0G,CAAC;CAE/G;CAGD,OAAO,sBACLC,gBAIAC,QACAC,QAEmC;AACnC,SAAO,iBAAiB,aAGtB,gBAAgB;GAAE;GAAQ;EAAQ,EAAC;CACtC;AACF"}
1
+ {"version":3,"file":"structured.cjs","names":["x: unknown","ChatPromptTemplate","input: StructuredPromptInput<RunInput, PartialVariableName>","coerceable: RunnableLike<ChatPromptValueInterface, NewRunOutput>","RunnableBinding","promptMessages: (\n | ChatPromptTemplate<InputValues, string>\n | BaseMessagePromptTemplateLike\n )[]","schema: StructuredPromptInput[\"schema\"]","method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\""],"sources":["../../src/prompts/structured.ts"],"sourcesContent":["import { ChatPromptValueInterface } from \"../prompt_values.js\";\nimport { RunnableLike, Runnable, RunnableBinding } from \"../runnables/base.js\";\nimport { RunnableConfig } from \"../runnables/config.js\";\nimport { InputValues } from \"../utils/types/index.js\";\nimport {\n BaseMessagePromptTemplateLike,\n ChatPromptTemplate,\n ChatPromptTemplateInput,\n} from \"./chat.js\";\n\nfunction isWithStructuredOutput(x: unknown): x is {\n withStructuredOutput: (...arg: unknown[]) => Runnable;\n} {\n return (\n typeof x === \"object\" &&\n x != null &&\n \"withStructuredOutput\" in x &&\n typeof x.withStructuredOutput === \"function\"\n );\n}\n\nfunction isRunnableBinding(x: unknown): x is RunnableBinding<unknown, unknown> {\n return (\n typeof x === \"object\" &&\n x != null &&\n \"lc_id\" in x &&\n Array.isArray(x.lc_id) &&\n x.lc_id.join(\"/\") === \"langchain_core/runnables/RunnableBinding\"\n );\n}\n\n/**\n * Interface for the input of a ChatPromptTemplate.\n */\nexport interface StructuredPromptInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n> extends ChatPromptTemplateInput<RunInput, PartialVariableName> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: Record<string, any>;\n method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\";\n}\n\nexport class StructuredPrompt<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n >\n extends ChatPromptTemplate<RunInput, PartialVariableName>\n implements StructuredPromptInput<RunInput, PartialVariableName>\n{\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: Record<string, any>;\n\n method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\";\n\n lc_namespace = [\"langchain_core\", \"prompts\", \"structured\"];\n\n get lc_aliases(): Record<string, string> {\n return {\n ...super.lc_aliases,\n schema: \"schema_\",\n };\n }\n\n constructor(input: StructuredPromptInput<RunInput, PartialVariableName>) {\n super(input);\n this.schema = input.schema;\n this.method = input.method;\n }\n\n pipe<NewRunOutput>(\n coerceable: RunnableLike<ChatPromptValueInterface, NewRunOutput>\n ): Runnable<RunInput, Exclude<NewRunOutput, Error>, RunnableConfig> {\n if (isWithStructuredOutput(coerceable)) {\n return super.pipe(coerceable.withStructuredOutput(this.schema));\n }\n\n if (\n isRunnableBinding(coerceable) &&\n isWithStructuredOutput(coerceable.bound)\n ) {\n return super.pipe(\n new RunnableBinding({\n bound: coerceable.bound.withStructuredOutput(\n this.schema,\n ...(this.method ? [{ method: this.method }] : [])\n ),\n kwargs: coerceable.kwargs ?? {},\n config: coerceable.config,\n configFactories: coerceable.configFactories,\n })\n );\n }\n\n throw new Error(\n `Structured prompts need to be piped to a language model that supports the \"withStructuredOutput()\" method.`\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static fromMessagesAndSchema<RunInput extends InputValues = any>(\n promptMessages: (\n | ChatPromptTemplate<InputValues, string>\n | BaseMessagePromptTemplateLike\n )[],\n schema: StructuredPromptInput[\"schema\"],\n method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\"\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): ChatPromptTemplate<RunInput, any> {\n return StructuredPrompt.fromMessages<\n RunInput,\n StructuredPromptInput<RunInput>\n >(promptMessages, { schema, method });\n }\n}\n"],"mappings":";;;;AAUA,SAAS,uBAAuBA,GAE9B;AACA,QACE,OAAO,MAAM,YACb,KAAK,QACL,0BAA0B,KAC1B,OAAO,EAAE,yBAAyB;AAErC;AAED,SAAS,kBAAkBA,GAAoD;AAC7E,QACE,OAAO,MAAM,YACb,KAAK,QACL,WAAW,KACX,MAAM,QAAQ,EAAE,MAAM,IACtB,EAAE,MAAM,KAAK,IAAI,KAAK;AAEzB;AAgBD,IAAa,mBAAb,MAAa,yBAMHC,gCAEV;CAEE;CAEA;CAEA,eAAe;EAAC;EAAkB;EAAW;CAAa;CAE1D,IAAI,aAAqC;AACvC,SAAO;GACL,GAAG,MAAM;GACT,QAAQ;EACT;CACF;CAED,YAAYC,OAA6D;EACvE,MAAM,MAAM;EACZ,KAAK,SAAS,MAAM;EACpB,KAAK,SAAS,MAAM;CACrB;CAED,KACEC,YACkE;AAClE,MAAI,uBAAuB,WAAW,CACpC,QAAO,MAAM,KAAK,WAAW,qBAAqB,KAAK,OAAO,CAAC;AAGjE,MACE,kBAAkB,WAAW,IAC7B,uBAAuB,WAAW,MAAM,CAExC,QAAO,MAAM,KACX,IAAIC,6BAAgB;GAClB,OAAO,WAAW,MAAM,qBACtB,KAAK,QACL,GAAI,KAAK,SAAS,CAAC,EAAE,QAAQ,KAAK,OAAQ,CAAC,IAAG,CAAE,EACjD;GACD,QAAQ,WAAW,UAAU,CAAE;GAC/B,QAAQ,WAAW;GACnB,iBAAiB,WAAW;EAC7B,GACF;AAGH,QAAM,IAAI,MACR,CAAC,0GAA0G,CAAC;CAE/G;CAGD,OAAO,sBACLC,gBAIAC,QACAC,QAEmC;AACnC,SAAO,iBAAiB,aAGtB,gBAAgB;GAAE;GAAQ;EAAQ,EAAC;CACtC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"structured.js","names":["x: unknown","input: StructuredPromptInput<RunInput, PartialVariableName>","coerceable: RunnableLike<ChatPromptValueInterface, NewRunOutput>","promptMessages: (\n | ChatPromptTemplate<InputValues, string>\n | BaseMessagePromptTemplateLike\n )[]","schema: StructuredPromptInput[\"schema\"]","method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\""],"sources":["../../src/prompts/structured.ts"],"sourcesContent":["import { ChatPromptValueInterface } from \"../prompt_values.js\";\nimport { RunnableLike, Runnable, RunnableBinding } from \"../runnables/base.js\";\nimport { RunnableConfig } from \"../runnables/config.js\";\nimport { InputValues } from \"../utils/types/index.js\";\nimport {\n BaseMessagePromptTemplateLike,\n ChatPromptTemplate,\n ChatPromptTemplateInput,\n} from \"./chat.js\";\n\nfunction isWithStructuredOutput(\n x: unknown\n // eslint-disable-next-line @typescript-eslint/ban-types\n): x is {\n withStructuredOutput: (...arg: unknown[]) => Runnable;\n} {\n return (\n typeof x === \"object\" &&\n x != null &&\n \"withStructuredOutput\" in x &&\n typeof x.withStructuredOutput === \"function\"\n );\n}\n\nfunction isRunnableBinding(x: unknown): x is RunnableBinding<unknown, unknown> {\n return (\n typeof x === \"object\" &&\n x != null &&\n \"lc_id\" in x &&\n Array.isArray(x.lc_id) &&\n x.lc_id.join(\"/\") === \"langchain_core/runnables/RunnableBinding\"\n );\n}\n\n/**\n * Interface for the input of a ChatPromptTemplate.\n */\nexport interface StructuredPromptInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n> extends ChatPromptTemplateInput<RunInput, PartialVariableName> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: Record<string, any>;\n method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\";\n}\n\nexport class StructuredPrompt<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n >\n extends ChatPromptTemplate<RunInput, PartialVariableName>\n implements StructuredPromptInput<RunInput, PartialVariableName>\n{\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: Record<string, any>;\n\n method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\";\n\n lc_namespace = [\"langchain_core\", \"prompts\", \"structured\"];\n\n get lc_aliases(): Record<string, string> {\n return {\n ...super.lc_aliases,\n schema: \"schema_\",\n };\n }\n\n constructor(input: StructuredPromptInput<RunInput, PartialVariableName>) {\n super(input);\n this.schema = input.schema;\n this.method = input.method;\n }\n\n pipe<NewRunOutput>(\n coerceable: RunnableLike<ChatPromptValueInterface, NewRunOutput>\n ): Runnable<RunInput, Exclude<NewRunOutput, Error>, RunnableConfig> {\n if (isWithStructuredOutput(coerceable)) {\n return super.pipe(coerceable.withStructuredOutput(this.schema));\n }\n\n if (\n isRunnableBinding(coerceable) &&\n isWithStructuredOutput(coerceable.bound)\n ) {\n return super.pipe(\n new RunnableBinding({\n bound: coerceable.bound.withStructuredOutput(\n this.schema,\n ...(this.method ? [{ method: this.method }] : [])\n ),\n kwargs: coerceable.kwargs ?? {},\n config: coerceable.config,\n configFactories: coerceable.configFactories,\n })\n );\n }\n\n throw new Error(\n `Structured prompts need to be piped to a language model that supports the \"withStructuredOutput()\" method.`\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static fromMessagesAndSchema<RunInput extends InputValues = any>(\n promptMessages: (\n | ChatPromptTemplate<InputValues, string>\n | BaseMessagePromptTemplateLike\n )[],\n schema: StructuredPromptInput[\"schema\"],\n method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\"\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): ChatPromptTemplate<RunInput, any> {\n return StructuredPrompt.fromMessages<\n RunInput,\n StructuredPromptInput<RunInput>\n >(promptMessages, { schema, method });\n }\n}\n"],"mappings":";;;;AAUA,SAAS,uBACPA,GAIA;AACA,QACE,OAAO,MAAM,YACb,KAAK,QACL,0BAA0B,KAC1B,OAAO,EAAE,yBAAyB;AAErC;AAED,SAAS,kBAAkBA,GAAoD;AAC7E,QACE,OAAO,MAAM,YACb,KAAK,QACL,WAAW,KACX,MAAM,QAAQ,EAAE,MAAM,IACtB,EAAE,MAAM,KAAK,IAAI,KAAK;AAEzB;AAgBD,IAAa,mBAAb,MAAa,yBAMH,mBAEV;CAEE;CAEA;CAEA,eAAe;EAAC;EAAkB;EAAW;CAAa;CAE1D,IAAI,aAAqC;AACvC,SAAO;GACL,GAAG,MAAM;GACT,QAAQ;EACT;CACF;CAED,YAAYC,OAA6D;EACvE,MAAM,MAAM;EACZ,KAAK,SAAS,MAAM;EACpB,KAAK,SAAS,MAAM;CACrB;CAED,KACEC,YACkE;AAClE,MAAI,uBAAuB,WAAW,CACpC,QAAO,MAAM,KAAK,WAAW,qBAAqB,KAAK,OAAO,CAAC;AAGjE,MACE,kBAAkB,WAAW,IAC7B,uBAAuB,WAAW,MAAM,CAExC,QAAO,MAAM,KACX,IAAI,gBAAgB;GAClB,OAAO,WAAW,MAAM,qBACtB,KAAK,QACL,GAAI,KAAK,SAAS,CAAC,EAAE,QAAQ,KAAK,OAAQ,CAAC,IAAG,CAAE,EACjD;GACD,QAAQ,WAAW,UAAU,CAAE;GAC/B,QAAQ,WAAW;GACnB,iBAAiB,WAAW;EAC7B,GACF;AAGH,QAAM,IAAI,MACR,CAAC,0GAA0G,CAAC;CAE/G;CAGD,OAAO,sBACLC,gBAIAC,QACAC,QAEmC;AACnC,SAAO,iBAAiB,aAGtB,gBAAgB;GAAE;GAAQ;EAAQ,EAAC;CACtC;AACF"}
1
+ {"version":3,"file":"structured.js","names":["x: unknown","input: StructuredPromptInput<RunInput, PartialVariableName>","coerceable: RunnableLike<ChatPromptValueInterface, NewRunOutput>","promptMessages: (\n | ChatPromptTemplate<InputValues, string>\n | BaseMessagePromptTemplateLike\n )[]","schema: StructuredPromptInput[\"schema\"]","method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\""],"sources":["../../src/prompts/structured.ts"],"sourcesContent":["import { ChatPromptValueInterface } from \"../prompt_values.js\";\nimport { RunnableLike, Runnable, RunnableBinding } from \"../runnables/base.js\";\nimport { RunnableConfig } from \"../runnables/config.js\";\nimport { InputValues } from \"../utils/types/index.js\";\nimport {\n BaseMessagePromptTemplateLike,\n ChatPromptTemplate,\n ChatPromptTemplateInput,\n} from \"./chat.js\";\n\nfunction isWithStructuredOutput(x: unknown): x is {\n withStructuredOutput: (...arg: unknown[]) => Runnable;\n} {\n return (\n typeof x === \"object\" &&\n x != null &&\n \"withStructuredOutput\" in x &&\n typeof x.withStructuredOutput === \"function\"\n );\n}\n\nfunction isRunnableBinding(x: unknown): x is RunnableBinding<unknown, unknown> {\n return (\n typeof x === \"object\" &&\n x != null &&\n \"lc_id\" in x &&\n Array.isArray(x.lc_id) &&\n x.lc_id.join(\"/\") === \"langchain_core/runnables/RunnableBinding\"\n );\n}\n\n/**\n * Interface for the input of a ChatPromptTemplate.\n */\nexport interface StructuredPromptInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n> extends ChatPromptTemplateInput<RunInput, PartialVariableName> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: Record<string, any>;\n method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\";\n}\n\nexport class StructuredPrompt<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n >\n extends ChatPromptTemplate<RunInput, PartialVariableName>\n implements StructuredPromptInput<RunInput, PartialVariableName>\n{\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: Record<string, any>;\n\n method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\";\n\n lc_namespace = [\"langchain_core\", \"prompts\", \"structured\"];\n\n get lc_aliases(): Record<string, string> {\n return {\n ...super.lc_aliases,\n schema: \"schema_\",\n };\n }\n\n constructor(input: StructuredPromptInput<RunInput, PartialVariableName>) {\n super(input);\n this.schema = input.schema;\n this.method = input.method;\n }\n\n pipe<NewRunOutput>(\n coerceable: RunnableLike<ChatPromptValueInterface, NewRunOutput>\n ): Runnable<RunInput, Exclude<NewRunOutput, Error>, RunnableConfig> {\n if (isWithStructuredOutput(coerceable)) {\n return super.pipe(coerceable.withStructuredOutput(this.schema));\n }\n\n if (\n isRunnableBinding(coerceable) &&\n isWithStructuredOutput(coerceable.bound)\n ) {\n return super.pipe(\n new RunnableBinding({\n bound: coerceable.bound.withStructuredOutput(\n this.schema,\n ...(this.method ? [{ method: this.method }] : [])\n ),\n kwargs: coerceable.kwargs ?? {},\n config: coerceable.config,\n configFactories: coerceable.configFactories,\n })\n );\n }\n\n throw new Error(\n `Structured prompts need to be piped to a language model that supports the \"withStructuredOutput()\" method.`\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static fromMessagesAndSchema<RunInput extends InputValues = any>(\n promptMessages: (\n | ChatPromptTemplate<InputValues, string>\n | BaseMessagePromptTemplateLike\n )[],\n schema: StructuredPromptInput[\"schema\"],\n method?: \"jsonMode\" | \"jsonSchema\" | \"functionMode\"\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): ChatPromptTemplate<RunInput, any> {\n return StructuredPrompt.fromMessages<\n RunInput,\n StructuredPromptInput<RunInput>\n >(promptMessages, { schema, method });\n }\n}\n"],"mappings":";;;;AAUA,SAAS,uBAAuBA,GAE9B;AACA,QACE,OAAO,MAAM,YACb,KAAK,QACL,0BAA0B,KAC1B,OAAO,EAAE,yBAAyB;AAErC;AAED,SAAS,kBAAkBA,GAAoD;AAC7E,QACE,OAAO,MAAM,YACb,KAAK,QACL,WAAW,KACX,MAAM,QAAQ,EAAE,MAAM,IACtB,EAAE,MAAM,KAAK,IAAI,KAAK;AAEzB;AAgBD,IAAa,mBAAb,MAAa,yBAMH,mBAEV;CAEE;CAEA;CAEA,eAAe;EAAC;EAAkB;EAAW;CAAa;CAE1D,IAAI,aAAqC;AACvC,SAAO;GACL,GAAG,MAAM;GACT,QAAQ;EACT;CACF;CAED,YAAYC,OAA6D;EACvE,MAAM,MAAM;EACZ,KAAK,SAAS,MAAM;EACpB,KAAK,SAAS,MAAM;CACrB;CAED,KACEC,YACkE;AAClE,MAAI,uBAAuB,WAAW,CACpC,QAAO,MAAM,KAAK,WAAW,qBAAqB,KAAK,OAAO,CAAC;AAGjE,MACE,kBAAkB,WAAW,IAC7B,uBAAuB,WAAW,MAAM,CAExC,QAAO,MAAM,KACX,IAAI,gBAAgB;GAClB,OAAO,WAAW,MAAM,qBACtB,KAAK,QACL,GAAI,KAAK,SAAS,CAAC,EAAE,QAAQ,KAAK,OAAQ,CAAC,IAAG,CAAE,EACjD;GACD,QAAQ,WAAW,UAAU,CAAE;GAC/B,QAAQ,WAAW;GACnB,iBAAiB,WAAW;EAC7B,GACF;AAGH,QAAM,IAAI,MACR,CAAC,0GAA0G,CAAC;CAE/G;CAGD,OAAO,sBACLC,gBAIAC,QACAC,QAEmC;AACnC,SAAO,iBAAiB,aAGtB,gBAAgB;GAAE;GAAQ;EAAQ,EAAC;CACtC;AACF"}
@@ -51,9 +51,10 @@ const parseFString = (template) => {
51
51
  * to make it compatible with other LangChain string parsing template formats.
52
52
  *
53
53
  * @param {mustache.TemplateSpans} template The result of parsing a mustache template with the mustache.js library.
54
+ * @param {string[]} context Array of section variable names for nested context
54
55
  * @returns {ParsedTemplateNode[]}
55
56
  */
56
- const mustacheTemplateToNodes = (template) => {
57
+ const mustacheTemplateToNodes = (template, context = []) => {
57
58
  const nodes = [];
58
59
  for (const temp of template) if (temp[0] === "name") {
59
60
  const name = temp[1].includes(".") ? temp[1].split(".")[0] : temp[1];
@@ -72,7 +73,8 @@ const mustacheTemplateToNodes = (template) => {
72
73
  name: temp[1]
73
74
  });
74
75
  if (temp[0] === "#" && temp.length > 4 && Array.isArray(temp[4])) {
75
- const nestedNodes = mustacheTemplateToNodes(temp[4]);
76
+ const newContext = [...context, temp[1]];
77
+ const nestedNodes = mustacheTemplateToNodes(temp[4], newContext);
76
78
  nodes.push(...nestedNodes);
77
79
  }
78
80
  } else nodes.push({