@langchain/core 1.1.24 → 1.1.25

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 (1103) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/_virtual/_rolldown/runtime.cjs +43 -0
  3. package/dist/_virtual/_rolldown/runtime.js +18 -0
  4. package/dist/agents.cjs +3 -1
  5. package/dist/agents.d.cts.map +1 -1
  6. package/dist/agents.d.ts.map +1 -1
  7. package/dist/agents.js +3 -1
  8. package/dist/caches/index.cjs +4 -4
  9. package/dist/caches/index.cjs.map +1 -1
  10. package/dist/caches/index.d.cts.map +1 -1
  11. package/dist/caches/index.d.ts.map +1 -1
  12. package/dist/caches/index.js +3 -4
  13. package/dist/caches/index.js.map +1 -1
  14. package/dist/callbacks/base.cjs +9 -16
  15. package/dist/callbacks/base.cjs.map +1 -1
  16. package/dist/callbacks/base.d.cts +1 -0
  17. package/dist/callbacks/base.d.cts.map +1 -1
  18. package/dist/callbacks/base.d.ts +1 -0
  19. package/dist/callbacks/base.d.ts.map +1 -1
  20. package/dist/callbacks/base.js +6 -15
  21. package/dist/callbacks/base.js.map +1 -1
  22. package/dist/callbacks/dispatch/index.cjs +6 -6
  23. package/dist/callbacks/dispatch/index.cjs.map +1 -1
  24. package/dist/callbacks/dispatch/index.d.cts +0 -1
  25. package/dist/callbacks/dispatch/index.d.cts.map +1 -1
  26. package/dist/callbacks/dispatch/index.d.ts +0 -1
  27. package/dist/callbacks/dispatch/index.d.ts.map +1 -1
  28. package/dist/callbacks/dispatch/index.js +4 -5
  29. package/dist/callbacks/dispatch/index.js.map +1 -1
  30. package/dist/callbacks/dispatch/web.cjs +1 -0
  31. package/dist/callbacks/dispatch/web.cjs.map +1 -1
  32. package/dist/callbacks/dispatch/web.d.cts +0 -1
  33. package/dist/callbacks/dispatch/web.d.cts.map +1 -1
  34. package/dist/callbacks/dispatch/web.d.ts +0 -1
  35. package/dist/callbacks/dispatch/web.d.ts.map +1 -1
  36. package/dist/callbacks/dispatch/web.js.map +1 -1
  37. package/dist/callbacks/manager.cjs +30 -50
  38. package/dist/callbacks/manager.cjs.map +1 -1
  39. package/dist/callbacks/manager.d.cts.map +1 -1
  40. package/dist/callbacks/manager.d.ts.map +1 -1
  41. package/dist/callbacks/manager.js +28 -49
  42. package/dist/callbacks/manager.js.map +1 -1
  43. package/dist/callbacks/promises.cjs +3 -3
  44. package/dist/callbacks/promises.js +2 -3
  45. package/dist/chat_history.cjs +4 -4
  46. package/dist/chat_history.cjs.map +1 -1
  47. package/dist/chat_history.d.cts +0 -1
  48. package/dist/chat_history.d.cts.map +1 -1
  49. package/dist/chat_history.d.ts +0 -1
  50. package/dist/chat_history.d.ts.map +1 -1
  51. package/dist/chat_history.js +3 -4
  52. package/dist/chat_history.js.map +1 -1
  53. package/dist/context.cjs +10 -2
  54. package/dist/context.cjs.map +1 -1
  55. package/dist/context.d.cts.map +1 -1
  56. package/dist/context.d.ts.map +1 -1
  57. package/dist/context.js +7 -0
  58. package/dist/context.js.map +1 -1
  59. package/dist/document_loaders/base.cjs +3 -3
  60. package/dist/document_loaders/base.cjs.map +1 -1
  61. package/dist/document_loaders/base.d.cts +0 -1
  62. package/dist/document_loaders/base.d.cts.map +1 -1
  63. package/dist/document_loaders/base.d.ts +0 -1
  64. package/dist/document_loaders/base.d.ts.map +1 -1
  65. package/dist/document_loaders/base.js +2 -3
  66. package/dist/document_loaders/base.js.map +1 -1
  67. package/dist/document_loaders/langsmith.cjs +4 -4
  68. package/dist/document_loaders/langsmith.cjs.map +1 -1
  69. package/dist/document_loaders/langsmith.d.cts.map +1 -1
  70. package/dist/document_loaders/langsmith.d.ts.map +1 -1
  71. package/dist/document_loaders/langsmith.js +2 -3
  72. package/dist/document_loaders/langsmith.js.map +1 -1
  73. package/dist/documents/document.cjs.map +1 -1
  74. package/dist/documents/document.d.cts.map +1 -1
  75. package/dist/documents/document.d.ts.map +1 -1
  76. package/dist/documents/document.js.map +1 -1
  77. package/dist/documents/index.cjs +3 -3
  78. package/dist/documents/index.js +2 -3
  79. package/dist/documents/transformers.cjs.map +1 -1
  80. package/dist/documents/transformers.d.cts +0 -1
  81. package/dist/documents/transformers.d.cts.map +1 -1
  82. package/dist/documents/transformers.d.ts +0 -1
  83. package/dist/documents/transformers.d.ts.map +1 -1
  84. package/dist/documents/transformers.js.map +1 -1
  85. package/dist/embeddings.cjs +3 -3
  86. package/dist/embeddings.cjs.map +1 -1
  87. package/dist/embeddings.d.cts +0 -1
  88. package/dist/embeddings.d.cts.map +1 -1
  89. package/dist/embeddings.d.ts +0 -1
  90. package/dist/embeddings.d.ts.map +1 -1
  91. package/dist/embeddings.js +2 -3
  92. package/dist/embeddings.js.map +1 -1
  93. package/dist/errors/index.cjs +141 -15
  94. package/dist/errors/index.cjs.map +1 -1
  95. package/dist/errors/index.d.cts +134 -11
  96. package/dist/errors/index.d.cts.map +1 -1
  97. package/dist/errors/index.d.ts +134 -11
  98. package/dist/errors/index.d.ts.map +1 -1
  99. package/dist/errors/index.js +138 -16
  100. package/dist/errors/index.js.map +1 -1
  101. package/dist/example_selectors/base.cjs.map +1 -1
  102. package/dist/example_selectors/base.d.cts +0 -1
  103. package/dist/example_selectors/base.d.cts.map +1 -1
  104. package/dist/example_selectors/base.d.ts +0 -1
  105. package/dist/example_selectors/base.d.ts.map +1 -1
  106. package/dist/example_selectors/base.js.map +1 -1
  107. package/dist/example_selectors/conditional.cjs +1 -2
  108. package/dist/example_selectors/conditional.cjs.map +1 -1
  109. package/dist/example_selectors/conditional.d.cts.map +1 -1
  110. package/dist/example_selectors/conditional.d.ts.map +1 -1
  111. package/dist/example_selectors/conditional.js +1 -2
  112. package/dist/example_selectors/conditional.js.map +1 -1
  113. package/dist/example_selectors/index.cjs +3 -3
  114. package/dist/example_selectors/index.js +2 -3
  115. package/dist/example_selectors/length_based.cjs +1 -2
  116. package/dist/example_selectors/length_based.cjs.map +1 -1
  117. package/dist/example_selectors/length_based.d.cts +0 -1
  118. package/dist/example_selectors/length_based.d.cts.map +1 -1
  119. package/dist/example_selectors/length_based.d.ts +0 -1
  120. package/dist/example_selectors/length_based.d.ts.map +1 -1
  121. package/dist/example_selectors/length_based.js +1 -2
  122. package/dist/example_selectors/length_based.js.map +1 -1
  123. package/dist/example_selectors/semantic_similarity.cjs +4 -8
  124. package/dist/example_selectors/semantic_similarity.cjs.map +1 -1
  125. package/dist/example_selectors/semantic_similarity.d.cts +0 -1
  126. package/dist/example_selectors/semantic_similarity.d.cts.map +1 -1
  127. package/dist/example_selectors/semantic_similarity.d.ts +0 -1
  128. package/dist/example_selectors/semantic_similarity.d.ts.map +1 -1
  129. package/dist/example_selectors/semantic_similarity.js +4 -8
  130. package/dist/example_selectors/semantic_similarity.js.map +1 -1
  131. package/dist/index.cjs +3 -1
  132. package/dist/index.js +3 -1
  133. package/dist/indexing/base.cjs +7 -11
  134. package/dist/indexing/base.cjs.map +1 -1
  135. package/dist/indexing/base.d.cts.map +1 -1
  136. package/dist/indexing/base.d.ts.map +1 -1
  137. package/dist/indexing/base.js +5 -9
  138. package/dist/indexing/base.js.map +1 -1
  139. package/dist/indexing/index.cjs +3 -3
  140. package/dist/indexing/index.js +2 -3
  141. package/dist/indexing/record_manager.cjs.map +1 -1
  142. package/dist/indexing/record_manager.d.cts.map +1 -1
  143. package/dist/indexing/record_manager.d.ts.map +1 -1
  144. package/dist/indexing/record_manager.js.map +1 -1
  145. package/dist/language_models/base.cjs +10 -14
  146. package/dist/language_models/base.cjs.map +1 -1
  147. package/dist/language_models/base.d.cts +2 -4
  148. package/dist/language_models/base.d.cts.map +1 -1
  149. package/dist/language_models/base.d.ts +2 -4
  150. package/dist/language_models/base.d.ts.map +1 -1
  151. package/dist/language_models/base.js +9 -14
  152. package/dist/language_models/base.js.map +1 -1
  153. package/dist/language_models/chat_models.cjs +19 -25
  154. package/dist/language_models/chat_models.cjs.map +1 -1
  155. package/dist/language_models/chat_models.d.cts.map +1 -1
  156. package/dist/language_models/chat_models.d.ts.map +1 -1
  157. package/dist/language_models/chat_models.js +18 -25
  158. package/dist/language_models/chat_models.js.map +1 -1
  159. package/dist/language_models/llms.cjs +12 -15
  160. package/dist/language_models/llms.cjs.map +1 -1
  161. package/dist/language_models/llms.d.cts.map +1 -1
  162. package/dist/language_models/llms.d.ts.map +1 -1
  163. package/dist/language_models/llms.js +11 -15
  164. package/dist/language_models/llms.js.map +1 -1
  165. package/dist/language_models/profile.cjs +3 -1
  166. package/dist/language_models/profile.d.cts.map +1 -1
  167. package/dist/language_models/profile.d.ts.map +1 -1
  168. package/dist/language_models/profile.js +3 -1
  169. package/dist/language_models/utils.cjs.map +1 -1
  170. package/dist/language_models/utils.js.map +1 -1
  171. package/dist/load/import_constants.cjs.map +1 -1
  172. package/dist/load/import_constants.js.map +1 -1
  173. package/dist/load/import_map.cjs +13 -14
  174. package/dist/load/import_map.js +13 -14
  175. package/dist/load/import_type.d.cts.map +1 -1
  176. package/dist/load/import_type.d.ts.map +1 -1
  177. package/dist/load/index.cjs +74 -13
  178. package/dist/load/index.cjs.map +1 -1
  179. package/dist/load/index.d.cts +13 -4
  180. package/dist/load/index.d.cts.map +1 -1
  181. package/dist/load/index.d.ts +13 -4
  182. package/dist/load/index.d.ts.map +1 -1
  183. package/dist/load/index.js +68 -8
  184. package/dist/load/index.js.map +1 -1
  185. package/dist/load/map_keys.cjs +5 -3
  186. package/dist/load/map_keys.cjs.map +1 -1
  187. package/dist/load/map_keys.d.cts.map +1 -1
  188. package/dist/load/map_keys.d.ts.map +1 -1
  189. package/dist/load/map_keys.js.map +1 -1
  190. package/dist/load/serializable.cjs +9 -19
  191. package/dist/load/serializable.cjs.map +1 -1
  192. package/dist/load/serializable.d.cts.map +1 -1
  193. package/dist/load/serializable.d.ts.map +1 -1
  194. package/dist/load/serializable.js +8 -19
  195. package/dist/load/serializable.js.map +1 -1
  196. package/dist/load/validation.cjs.map +1 -1
  197. package/dist/load/validation.js.map +1 -1
  198. package/dist/memory.cjs +3 -3
  199. package/dist/memory.cjs.map +1 -1
  200. package/dist/memory.d.cts.map +1 -1
  201. package/dist/memory.d.ts.map +1 -1
  202. package/dist/memory.js +2 -3
  203. package/dist/memory.js.map +1 -1
  204. package/dist/messages/ai.cjs.map +1 -1
  205. package/dist/messages/ai.d.cts.map +1 -1
  206. package/dist/messages/ai.d.ts.map +1 -1
  207. package/dist/messages/ai.js.map +1 -1
  208. package/dist/messages/base.cjs +10 -12
  209. package/dist/messages/base.cjs.map +1 -1
  210. package/dist/messages/base.d.cts +6 -3
  211. package/dist/messages/base.d.cts.map +1 -1
  212. package/dist/messages/base.d.ts +6 -3
  213. package/dist/messages/base.d.ts.map +1 -1
  214. package/dist/messages/base.js +10 -12
  215. package/dist/messages/base.js.map +1 -1
  216. package/dist/messages/block_translators/anthropic.cjs +30 -35
  217. package/dist/messages/block_translators/anthropic.cjs.map +1 -1
  218. package/dist/messages/block_translators/anthropic.js +30 -35
  219. package/dist/messages/block_translators/anthropic.js.map +1 -1
  220. package/dist/messages/block_translators/bedrock_converse.cjs +38 -46
  221. package/dist/messages/block_translators/bedrock_converse.cjs.map +1 -1
  222. package/dist/messages/block_translators/bedrock_converse.js +38 -46
  223. package/dist/messages/block_translators/bedrock_converse.js.map +1 -1
  224. package/dist/messages/block_translators/data.cjs.map +1 -1
  225. package/dist/messages/block_translators/data.js.map +1 -1
  226. package/dist/messages/block_translators/deepseek.cjs.map +1 -1
  227. package/dist/messages/block_translators/deepseek.js.map +1 -1
  228. package/dist/messages/block_translators/google.cjs +6 -9
  229. package/dist/messages/block_translators/google.cjs.map +1 -1
  230. package/dist/messages/block_translators/google.js +6 -9
  231. package/dist/messages/block_translators/google.js.map +1 -1
  232. package/dist/messages/block_translators/google_genai.cjs.map +1 -1
  233. package/dist/messages/block_translators/google_genai.js.map +1 -1
  234. package/dist/messages/block_translators/google_vertexai.cjs +1 -3
  235. package/dist/messages/block_translators/google_vertexai.cjs.map +1 -1
  236. package/dist/messages/block_translators/google_vertexai.js +1 -3
  237. package/dist/messages/block_translators/google_vertexai.js.map +1 -1
  238. package/dist/messages/block_translators/groq.cjs.map +1 -1
  239. package/dist/messages/block_translators/groq.js.map +1 -1
  240. package/dist/messages/block_translators/index.cjs.map +1 -1
  241. package/dist/messages/block_translators/index.js.map +1 -1
  242. package/dist/messages/block_translators/ollama.cjs.map +1 -1
  243. package/dist/messages/block_translators/ollama.js.map +1 -1
  244. package/dist/messages/block_translators/openai.cjs +6 -10
  245. package/dist/messages/block_translators/openai.cjs.map +1 -1
  246. package/dist/messages/block_translators/openai.js +6 -10
  247. package/dist/messages/block_translators/openai.js.map +1 -1
  248. package/dist/messages/block_translators/utils.cjs +1 -1
  249. package/dist/messages/block_translators/utils.cjs.map +1 -1
  250. package/dist/messages/block_translators/utils.js +1 -1
  251. package/dist/messages/block_translators/utils.js.map +1 -1
  252. package/dist/messages/block_translators/xai.cjs.map +1 -1
  253. package/dist/messages/block_translators/xai.js.map +1 -1
  254. package/dist/messages/chat.cjs.map +1 -1
  255. package/dist/messages/chat.d.cts.map +1 -1
  256. package/dist/messages/chat.d.ts.map +1 -1
  257. package/dist/messages/chat.js.map +1 -1
  258. package/dist/messages/content/base.d.cts.map +1 -1
  259. package/dist/messages/content/base.d.ts.map +1 -1
  260. package/dist/messages/content/data.cjs +1 -3
  261. package/dist/messages/content/data.cjs.map +1 -1
  262. package/dist/messages/content/data.d.cts +0 -1
  263. package/dist/messages/content/data.d.cts.map +1 -1
  264. package/dist/messages/content/data.d.ts +0 -1
  265. package/dist/messages/content/data.d.ts.map +1 -1
  266. package/dist/messages/content/data.js +1 -3
  267. package/dist/messages/content/data.js.map +1 -1
  268. package/dist/messages/content/index.cjs +2 -2
  269. package/dist/messages/content/index.cjs.map +1 -1
  270. package/dist/messages/content/index.d.cts.map +1 -1
  271. package/dist/messages/content/index.d.ts.map +1 -1
  272. package/dist/messages/content/index.js +6 -6
  273. package/dist/messages/content/index.js.map +1 -1
  274. package/dist/messages/content/multimodal.cjs.map +1 -1
  275. package/dist/messages/content/multimodal.d.cts +4 -8
  276. package/dist/messages/content/multimodal.d.cts.map +1 -1
  277. package/dist/messages/content/multimodal.d.ts +4 -8
  278. package/dist/messages/content/multimodal.d.ts.map +1 -1
  279. package/dist/messages/content/multimodal.js.map +1 -1
  280. package/dist/messages/content/tools.cjs.map +1 -1
  281. package/dist/messages/content/tools.d.cts.map +1 -1
  282. package/dist/messages/content/tools.d.ts.map +1 -1
  283. package/dist/messages/content/tools.js.map +1 -1
  284. package/dist/messages/format.cjs.map +1 -1
  285. package/dist/messages/format.d.cts.map +1 -1
  286. package/dist/messages/format.d.ts.map +1 -1
  287. package/dist/messages/format.js.map +1 -1
  288. package/dist/messages/function.cjs.map +1 -1
  289. package/dist/messages/function.d.cts.map +1 -1
  290. package/dist/messages/function.d.ts.map +1 -1
  291. package/dist/messages/function.js.map +1 -1
  292. package/dist/messages/human.cjs.map +1 -1
  293. package/dist/messages/human.d.cts.map +1 -1
  294. package/dist/messages/human.d.ts.map +1 -1
  295. package/dist/messages/human.js.map +1 -1
  296. package/dist/messages/index.cjs +4 -4
  297. package/dist/messages/index.js +3 -4
  298. package/dist/messages/message.cjs.map +1 -1
  299. package/dist/messages/message.d.cts +13 -24
  300. package/dist/messages/message.d.cts.map +1 -1
  301. package/dist/messages/message.d.ts +13 -24
  302. package/dist/messages/message.d.ts.map +1 -1
  303. package/dist/messages/message.js.map +1 -1
  304. package/dist/messages/metadata.cjs +1 -2
  305. package/dist/messages/metadata.cjs.map +1 -1
  306. package/dist/messages/metadata.d.cts.map +1 -1
  307. package/dist/messages/metadata.d.ts.map +1 -1
  308. package/dist/messages/metadata.js +1 -2
  309. package/dist/messages/metadata.js.map +1 -1
  310. package/dist/messages/modifier.cjs.map +1 -1
  311. package/dist/messages/modifier.d.cts.map +1 -1
  312. package/dist/messages/modifier.d.ts.map +1 -1
  313. package/dist/messages/modifier.js.map +1 -1
  314. package/dist/messages/system.cjs.map +1 -1
  315. package/dist/messages/system.d.cts.map +1 -1
  316. package/dist/messages/system.d.ts.map +1 -1
  317. package/dist/messages/system.js.map +1 -1
  318. package/dist/messages/tool.cjs +3 -3
  319. package/dist/messages/tool.cjs.map +1 -1
  320. package/dist/messages/tool.d.cts.map +1 -1
  321. package/dist/messages/tool.d.ts.map +1 -1
  322. package/dist/messages/tool.js +2 -3
  323. package/dist/messages/tool.js.map +1 -1
  324. package/dist/messages/transformers.cjs +8 -14
  325. package/dist/messages/transformers.cjs.map +1 -1
  326. package/dist/messages/transformers.d.cts.map +1 -1
  327. package/dist/messages/transformers.d.ts.map +1 -1
  328. package/dist/messages/transformers.js +8 -14
  329. package/dist/messages/transformers.js.map +1 -1
  330. package/dist/messages/utils.cjs +11 -14
  331. package/dist/messages/utils.cjs.map +1 -1
  332. package/dist/messages/utils.d.cts +7 -7
  333. package/dist/messages/utils.d.cts.map +1 -1
  334. package/dist/messages/utils.d.ts +7 -7
  335. package/dist/messages/utils.d.ts.map +1 -1
  336. package/dist/messages/utils.js +11 -14
  337. package/dist/messages/utils.js.map +1 -1
  338. package/dist/output_parsers/base.cjs +5 -5
  339. package/dist/output_parsers/base.cjs.map +1 -1
  340. package/dist/output_parsers/base.d.cts.map +1 -1
  341. package/dist/output_parsers/base.d.ts.map +1 -1
  342. package/dist/output_parsers/base.js +5 -5
  343. package/dist/output_parsers/base.js.map +1 -1
  344. package/dist/output_parsers/bytes.cjs.map +1 -1
  345. package/dist/output_parsers/bytes.d.cts +0 -1
  346. package/dist/output_parsers/bytes.d.cts.map +1 -1
  347. package/dist/output_parsers/bytes.d.ts +0 -1
  348. package/dist/output_parsers/bytes.d.ts.map +1 -1
  349. package/dist/output_parsers/bytes.js.map +1 -1
  350. package/dist/output_parsers/index.cjs +3 -3
  351. package/dist/output_parsers/index.js +2 -3
  352. package/dist/output_parsers/json.cjs +1 -1
  353. package/dist/output_parsers/json.cjs.map +1 -1
  354. package/dist/output_parsers/json.d.cts +0 -1
  355. package/dist/output_parsers/json.d.cts.map +1 -1
  356. package/dist/output_parsers/json.d.ts.map +1 -1
  357. package/dist/output_parsers/json.js +1 -1
  358. package/dist/output_parsers/json.js.map +1 -1
  359. package/dist/output_parsers/list.cjs.map +1 -1
  360. package/dist/output_parsers/list.d.cts +0 -1
  361. package/dist/output_parsers/list.d.cts.map +1 -1
  362. package/dist/output_parsers/list.d.ts +0 -1
  363. package/dist/output_parsers/list.d.ts.map +1 -1
  364. package/dist/output_parsers/list.js.map +1 -1
  365. package/dist/output_parsers/openai_functions/index.cjs +3 -3
  366. package/dist/output_parsers/openai_functions/index.js +2 -3
  367. package/dist/output_parsers/openai_functions/json_output_functions_parsers.cjs +6 -9
  368. package/dist/output_parsers/openai_functions/json_output_functions_parsers.cjs.map +1 -1
  369. package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.cts +0 -1
  370. package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.cts.map +1 -1
  371. package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts.map +1 -1
  372. package/dist/output_parsers/openai_functions/json_output_functions_parsers.js +6 -9
  373. package/dist/output_parsers/openai_functions/json_output_functions_parsers.js.map +1 -1
  374. package/dist/output_parsers/openai_tools/index.cjs +3 -3
  375. package/dist/output_parsers/openai_tools/index.js +2 -3
  376. package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs +14 -21
  377. package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs.map +1 -1
  378. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts +1 -2
  379. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts.map +1 -1
  380. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +1 -2
  381. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts.map +1 -1
  382. package/dist/output_parsers/openai_tools/json_output_tools_parsers.js +14 -21
  383. package/dist/output_parsers/openai_tools/json_output_tools_parsers.js.map +1 -1
  384. package/dist/output_parsers/string.cjs +3 -0
  385. package/dist/output_parsers/string.cjs.map +1 -1
  386. package/dist/output_parsers/string.d.cts +0 -1
  387. package/dist/output_parsers/string.d.cts.map +1 -1
  388. package/dist/output_parsers/string.d.ts +0 -1
  389. package/dist/output_parsers/string.d.ts.map +1 -1
  390. package/dist/output_parsers/string.js +3 -0
  391. package/dist/output_parsers/string.js.map +1 -1
  392. package/dist/output_parsers/structured.cjs +10 -13
  393. package/dist/output_parsers/structured.cjs.map +1 -1
  394. package/dist/output_parsers/structured.d.cts.map +1 -1
  395. package/dist/output_parsers/structured.d.ts.map +1 -1
  396. package/dist/output_parsers/structured.js +8 -11
  397. package/dist/output_parsers/structured.js.map +1 -1
  398. package/dist/output_parsers/transform.cjs +3 -3
  399. package/dist/output_parsers/transform.cjs.map +1 -1
  400. package/dist/output_parsers/transform.d.cts +0 -1
  401. package/dist/output_parsers/transform.d.cts.map +1 -1
  402. package/dist/output_parsers/transform.d.ts +0 -1
  403. package/dist/output_parsers/transform.d.ts.map +1 -1
  404. package/dist/output_parsers/transform.js.map +1 -1
  405. package/dist/output_parsers/xml.cjs +4 -7
  406. package/dist/output_parsers/xml.cjs.map +1 -1
  407. package/dist/output_parsers/xml.d.cts.map +1 -1
  408. package/dist/output_parsers/xml.d.ts.map +1 -1
  409. package/dist/output_parsers/xml.js +4 -7
  410. package/dist/output_parsers/xml.js.map +1 -1
  411. package/dist/outputs.cjs +3 -3
  412. package/dist/outputs.cjs.map +1 -1
  413. package/dist/outputs.d.cts.map +1 -1
  414. package/dist/outputs.d.ts.map +1 -1
  415. package/dist/outputs.js +2 -3
  416. package/dist/outputs.js.map +1 -1
  417. package/dist/prompt_values.cjs +3 -3
  418. package/dist/prompt_values.cjs.map +1 -1
  419. package/dist/prompt_values.d.cts +1 -3
  420. package/dist/prompt_values.d.cts.map +1 -1
  421. package/dist/prompt_values.d.ts +1 -3
  422. package/dist/prompt_values.d.ts.map +1 -1
  423. package/dist/prompt_values.js +2 -3
  424. package/dist/prompt_values.js.map +1 -1
  425. package/dist/prompts/base.cjs +2 -3
  426. package/dist/prompts/base.cjs.map +1 -1
  427. package/dist/prompts/base.d.cts.map +1 -1
  428. package/dist/prompts/base.d.ts.map +1 -1
  429. package/dist/prompts/base.js +2 -3
  430. package/dist/prompts/base.js.map +1 -1
  431. package/dist/prompts/chat.cjs +22 -37
  432. package/dist/prompts/chat.cjs.map +1 -1
  433. package/dist/prompts/chat.d.cts +1 -0
  434. package/dist/prompts/chat.d.cts.map +1 -1
  435. package/dist/prompts/chat.d.ts +1 -0
  436. package/dist/prompts/chat.d.ts.map +1 -1
  437. package/dist/prompts/chat.js +22 -37
  438. package/dist/prompts/chat.js.map +1 -1
  439. package/dist/prompts/dict.cjs.map +1 -1
  440. package/dist/prompts/dict.d.cts.map +1 -1
  441. package/dist/prompts/dict.d.ts.map +1 -1
  442. package/dist/prompts/dict.js.map +1 -1
  443. package/dist/prompts/few_shot.cjs +9 -14
  444. package/dist/prompts/few_shot.cjs.map +1 -1
  445. package/dist/prompts/few_shot.d.cts.map +1 -1
  446. package/dist/prompts/few_shot.d.ts.map +1 -1
  447. package/dist/prompts/few_shot.js +9 -14
  448. package/dist/prompts/few_shot.js.map +1 -1
  449. package/dist/prompts/image.cjs +3 -5
  450. package/dist/prompts/image.cjs.map +1 -1
  451. package/dist/prompts/image.d.cts +0 -1
  452. package/dist/prompts/image.d.cts.map +1 -1
  453. package/dist/prompts/image.d.ts +0 -1
  454. package/dist/prompts/image.d.ts.map +1 -1
  455. package/dist/prompts/image.js +3 -5
  456. package/dist/prompts/image.js.map +1 -1
  457. package/dist/prompts/index.cjs +3 -3
  458. package/dist/prompts/index.js +2 -3
  459. package/dist/prompts/pipeline.cjs.map +1 -1
  460. package/dist/prompts/pipeline.d.cts +0 -1
  461. package/dist/prompts/pipeline.d.cts.map +1 -1
  462. package/dist/prompts/pipeline.d.ts +0 -1
  463. package/dist/prompts/pipeline.d.ts.map +1 -1
  464. package/dist/prompts/pipeline.js.map +1 -1
  465. package/dist/prompts/prompt.cjs +9 -12
  466. package/dist/prompts/prompt.cjs.map +1 -1
  467. package/dist/prompts/prompt.d.cts +0 -1
  468. package/dist/prompts/prompt.d.cts.map +1 -1
  469. package/dist/prompts/prompt.d.ts.map +1 -1
  470. package/dist/prompts/prompt.js +9 -12
  471. package/dist/prompts/prompt.js.map +1 -1
  472. package/dist/prompts/serde.d.cts +0 -1
  473. package/dist/prompts/serde.d.cts.map +1 -1
  474. package/dist/prompts/serde.d.ts +0 -1
  475. package/dist/prompts/serde.d.ts.map +1 -1
  476. package/dist/prompts/string.cjs +1 -2
  477. package/dist/prompts/string.cjs.map +1 -1
  478. package/dist/prompts/string.d.cts +0 -1
  479. package/dist/prompts/string.d.cts.map +1 -1
  480. package/dist/prompts/string.d.ts +0 -1
  481. package/dist/prompts/string.d.ts.map +1 -1
  482. package/dist/prompts/string.js +1 -2
  483. package/dist/prompts/string.js.map +1 -1
  484. package/dist/prompts/structured.cjs.map +1 -1
  485. package/dist/prompts/structured.d.cts +0 -1
  486. package/dist/prompts/structured.d.cts.map +1 -1
  487. package/dist/prompts/structured.d.ts.map +1 -1
  488. package/dist/prompts/structured.js.map +1 -1
  489. package/dist/prompts/template.cjs +7 -11
  490. package/dist/prompts/template.cjs.map +1 -1
  491. package/dist/prompts/template.d.cts +0 -1
  492. package/dist/prompts/template.d.cts.map +1 -1
  493. package/dist/prompts/template.d.ts.map +1 -1
  494. package/dist/prompts/template.js +4 -9
  495. package/dist/prompts/template.js.map +1 -1
  496. package/dist/retrievers/document_compressors/index.cjs +3 -3
  497. package/dist/retrievers/document_compressors/index.cjs.map +1 -1
  498. package/dist/retrievers/document_compressors/index.d.cts +0 -1
  499. package/dist/retrievers/document_compressors/index.d.cts.map +1 -1
  500. package/dist/retrievers/document_compressors/index.d.ts +0 -1
  501. package/dist/retrievers/document_compressors/index.d.ts.map +1 -1
  502. package/dist/retrievers/document_compressors/index.js +2 -3
  503. package/dist/retrievers/document_compressors/index.js.map +1 -1
  504. package/dist/retrievers/index.cjs +4 -5
  505. package/dist/retrievers/index.cjs.map +1 -1
  506. package/dist/retrievers/index.d.cts +0 -1
  507. package/dist/retrievers/index.d.cts.map +1 -1
  508. package/dist/retrievers/index.d.ts +0 -1
  509. package/dist/retrievers/index.d.ts.map +1 -1
  510. package/dist/retrievers/index.js +3 -5
  511. package/dist/retrievers/index.js.map +1 -1
  512. package/dist/runnables/base.cjs +44 -67
  513. package/dist/runnables/base.cjs.map +1 -1
  514. package/dist/runnables/base.d.cts +1 -2
  515. package/dist/runnables/base.d.cts.map +1 -1
  516. package/dist/runnables/base.d.ts +1 -2
  517. package/dist/runnables/base.d.ts.map +1 -1
  518. package/dist/runnables/base.js +40 -63
  519. package/dist/runnables/base.js.map +1 -1
  520. package/dist/runnables/branch.cjs +4 -8
  521. package/dist/runnables/branch.cjs.map +1 -1
  522. package/dist/runnables/branch.d.cts +0 -1
  523. package/dist/runnables/branch.d.cts.map +1 -1
  524. package/dist/runnables/branch.d.ts +0 -1
  525. package/dist/runnables/branch.d.ts.map +1 -1
  526. package/dist/runnables/branch.js +4 -8
  527. package/dist/runnables/branch.js.map +1 -1
  528. package/dist/runnables/config.cjs +1 -1
  529. package/dist/runnables/config.cjs.map +1 -1
  530. package/dist/runnables/config.d.cts.map +1 -1
  531. package/dist/runnables/config.d.ts.map +1 -1
  532. package/dist/runnables/config.js +1 -1
  533. package/dist/runnables/config.js.map +1 -1
  534. package/dist/runnables/graph.cjs +6 -8
  535. package/dist/runnables/graph.cjs.map +1 -1
  536. package/dist/runnables/graph.d.cts.map +1 -1
  537. package/dist/runnables/graph.d.ts.map +1 -1
  538. package/dist/runnables/graph.js +4 -7
  539. package/dist/runnables/graph.js.map +1 -1
  540. package/dist/runnables/graph_mermaid.cjs +6 -9
  541. package/dist/runnables/graph_mermaid.cjs.map +1 -1
  542. package/dist/runnables/graph_mermaid.js +6 -9
  543. package/dist/runnables/graph_mermaid.js.map +1 -1
  544. package/dist/runnables/history.cjs +4 -6
  545. package/dist/runnables/history.cjs.map +1 -1
  546. package/dist/runnables/history.d.cts.map +1 -1
  547. package/dist/runnables/history.d.ts.map +1 -1
  548. package/dist/runnables/history.js +4 -6
  549. package/dist/runnables/history.js.map +1 -1
  550. package/dist/runnables/index.cjs +3 -3
  551. package/dist/runnables/index.js +2 -3
  552. package/dist/runnables/iter.cjs.map +1 -1
  553. package/dist/runnables/iter.js.map +1 -1
  554. package/dist/runnables/passthrough.cjs +1 -1
  555. package/dist/runnables/passthrough.cjs.map +1 -1
  556. package/dist/runnables/passthrough.d.cts.map +1 -1
  557. package/dist/runnables/passthrough.d.ts.map +1 -1
  558. package/dist/runnables/passthrough.js +1 -1
  559. package/dist/runnables/passthrough.js.map +1 -1
  560. package/dist/runnables/router.cjs +2 -3
  561. package/dist/runnables/router.cjs.map +1 -1
  562. package/dist/runnables/router.d.cts.map +1 -1
  563. package/dist/runnables/router.d.ts.map +1 -1
  564. package/dist/runnables/router.js +2 -3
  565. package/dist/runnables/router.js.map +1 -1
  566. package/dist/runnables/types.d.cts +1 -2
  567. package/dist/runnables/types.d.cts.map +1 -1
  568. package/dist/runnables/types.d.ts +1 -2
  569. package/dist/runnables/types.d.ts.map +1 -1
  570. package/dist/runnables/utils.cjs +1 -2
  571. package/dist/runnables/utils.cjs.map +1 -1
  572. package/dist/runnables/utils.js +1 -2
  573. package/dist/runnables/utils.js.map +1 -1
  574. package/dist/runnables/wrappers.cjs.map +1 -1
  575. package/dist/runnables/wrappers.js.map +1 -1
  576. package/dist/singletons/async_local_storage/context.cjs +4 -5
  577. package/dist/singletons/async_local_storage/context.cjs.map +1 -1
  578. package/dist/singletons/async_local_storage/context.d.cts +0 -1
  579. package/dist/singletons/async_local_storage/context.d.cts.map +1 -1
  580. package/dist/singletons/async_local_storage/context.d.ts +0 -1
  581. package/dist/singletons/async_local_storage/context.d.ts.map +1 -1
  582. package/dist/singletons/async_local_storage/context.js +2 -3
  583. package/dist/singletons/async_local_storage/context.js.map +1 -1
  584. package/dist/singletons/async_local_storage/globals.cjs.map +1 -1
  585. package/dist/singletons/async_local_storage/globals.d.cts.map +1 -1
  586. package/dist/singletons/async_local_storage/globals.d.ts.map +1 -1
  587. package/dist/singletons/async_local_storage/globals.js.map +1 -1
  588. package/dist/singletons/async_local_storage/index.cjs +5 -10
  589. package/dist/singletons/async_local_storage/index.cjs.map +1 -1
  590. package/dist/singletons/async_local_storage/index.d.cts.map +1 -1
  591. package/dist/singletons/async_local_storage/index.d.ts.map +1 -1
  592. package/dist/singletons/async_local_storage/index.js +3 -8
  593. package/dist/singletons/async_local_storage/index.js.map +1 -1
  594. package/dist/singletons/callbacks.cjs +4 -4
  595. package/dist/singletons/callbacks.cjs.map +1 -1
  596. package/dist/singletons/callbacks.d.cts +0 -1
  597. package/dist/singletons/callbacks.d.cts.map +1 -1
  598. package/dist/singletons/callbacks.d.ts +0 -1
  599. package/dist/singletons/callbacks.d.ts.map +1 -1
  600. package/dist/singletons/callbacks.js +1 -2
  601. package/dist/singletons/callbacks.js.map +1 -1
  602. package/dist/singletons/index.cjs +3 -3
  603. package/dist/singletons/index.js +2 -3
  604. package/dist/singletons/tracer.cjs +3 -6
  605. package/dist/singletons/tracer.cjs.map +1 -1
  606. package/dist/singletons/tracer.js +1 -4
  607. package/dist/singletons/tracer.js.map +1 -1
  608. package/dist/stores.cjs +3 -3
  609. package/dist/stores.cjs.map +1 -1
  610. package/dist/stores.d.cts +0 -1
  611. package/dist/stores.d.cts.map +1 -1
  612. package/dist/stores.d.ts +0 -1
  613. package/dist/stores.d.ts.map +1 -1
  614. package/dist/stores.js +2 -3
  615. package/dist/stores.js.map +1 -1
  616. package/dist/structured_query/base.cjs +3 -3
  617. package/dist/structured_query/base.cjs.map +1 -1
  618. package/dist/structured_query/base.d.cts +0 -1
  619. package/dist/structured_query/base.d.cts.map +1 -1
  620. package/dist/structured_query/base.d.ts +0 -1
  621. package/dist/structured_query/base.d.ts.map +1 -1
  622. package/dist/structured_query/base.js +3 -3
  623. package/dist/structured_query/base.js.map +1 -1
  624. package/dist/structured_query/functional.cjs +3 -3
  625. package/dist/structured_query/functional.cjs.map +1 -1
  626. package/dist/structured_query/functional.d.cts +0 -1
  627. package/dist/structured_query/functional.d.cts.map +1 -1
  628. package/dist/structured_query/functional.d.ts +0 -1
  629. package/dist/structured_query/functional.d.ts.map +1 -1
  630. package/dist/structured_query/functional.js +3 -3
  631. package/dist/structured_query/functional.js.map +1 -1
  632. package/dist/structured_query/index.cjs +3 -3
  633. package/dist/structured_query/index.js +2 -3
  634. package/dist/structured_query/ir.cjs.map +1 -1
  635. package/dist/structured_query/ir.d.cts +0 -1
  636. package/dist/structured_query/ir.d.cts.map +1 -1
  637. package/dist/structured_query/ir.d.ts +0 -1
  638. package/dist/structured_query/ir.d.ts.map +1 -1
  639. package/dist/structured_query/ir.js.map +1 -1
  640. package/dist/structured_query/utils.cjs.map +1 -1
  641. package/dist/structured_query/utils.d.cts.map +1 -1
  642. package/dist/structured_query/utils.d.ts.map +1 -1
  643. package/dist/structured_query/utils.js.map +1 -1
  644. package/dist/tools/index.cjs +11 -12
  645. package/dist/tools/index.cjs.map +1 -1
  646. package/dist/tools/index.d.cts +2 -1
  647. package/dist/tools/index.d.cts.map +1 -1
  648. package/dist/tools/index.d.ts +2 -1
  649. package/dist/tools/index.d.ts.map +1 -1
  650. package/dist/tools/index.js +7 -9
  651. package/dist/tools/index.js.map +1 -1
  652. package/dist/tools/types.cjs.map +1 -1
  653. package/dist/tools/types.d.cts +1 -0
  654. package/dist/tools/types.d.cts.map +1 -1
  655. package/dist/tools/types.d.ts +1 -0
  656. package/dist/tools/types.d.ts.map +1 -1
  657. package/dist/tools/types.js.map +1 -1
  658. package/dist/tools/utils.cjs.map +1 -1
  659. package/dist/tools/utils.d.cts +0 -1
  660. package/dist/tools/utils.d.cts.map +1 -1
  661. package/dist/tools/utils.d.ts +0 -1
  662. package/dist/tools/utils.d.ts.map +1 -1
  663. package/dist/tools/utils.js.map +1 -1
  664. package/dist/tracers/base.cjs +7 -7
  665. package/dist/tracers/base.cjs.map +1 -1
  666. package/dist/tracers/base.d.cts +6 -12
  667. package/dist/tracers/base.d.cts.map +1 -1
  668. package/dist/tracers/base.d.ts +6 -12
  669. package/dist/tracers/base.d.ts.map +1 -1
  670. package/dist/tracers/base.js +5 -6
  671. package/dist/tracers/base.js.map +1 -1
  672. package/dist/tracers/console.cjs +9 -9
  673. package/dist/tracers/console.cjs.map +1 -1
  674. package/dist/tracers/console.d.cts +0 -1
  675. package/dist/tracers/console.d.cts.map +1 -1
  676. package/dist/tracers/console.d.ts +0 -1
  677. package/dist/tracers/console.d.ts.map +1 -1
  678. package/dist/tracers/console.js +6 -8
  679. package/dist/tracers/console.js.map +1 -1
  680. package/dist/tracers/event_stream.cjs +2 -4
  681. package/dist/tracers/event_stream.cjs.map +1 -1
  682. package/dist/tracers/event_stream.d.cts +2 -5
  683. package/dist/tracers/event_stream.d.cts.map +1 -1
  684. package/dist/tracers/event_stream.d.ts +2 -5
  685. package/dist/tracers/event_stream.d.ts.map +1 -1
  686. package/dist/tracers/event_stream.js +2 -4
  687. package/dist/tracers/event_stream.js.map +1 -1
  688. package/dist/tracers/log_stream.cjs +5 -5
  689. package/dist/tracers/log_stream.cjs.map +1 -1
  690. package/dist/tracers/log_stream.d.cts +14 -31
  691. package/dist/tracers/log_stream.d.cts.map +1 -1
  692. package/dist/tracers/log_stream.d.ts +14 -31
  693. package/dist/tracers/log_stream.d.ts.map +1 -1
  694. package/dist/tracers/log_stream.js +4 -5
  695. package/dist/tracers/log_stream.js.map +1 -1
  696. package/dist/tracers/root_listener.cjs.map +1 -1
  697. package/dist/tracers/root_listener.js.map +1 -1
  698. package/dist/tracers/run_collector.cjs +3 -3
  699. package/dist/tracers/run_collector.cjs.map +1 -1
  700. package/dist/tracers/run_collector.d.cts +0 -1
  701. package/dist/tracers/run_collector.d.cts.map +1 -1
  702. package/dist/tracers/run_collector.d.ts +0 -1
  703. package/dist/tracers/run_collector.d.ts.map +1 -1
  704. package/dist/tracers/run_collector.js +2 -3
  705. package/dist/tracers/run_collector.js.map +1 -1
  706. package/dist/tracers/tracer_langchain.cjs +8 -11
  707. package/dist/tracers/tracer_langchain.cjs.map +1 -1
  708. package/dist/tracers/tracer_langchain.d.cts +8 -8
  709. package/dist/tracers/tracer_langchain.d.cts.map +1 -1
  710. package/dist/tracers/tracer_langchain.d.ts +8 -8
  711. package/dist/tracers/tracer_langchain.d.ts.map +1 -1
  712. package/dist/tracers/tracer_langchain.js +5 -9
  713. package/dist/tracers/tracer_langchain.js.map +1 -1
  714. package/dist/types/_internal.d.cts.map +1 -1
  715. package/dist/types/_internal.d.ts.map +1 -1
  716. package/dist/types/stream.cjs +3 -1
  717. package/dist/types/stream.js +3 -1
  718. package/dist/types/type-utils.d.cts.map +1 -1
  719. package/dist/types/type-utils.d.ts.map +1 -1
  720. package/dist/utils/async_caller.cjs +8 -9
  721. package/dist/utils/async_caller.cjs.map +1 -1
  722. package/dist/utils/async_caller.d.cts.map +1 -1
  723. package/dist/utils/async_caller.d.ts.map +1 -1
  724. package/dist/utils/async_caller.js +5 -8
  725. package/dist/utils/async_caller.js.map +1 -1
  726. package/dist/utils/callbacks.cjs +2 -3
  727. package/dist/utils/callbacks.cjs.map +1 -1
  728. package/dist/utils/callbacks.js +2 -3
  729. package/dist/utils/callbacks.js.map +1 -1
  730. package/dist/utils/chunk_array.cjs +4 -5
  731. package/dist/utils/chunk_array.cjs.map +1 -1
  732. package/dist/utils/chunk_array.d.cts.map +1 -1
  733. package/dist/utils/chunk_array.d.ts.map +1 -1
  734. package/dist/utils/chunk_array.js +3 -5
  735. package/dist/utils/chunk_array.js.map +1 -1
  736. package/dist/utils/context.cjs +4 -5
  737. package/dist/utils/context.cjs.map +1 -1
  738. package/dist/utils/context.d.cts.map +1 -1
  739. package/dist/utils/context.d.ts.map +1 -1
  740. package/dist/utils/context.js +3 -5
  741. package/dist/utils/context.js.map +1 -1
  742. package/dist/utils/env.cjs +9 -12
  743. package/dist/utils/env.cjs.map +1 -1
  744. package/dist/utils/env.d.cts.map +1 -1
  745. package/dist/utils/env.d.ts.map +1 -1
  746. package/dist/utils/env.js +8 -12
  747. package/dist/utils/env.js.map +1 -1
  748. package/dist/utils/event_source_parse.cjs +9 -9
  749. package/dist/utils/event_source_parse.cjs.map +1 -1
  750. package/dist/utils/event_source_parse.d.cts.map +1 -1
  751. package/dist/utils/event_source_parse.d.ts.map +1 -1
  752. package/dist/utils/event_source_parse.js +8 -9
  753. package/dist/utils/event_source_parse.js.map +1 -1
  754. package/dist/utils/fast-json-patch/index.cjs +3 -0
  755. package/dist/utils/fast-json-patch/index.cjs.map +1 -1
  756. package/dist/utils/fast-json-patch/index.js +4 -0
  757. package/dist/utils/fast-json-patch/index.js.map +1 -1
  758. package/dist/utils/fast-json-patch/src/core.cjs +6 -10
  759. package/dist/utils/fast-json-patch/src/core.cjs.map +1 -1
  760. package/dist/utils/fast-json-patch/src/core.d.cts +0 -1
  761. package/dist/utils/fast-json-patch/src/core.d.cts.map +1 -1
  762. package/dist/utils/fast-json-patch/src/core.d.ts +0 -1
  763. package/dist/utils/fast-json-patch/src/core.d.ts.map +1 -1
  764. package/dist/utils/fast-json-patch/src/core.js +6 -10
  765. package/dist/utils/fast-json-patch/src/core.js.map +1 -1
  766. package/dist/utils/fast-json-patch/src/duplex.cjs +5 -3
  767. package/dist/utils/fast-json-patch/src/duplex.cjs.map +1 -1
  768. package/dist/utils/fast-json-patch/src/duplex.d.cts +0 -1
  769. package/dist/utils/fast-json-patch/src/duplex.d.cts.map +1 -1
  770. package/dist/utils/fast-json-patch/src/duplex.d.ts +0 -1
  771. package/dist/utils/fast-json-patch/src/duplex.d.ts.map +1 -1
  772. package/dist/utils/fast-json-patch/src/duplex.js +5 -3
  773. package/dist/utils/fast-json-patch/src/duplex.js.map +1 -1
  774. package/dist/utils/fast-json-patch/src/helpers.cjs +4 -4
  775. package/dist/utils/fast-json-patch/src/helpers.cjs.map +1 -1
  776. package/dist/utils/fast-json-patch/src/helpers.js +4 -4
  777. package/dist/utils/fast-json-patch/src/helpers.js.map +1 -1
  778. package/dist/utils/format.cjs +3 -1
  779. package/dist/utils/format.d.cts.map +1 -1
  780. package/dist/utils/format.d.ts.map +1 -1
  781. package/dist/utils/format.js +3 -1
  782. package/dist/utils/function_calling.cjs +3 -3
  783. package/dist/utils/function_calling.cjs.map +1 -1
  784. package/dist/utils/function_calling.d.cts +0 -1
  785. package/dist/utils/function_calling.d.cts.map +1 -1
  786. package/dist/utils/function_calling.d.ts +0 -1
  787. package/dist/utils/function_calling.d.ts.map +1 -1
  788. package/dist/utils/function_calling.js +2 -3
  789. package/dist/utils/function_calling.js.map +1 -1
  790. package/dist/utils/hash.cjs +3 -3
  791. package/dist/utils/hash.d.cts +0 -1
  792. package/dist/utils/hash.d.cts.map +1 -1
  793. package/dist/utils/hash.d.ts +0 -1
  794. package/dist/utils/hash.d.ts.map +1 -1
  795. package/dist/utils/hash.js +2 -3
  796. package/dist/utils/is-network-error/index.cjs +2 -3
  797. package/dist/utils/is-network-error/index.cjs.map +1 -1
  798. package/dist/utils/is-network-error/index.js +2 -3
  799. package/dist/utils/is-network-error/index.js.map +1 -1
  800. package/dist/utils/js-sha256/hash.cjs +41 -34
  801. package/dist/utils/js-sha256/hash.cjs.map +1 -1
  802. package/dist/utils/js-sha256/hash.d.cts.map +1 -1
  803. package/dist/utils/js-sha256/hash.d.ts.map +1 -1
  804. package/dist/utils/js-sha256/hash.js +41 -35
  805. package/dist/utils/js-sha256/hash.js.map +1 -1
  806. package/dist/utils/json.cjs.map +1 -1
  807. package/dist/utils/json.d.cts.map +1 -1
  808. package/dist/utils/json.d.ts.map +1 -1
  809. package/dist/utils/json.js.map +1 -1
  810. package/dist/utils/json_patch.cjs +3 -3
  811. package/dist/utils/json_patch.js +2 -3
  812. package/dist/utils/json_schema.cjs +12 -14
  813. package/dist/utils/json_schema.cjs.map +1 -1
  814. package/dist/utils/json_schema.d.cts.map +1 -1
  815. package/dist/utils/json_schema.d.ts.map +1 -1
  816. package/dist/utils/json_schema.js +4 -7
  817. package/dist/utils/json_schema.js.map +1 -1
  818. package/dist/utils/math.cjs +7 -8
  819. package/dist/utils/math.cjs.map +1 -1
  820. package/dist/utils/math.d.cts.map +1 -1
  821. package/dist/utils/math.d.ts.map +1 -1
  822. package/dist/utils/math.js +8 -10
  823. package/dist/utils/math.js.map +1 -1
  824. package/dist/utils/ml-distance/distances.cjs.map +1 -1
  825. package/dist/utils/ml-distance/distances.js.map +1 -1
  826. package/dist/utils/ml-distance/similarities.cjs.map +1 -1
  827. package/dist/utils/ml-distance/similarities.d.cts.map +1 -1
  828. package/dist/utils/ml-distance/similarities.d.ts.map +1 -1
  829. package/dist/utils/ml-distance/similarities.js.map +1 -1
  830. package/dist/utils/ml-distance-euclidean/euclidean.cjs.map +1 -1
  831. package/dist/utils/ml-distance-euclidean/euclidean.js.map +1 -1
  832. package/dist/utils/namespace.cjs +63 -0
  833. package/dist/utils/namespace.cjs.map +1 -0
  834. package/dist/utils/namespace.d.cts +73 -0
  835. package/dist/utils/namespace.d.cts.map +1 -0
  836. package/dist/utils/namespace.d.ts +73 -0
  837. package/dist/utils/namespace.d.ts.map +1 -0
  838. package/dist/utils/namespace.js +62 -0
  839. package/dist/utils/namespace.js.map +1 -0
  840. package/dist/utils/p-retry/index.cjs +2 -2
  841. package/dist/utils/p-retry/index.cjs.map +1 -1
  842. package/dist/utils/p-retry/index.js +2 -2
  843. package/dist/utils/p-retry/index.js.map +1 -1
  844. package/dist/utils/sax-js/sax.cjs +28 -34
  845. package/dist/utils/sax-js/sax.cjs.map +1 -1
  846. package/dist/utils/sax-js/sax.js +28 -34
  847. package/dist/utils/sax-js/sax.js.map +1 -1
  848. package/dist/utils/signal.cjs +1 -1
  849. package/dist/utils/signal.cjs.map +1 -1
  850. package/dist/utils/signal.d.cts.map +1 -1
  851. package/dist/utils/signal.d.ts.map +1 -1
  852. package/dist/utils/signal.js +1 -1
  853. package/dist/utils/signal.js.map +1 -1
  854. package/dist/utils/ssrf.cjs +8 -10
  855. package/dist/utils/ssrf.cjs.map +1 -1
  856. package/dist/utils/ssrf.d.cts.map +1 -1
  857. package/dist/utils/ssrf.d.ts.map +1 -1
  858. package/dist/utils/ssrf.js +7 -10
  859. package/dist/utils/ssrf.js.map +1 -1
  860. package/dist/utils/stream.cjs +4 -4
  861. package/dist/utils/stream.cjs.map +1 -1
  862. package/dist/utils/stream.d.cts.map +1 -1
  863. package/dist/utils/stream.d.ts.map +1 -1
  864. package/dist/utils/stream.js +3 -4
  865. package/dist/utils/stream.js.map +1 -1
  866. package/dist/utils/testing/chat_models.cjs +3 -5
  867. package/dist/utils/testing/chat_models.cjs.map +1 -1
  868. package/dist/utils/testing/chat_models.d.cts.map +1 -1
  869. package/dist/utils/testing/chat_models.d.ts.map +1 -1
  870. package/dist/utils/testing/chat_models.js +3 -5
  871. package/dist/utils/testing/chat_models.js.map +1 -1
  872. package/dist/utils/testing/embeddings.cjs +2 -4
  873. package/dist/utils/testing/embeddings.cjs.map +1 -1
  874. package/dist/utils/testing/embeddings.d.cts +0 -1
  875. package/dist/utils/testing/embeddings.d.cts.map +1 -1
  876. package/dist/utils/testing/embeddings.d.ts +0 -1
  877. package/dist/utils/testing/embeddings.d.ts.map +1 -1
  878. package/dist/utils/testing/embeddings.js +2 -4
  879. package/dist/utils/testing/embeddings.js.map +1 -1
  880. package/dist/utils/testing/index.cjs +3 -3
  881. package/dist/utils/testing/index.js +2 -3
  882. package/dist/utils/testing/llms.cjs.map +1 -1
  883. package/dist/utils/testing/llms.d.cts.map +1 -1
  884. package/dist/utils/testing/llms.d.ts.map +1 -1
  885. package/dist/utils/testing/llms.js.map +1 -1
  886. package/dist/utils/testing/message_history.cjs +1 -1
  887. package/dist/utils/testing/message_history.cjs.map +1 -1
  888. package/dist/utils/testing/message_history.d.cts.map +1 -1
  889. package/dist/utils/testing/message_history.d.ts.map +1 -1
  890. package/dist/utils/testing/message_history.js +1 -1
  891. package/dist/utils/testing/message_history.js.map +1 -1
  892. package/dist/utils/testing/output_parsers.cjs.map +1 -1
  893. package/dist/utils/testing/output_parsers.d.cts +0 -1
  894. package/dist/utils/testing/output_parsers.d.cts.map +1 -1
  895. package/dist/utils/testing/output_parsers.d.ts +0 -1
  896. package/dist/utils/testing/output_parsers.d.ts.map +1 -1
  897. package/dist/utils/testing/output_parsers.js.map +1 -1
  898. package/dist/utils/testing/retrievers.cjs +1 -1
  899. package/dist/utils/testing/retrievers.cjs.map +1 -1
  900. package/dist/utils/testing/retrievers.d.cts.map +1 -1
  901. package/dist/utils/testing/retrievers.d.ts.map +1 -1
  902. package/dist/utils/testing/retrievers.js +1 -1
  903. package/dist/utils/testing/retrievers.js.map +1 -1
  904. package/dist/utils/testing/runnables.cjs.map +1 -1
  905. package/dist/utils/testing/runnables.d.cts.map +1 -1
  906. package/dist/utils/testing/runnables.d.ts.map +1 -1
  907. package/dist/utils/testing/runnables.js.map +1 -1
  908. package/dist/utils/testing/tools.cjs.map +1 -1
  909. package/dist/utils/testing/tools.d.cts.map +1 -1
  910. package/dist/utils/testing/tools.d.ts.map +1 -1
  911. package/dist/utils/testing/tools.js.map +1 -1
  912. package/dist/utils/testing/tracers.cjs.map +1 -1
  913. package/dist/utils/testing/tracers.d.cts.map +1 -1
  914. package/dist/utils/testing/tracers.d.ts.map +1 -1
  915. package/dist/utils/testing/tracers.js.map +1 -1
  916. package/dist/utils/testing/vectorstores.cjs +7 -11
  917. package/dist/utils/testing/vectorstores.cjs.map +1 -1
  918. package/dist/utils/testing/vectorstores.d.cts +0 -1
  919. package/dist/utils/testing/vectorstores.d.cts.map +1 -1
  920. package/dist/utils/testing/vectorstores.d.ts +0 -1
  921. package/dist/utils/testing/vectorstores.d.ts.map +1 -1
  922. package/dist/utils/testing/vectorstores.js +7 -11
  923. package/dist/utils/testing/vectorstores.js.map +1 -1
  924. package/dist/utils/tiktoken.cjs +4 -4
  925. package/dist/utils/tiktoken.cjs.map +1 -1
  926. package/dist/utils/tiktoken.d.cts.map +1 -1
  927. package/dist/utils/tiktoken.d.ts.map +1 -1
  928. package/dist/utils/tiktoken.js +2 -3
  929. package/dist/utils/tiktoken.js.map +1 -1
  930. package/dist/utils/types/index.cjs +3 -3
  931. package/dist/utils/types/index.d.cts +0 -1
  932. package/dist/utils/types/index.d.cts.map +1 -1
  933. package/dist/utils/types/index.d.ts +0 -1
  934. package/dist/utils/types/index.d.ts.map +1 -1
  935. package/dist/utils/types/index.js +2 -3
  936. package/dist/utils/types/zod.cjs +17 -32
  937. package/dist/utils/types/zod.cjs.map +1 -1
  938. package/dist/utils/types/zod.d.cts +1 -1
  939. package/dist/utils/types/zod.d.cts.map +1 -1
  940. package/dist/utils/types/zod.d.ts +1 -1
  941. package/dist/utils/types/zod.d.ts.map +1 -1
  942. package/dist/utils/types/zod.js +15 -30
  943. package/dist/utils/types/zod.js.map +1 -1
  944. package/dist/utils/zod-to-json-schema/Options.cjs.map +1 -1
  945. package/dist/utils/zod-to-json-schema/Options.js.map +1 -1
  946. package/dist/utils/zod-to-json-schema/Refs.cjs.map +1 -1
  947. package/dist/utils/zod-to-json-schema/Refs.js.map +1 -1
  948. package/dist/utils/zod-to-json-schema/errorMessages.cjs.map +1 -1
  949. package/dist/utils/zod-to-json-schema/errorMessages.d.cts.map +1 -1
  950. package/dist/utils/zod-to-json-schema/errorMessages.d.ts.map +1 -1
  951. package/dist/utils/zod-to-json-schema/errorMessages.js.map +1 -1
  952. package/dist/utils/zod-to-json-schema/getRelativePath.cjs.map +1 -1
  953. package/dist/utils/zod-to-json-schema/getRelativePath.js.map +1 -1
  954. package/dist/utils/zod-to-json-schema/index.js +2 -0
  955. package/dist/utils/zod-to-json-schema/parseDef.cjs.map +1 -1
  956. package/dist/utils/zod-to-json-schema/parseDef.js.map +1 -1
  957. package/dist/utils/zod-to-json-schema/parseTypes.d.cts.map +1 -1
  958. package/dist/utils/zod-to-json-schema/parseTypes.d.ts.map +1 -1
  959. package/dist/utils/zod-to-json-schema/parsers/any.cjs.map +1 -1
  960. package/dist/utils/zod-to-json-schema/parsers/any.d.cts.map +1 -1
  961. package/dist/utils/zod-to-json-schema/parsers/any.d.ts.map +1 -1
  962. package/dist/utils/zod-to-json-schema/parsers/any.js.map +1 -1
  963. package/dist/utils/zod-to-json-schema/parsers/array.cjs +2 -2
  964. package/dist/utils/zod-to-json-schema/parsers/array.cjs.map +1 -1
  965. package/dist/utils/zod-to-json-schema/parsers/array.d.cts.map +1 -1
  966. package/dist/utils/zod-to-json-schema/parsers/array.d.ts.map +1 -1
  967. package/dist/utils/zod-to-json-schema/parsers/array.js.map +1 -1
  968. package/dist/utils/zod-to-json-schema/parsers/bigint.cjs.map +1 -1
  969. package/dist/utils/zod-to-json-schema/parsers/bigint.d.cts.map +1 -1
  970. package/dist/utils/zod-to-json-schema/parsers/bigint.d.ts.map +1 -1
  971. package/dist/utils/zod-to-json-schema/parsers/bigint.js.map +1 -1
  972. package/dist/utils/zod-to-json-schema/parsers/boolean.cjs.map +1 -1
  973. package/dist/utils/zod-to-json-schema/parsers/boolean.d.cts.map +1 -1
  974. package/dist/utils/zod-to-json-schema/parsers/boolean.d.ts.map +1 -1
  975. package/dist/utils/zod-to-json-schema/parsers/boolean.js.map +1 -1
  976. package/dist/utils/zod-to-json-schema/parsers/branded.cjs.map +1 -1
  977. package/dist/utils/zod-to-json-schema/parsers/branded.js.map +1 -1
  978. package/dist/utils/zod-to-json-schema/parsers/catch.cjs.map +1 -1
  979. package/dist/utils/zod-to-json-schema/parsers/catch.js.map +1 -1
  980. package/dist/utils/zod-to-json-schema/parsers/date.cjs.map +1 -1
  981. package/dist/utils/zod-to-json-schema/parsers/date.d.cts +0 -1
  982. package/dist/utils/zod-to-json-schema/parsers/date.d.cts.map +1 -1
  983. package/dist/utils/zod-to-json-schema/parsers/date.d.ts.map +1 -1
  984. package/dist/utils/zod-to-json-schema/parsers/date.js.map +1 -1
  985. package/dist/utils/zod-to-json-schema/parsers/default.cjs.map +1 -1
  986. package/dist/utils/zod-to-json-schema/parsers/default.js.map +1 -1
  987. package/dist/utils/zod-to-json-schema/parsers/effects.cjs.map +1 -1
  988. package/dist/utils/zod-to-json-schema/parsers/effects.js.map +1 -1
  989. package/dist/utils/zod-to-json-schema/parsers/enum.cjs.map +1 -1
  990. package/dist/utils/zod-to-json-schema/parsers/enum.d.cts.map +1 -1
  991. package/dist/utils/zod-to-json-schema/parsers/enum.d.ts.map +1 -1
  992. package/dist/utils/zod-to-json-schema/parsers/enum.js.map +1 -1
  993. package/dist/utils/zod-to-json-schema/parsers/intersection.cjs +1 -1
  994. package/dist/utils/zod-to-json-schema/parsers/intersection.cjs.map +1 -1
  995. package/dist/utils/zod-to-json-schema/parsers/intersection.d.cts.map +1 -1
  996. package/dist/utils/zod-to-json-schema/parsers/intersection.d.ts.map +1 -1
  997. package/dist/utils/zod-to-json-schema/parsers/intersection.js +1 -1
  998. package/dist/utils/zod-to-json-schema/parsers/intersection.js.map +1 -1
  999. package/dist/utils/zod-to-json-schema/parsers/literal.cjs.map +1 -1
  1000. package/dist/utils/zod-to-json-schema/parsers/literal.d.cts +0 -1
  1001. package/dist/utils/zod-to-json-schema/parsers/literal.d.cts.map +1 -1
  1002. package/dist/utils/zod-to-json-schema/parsers/literal.d.ts.map +1 -1
  1003. package/dist/utils/zod-to-json-schema/parsers/literal.js.map +1 -1
  1004. package/dist/utils/zod-to-json-schema/parsers/map.cjs +17 -19
  1005. package/dist/utils/zod-to-json-schema/parsers/map.cjs.map +1 -1
  1006. package/dist/utils/zod-to-json-schema/parsers/map.d.cts +0 -1
  1007. package/dist/utils/zod-to-json-schema/parsers/map.d.cts.map +1 -1
  1008. package/dist/utils/zod-to-json-schema/parsers/map.d.ts.map +1 -1
  1009. package/dist/utils/zod-to-json-schema/parsers/map.js +17 -19
  1010. package/dist/utils/zod-to-json-schema/parsers/map.js.map +1 -1
  1011. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs +2 -3
  1012. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs.map +1 -1
  1013. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.cts.map +1 -1
  1014. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.ts.map +1 -1
  1015. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.js +2 -3
  1016. package/dist/utils/zod-to-json-schema/parsers/nativeEnum.js.map +1 -1
  1017. package/dist/utils/zod-to-json-schema/parsers/never.cjs.map +1 -1
  1018. package/dist/utils/zod-to-json-schema/parsers/never.d.cts.map +1 -1
  1019. package/dist/utils/zod-to-json-schema/parsers/never.d.ts.map +1 -1
  1020. package/dist/utils/zod-to-json-schema/parsers/never.js.map +1 -1
  1021. package/dist/utils/zod-to-json-schema/parsers/null.cjs.map +1 -1
  1022. package/dist/utils/zod-to-json-schema/parsers/null.d.cts.map +1 -1
  1023. package/dist/utils/zod-to-json-schema/parsers/null.d.ts.map +1 -1
  1024. package/dist/utils/zod-to-json-schema/parsers/null.js.map +1 -1
  1025. package/dist/utils/zod-to-json-schema/parsers/nullable.cjs +5 -5
  1026. package/dist/utils/zod-to-json-schema/parsers/nullable.cjs.map +1 -1
  1027. package/dist/utils/zod-to-json-schema/parsers/nullable.d.cts.map +1 -1
  1028. package/dist/utils/zod-to-json-schema/parsers/nullable.d.ts.map +1 -1
  1029. package/dist/utils/zod-to-json-schema/parsers/nullable.js +5 -5
  1030. package/dist/utils/zod-to-json-schema/parsers/nullable.js.map +1 -1
  1031. package/dist/utils/zod-to-json-schema/parsers/number.cjs.map +1 -1
  1032. package/dist/utils/zod-to-json-schema/parsers/number.d.cts.map +1 -1
  1033. package/dist/utils/zod-to-json-schema/parsers/number.d.ts.map +1 -1
  1034. package/dist/utils/zod-to-json-schema/parsers/number.js.map +1 -1
  1035. package/dist/utils/zod-to-json-schema/parsers/object.cjs.map +1 -1
  1036. package/dist/utils/zod-to-json-schema/parsers/object.d.cts.map +1 -1
  1037. package/dist/utils/zod-to-json-schema/parsers/object.d.ts.map +1 -1
  1038. package/dist/utils/zod-to-json-schema/parsers/object.js.map +1 -1
  1039. package/dist/utils/zod-to-json-schema/parsers/optional.cjs.map +1 -1
  1040. package/dist/utils/zod-to-json-schema/parsers/optional.js.map +1 -1
  1041. package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs +2 -3
  1042. package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs.map +1 -1
  1043. package/dist/utils/zod-to-json-schema/parsers/pipeline.js +2 -3
  1044. package/dist/utils/zod-to-json-schema/parsers/pipeline.js.map +1 -1
  1045. package/dist/utils/zod-to-json-schema/parsers/promise.cjs.map +1 -1
  1046. package/dist/utils/zod-to-json-schema/parsers/promise.js.map +1 -1
  1047. package/dist/utils/zod-to-json-schema/parsers/readonly.cjs.map +1 -1
  1048. package/dist/utils/zod-to-json-schema/parsers/readonly.js.map +1 -1
  1049. package/dist/utils/zod-to-json-schema/parsers/record.cjs +4 -4
  1050. package/dist/utils/zod-to-json-schema/parsers/record.cjs.map +1 -1
  1051. package/dist/utils/zod-to-json-schema/parsers/record.d.cts.map +1 -1
  1052. package/dist/utils/zod-to-json-schema/parsers/record.d.ts.map +1 -1
  1053. package/dist/utils/zod-to-json-schema/parsers/record.js +2 -2
  1054. package/dist/utils/zod-to-json-schema/parsers/record.js.map +1 -1
  1055. package/dist/utils/zod-to-json-schema/parsers/set.cjs +4 -5
  1056. package/dist/utils/zod-to-json-schema/parsers/set.cjs.map +1 -1
  1057. package/dist/utils/zod-to-json-schema/parsers/set.d.cts.map +1 -1
  1058. package/dist/utils/zod-to-json-schema/parsers/set.d.ts.map +1 -1
  1059. package/dist/utils/zod-to-json-schema/parsers/set.js +4 -5
  1060. package/dist/utils/zod-to-json-schema/parsers/set.js.map +1 -1
  1061. package/dist/utils/zod-to-json-schema/parsers/string.cjs.map +1 -1
  1062. package/dist/utils/zod-to-json-schema/parsers/string.d.cts +0 -1
  1063. package/dist/utils/zod-to-json-schema/parsers/string.d.cts.map +1 -1
  1064. package/dist/utils/zod-to-json-schema/parsers/string.d.ts +0 -1
  1065. package/dist/utils/zod-to-json-schema/parsers/string.d.ts.map +1 -1
  1066. package/dist/utils/zod-to-json-schema/parsers/string.js.map +1 -1
  1067. package/dist/utils/zod-to-json-schema/parsers/tuple.cjs.map +1 -1
  1068. package/dist/utils/zod-to-json-schema/parsers/tuple.d.cts.map +1 -1
  1069. package/dist/utils/zod-to-json-schema/parsers/tuple.d.ts.map +1 -1
  1070. package/dist/utils/zod-to-json-schema/parsers/tuple.js.map +1 -1
  1071. package/dist/utils/zod-to-json-schema/parsers/undefined.cjs.map +1 -1
  1072. package/dist/utils/zod-to-json-schema/parsers/undefined.d.cts.map +1 -1
  1073. package/dist/utils/zod-to-json-schema/parsers/undefined.d.ts.map +1 -1
  1074. package/dist/utils/zod-to-json-schema/parsers/undefined.js.map +1 -1
  1075. package/dist/utils/zod-to-json-schema/parsers/union.cjs +3 -6
  1076. package/dist/utils/zod-to-json-schema/parsers/union.cjs.map +1 -1
  1077. package/dist/utils/zod-to-json-schema/parsers/union.d.cts.map +1 -1
  1078. package/dist/utils/zod-to-json-schema/parsers/union.d.ts.map +1 -1
  1079. package/dist/utils/zod-to-json-schema/parsers/union.js +3 -6
  1080. package/dist/utils/zod-to-json-schema/parsers/union.js.map +1 -1
  1081. package/dist/utils/zod-to-json-schema/parsers/unknown.cjs.map +1 -1
  1082. package/dist/utils/zod-to-json-schema/parsers/unknown.d.cts.map +1 -1
  1083. package/dist/utils/zod-to-json-schema/parsers/unknown.d.ts.map +1 -1
  1084. package/dist/utils/zod-to-json-schema/parsers/unknown.js.map +1 -1
  1085. package/dist/utils/zod-to-json-schema/selectParser.cjs +3 -3
  1086. package/dist/utils/zod-to-json-schema/selectParser.cjs.map +1 -1
  1087. package/dist/utils/zod-to-json-schema/selectParser.js +1 -1
  1088. package/dist/utils/zod-to-json-schema/selectParser.js.map +1 -1
  1089. package/dist/utils/zod-to-json-schema/zodToJsonSchema.cjs +3 -3
  1090. package/dist/utils/zod-to-json-schema/zodToJsonSchema.cjs.map +1 -1
  1091. package/dist/utils/zod-to-json-schema/zodToJsonSchema.js +3 -3
  1092. package/dist/utils/zod-to-json-schema/zodToJsonSchema.js.map +1 -1
  1093. package/dist/vectorstores.cjs +4 -5
  1094. package/dist/vectorstores.cjs.map +1 -1
  1095. package/dist/vectorstores.d.cts +0 -1
  1096. package/dist/vectorstores.d.cts.map +1 -1
  1097. package/dist/vectorstores.d.ts +0 -1
  1098. package/dist/vectorstores.d.ts.map +1 -1
  1099. package/dist/vectorstores.js +3 -5
  1100. package/dist/vectorstores.js.map +1 -1
  1101. package/package.json +2 -2
  1102. package/dist/_virtual/rolldown_runtime.cjs +0 -32
  1103. package/dist/_virtual/rolldown_runtime.js +0 -11
@@ -78,12 +78,11 @@ var FewShotPromptTemplate = class FewShotPromptTemplate extends BaseStringPrompt
78
78
  ...this.partialVariables ?? {},
79
79
  ...values
80
80
  };
81
- const promptDict = {
81
+ return new FewShotPromptTemplate({
82
82
  ...this,
83
83
  inputVariables: newInputVariables,
84
84
  partialVariables: newPartialVariables
85
- };
86
- return new FewShotPromptTemplate(promptDict);
85
+ });
87
86
  }
88
87
  /**
89
88
  * Formats the prompt with the given values.
@@ -94,12 +93,11 @@ var FewShotPromptTemplate = class FewShotPromptTemplate extends BaseStringPrompt
94
93
  const allValues = await this.mergePartialAndUserVariables(values);
95
94
  const examples = await this.getExamples(allValues);
96
95
  const exampleStrings = await Promise.all(examples.map((example) => this.examplePrompt.format(example)));
97
- const template = [
96
+ return renderTemplate([
98
97
  this.prefix,
99
98
  ...exampleStrings,
100
99
  this.suffix
101
- ].join(this.exampleSeparator);
102
- return renderTemplate(template, this.templateFormat, allValues);
100
+ ].join(this.exampleSeparator), this.templateFormat, allValues);
103
101
  }
104
102
  serialize() {
105
103
  if (this.exampleSelector || !this.examples) throw new Error("Serializing an example selector is not currently supported");
@@ -207,14 +205,12 @@ var FewShotChatMessagePromptTemplate = class FewShotChatMessagePromptTemplate ex
207
205
  async format(values) {
208
206
  const allValues = await this.mergePartialAndUserVariables(values);
209
207
  const examples = await this.getExamples(allValues);
210
- const exampleMessages = await Promise.all(examples.map((example) => this.examplePrompt.formatMessages(example)));
211
- const exampleStrings = exampleMessages.flat().map((message) => message.content);
212
- const template = [
208
+ const exampleStrings = (await Promise.all(examples.map((example) => this.examplePrompt.formatMessages(example)))).flat().map((message) => message.content);
209
+ return renderTemplate([
213
210
  this.prefix,
214
211
  ...exampleStrings,
215
212
  this.suffix
216
- ].join(this.exampleSeparator);
217
- return renderTemplate(template, this.templateFormat, allValues);
213
+ ].join(this.exampleSeparator), this.templateFormat, allValues);
218
214
  }
219
215
  /**
220
216
  * Partially formats the prompt with the given values.
@@ -227,12 +223,11 @@ var FewShotChatMessagePromptTemplate = class FewShotChatMessagePromptTemplate ex
227
223
  ...this.partialVariables ?? {},
228
224
  ...values
229
225
  };
230
- const promptDict = {
226
+ return new FewShotChatMessagePromptTemplate({
231
227
  ...this,
232
228
  inputVariables: newInputVariables,
233
229
  partialVariables: newPartialVariables
234
- };
235
- return new FewShotChatMessagePromptTemplate(promptDict);
230
+ });
236
231
  }
237
232
  };
238
233
 
@@ -1 +1 @@
1
- {"version":3,"file":"few_shot.js","names":["input: FewShotPromptTemplateInput","totalInputVariables: string[]","inputVariables: InputValues","values: PartialValues<NewPartialVariableName>","values: InputValues","data: SerializedFewShotTemplate","examples: Example[]","fields: FewShotChatMessagePromptTemplateInput","values: TypedPromptInputValues<RunInput>","result: Record<string, any>","messages: BaseMessage[]","values: PartialValues<PartialVariableName>"],"sources":["../../src/prompts/few_shot.ts"],"sourcesContent":["import { BaseStringPromptTemplate } from \"./string.js\";\nimport type {\n BasePromptTemplateInput,\n TypedPromptInputValues,\n Example,\n} from \"./base.js\";\nimport type { BaseExampleSelector } from \"../example_selectors/base.js\";\nimport {\n type TemplateFormat,\n checkValidTemplate,\n renderTemplate,\n} from \"./template.js\";\nimport { PromptTemplate } from \"./prompt.js\";\nimport type { SerializedFewShotTemplate } from \"./serde.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport type { BaseMessage } from \"../messages/index.js\";\nimport {\n BaseChatPromptTemplate,\n type BaseMessagePromptTemplate,\n} from \"./chat.js\";\n\nexport interface FewShotPromptTemplateInput extends BasePromptTemplateInput<InputValues> {\n /**\n * Examples to format into the prompt. Exactly one of this or\n * {@link exampleSelector} must be\n * provided.\n */\n examples?: Example[];\n\n /**\n * An {@link BaseExampleSelector} Examples to format into the prompt. Exactly one of this or\n * {@link examples} must be\n * provided.\n */\n exampleSelector?: BaseExampleSelector;\n\n /**\n * An {@link PromptTemplate} used to format a single example.\n */\n examplePrompt: PromptTemplate;\n\n /**\n * String separator used to join the prefix, the examples, and suffix.\n */\n exampleSeparator?: string;\n\n /**\n * A prompt template string to put before the examples.\n *\n * @defaultValue `\"\"`\n */\n prefix?: string;\n\n /**\n * A prompt template string to put after the examples.\n */\n suffix?: string;\n\n /**\n * The format of the prompt template. Options are: 'f-string'\n */\n templateFormat?: TemplateFormat;\n\n /**\n * Whether or not to try validating the template on initialization.\n */\n validateTemplate?: boolean;\n}\n\n/**\n * Prompt template that contains few-shot examples.\n * @augments BasePromptTemplate\n * @augments FewShotPromptTemplateInput\n * @example\n * ```typescript\n * const examplePrompt = PromptTemplate.fromTemplate(\n * \"Input: {input}\\nOutput: {output}\",\n * );\n *\n * const exampleSelector = await SemanticSimilarityExampleSelector.fromExamples(\n * [\n * { input: \"happy\", output: \"sad\" },\n * { input: \"tall\", output: \"short\" },\n * { input: \"energetic\", output: \"lethargic\" },\n * { input: \"sunny\", output: \"gloomy\" },\n * { input: \"windy\", output: \"calm\" },\n * ],\n * new OpenAIEmbeddings(),\n * HNSWLib,\n * { k: 1 },\n * );\n *\n * const dynamicPrompt = new FewShotPromptTemplate({\n * exampleSelector,\n * examplePrompt,\n * prefix: \"Give the antonym of every input\",\n * suffix: \"Input: {adjective}\\nOutput:\",\n * inputVariables: [\"adjective\"],\n * });\n *\n * // Format the dynamic prompt with the input 'rainy'\n * console.log(await dynamicPrompt.format({ adjective: \"rainy\" }));\n *\n * ```\n */\nexport class FewShotPromptTemplate\n extends BaseStringPromptTemplate\n implements FewShotPromptTemplateInput\n{\n lc_serializable = false;\n\n examples?: InputValues[];\n\n exampleSelector?: BaseExampleSelector | undefined;\n\n examplePrompt: PromptTemplate;\n\n suffix = \"\";\n\n exampleSeparator = \"\\n\\n\";\n\n prefix = \"\";\n\n templateFormat: TemplateFormat = \"f-string\";\n\n validateTemplate = true;\n\n constructor(input: FewShotPromptTemplateInput) {\n super(input);\n Object.assign(this, input);\n\n if (this.examples !== undefined && this.exampleSelector !== undefined) {\n throw new Error(\n \"Only one of 'examples' and 'example_selector' should be provided\"\n );\n }\n\n if (this.examples === undefined && this.exampleSelector === undefined) {\n throw new Error(\n \"One of 'examples' and 'example_selector' should be provided\"\n );\n }\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 this.prefix + this.suffix,\n this.templateFormat,\n totalInputVariables\n );\n }\n }\n\n _getPromptType(): \"few_shot\" {\n return \"few_shot\";\n }\n\n static lc_name() {\n return \"FewShotPromptTemplate\";\n }\n\n private async getExamples(\n inputVariables: InputValues\n ): Promise<InputValues[]> {\n if (this.examples !== undefined) {\n return this.examples;\n }\n if (this.exampleSelector !== undefined) {\n return this.exampleSelector.selectExamples(inputVariables);\n }\n\n throw new Error(\n \"One of 'examples' and 'example_selector' should be provided\"\n );\n }\n\n async partial<NewPartialVariableName extends string>(\n values: PartialValues<NewPartialVariableName>\n ) {\n const newInputVariables = this.inputVariables.filter(\n (iv) => !(iv in values)\n );\n const newPartialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n };\n const promptDict = {\n ...this,\n inputVariables: newInputVariables,\n partialVariables: newPartialVariables,\n };\n return new FewShotPromptTemplate(promptDict);\n }\n\n /**\n * Formats the prompt with the given values.\n * @param values The values to format the prompt with.\n * @returns A promise that resolves to a string representing the formatted prompt.\n */\n async format(values: InputValues): Promise<string> {\n const allValues = await this.mergePartialAndUserVariables(values);\n const examples = await this.getExamples(allValues);\n\n const exampleStrings = await Promise.all(\n examples.map((example) => this.examplePrompt.format(example))\n );\n const template = [this.prefix, ...exampleStrings, this.suffix].join(\n this.exampleSeparator\n );\n return renderTemplate(template, this.templateFormat, allValues);\n }\n\n serialize(): SerializedFewShotTemplate {\n if (this.exampleSelector || !this.examples) {\n throw new Error(\n \"Serializing an example selector is not currently supported\"\n );\n }\n if (this.outputParser !== undefined) {\n throw new Error(\n \"Serializing an output parser is not currently supported\"\n );\n }\n return {\n _type: this._getPromptType(),\n input_variables: this.inputVariables,\n example_prompt: this.examplePrompt.serialize(),\n example_separator: this.exampleSeparator,\n suffix: this.suffix,\n prefix: this.prefix,\n template_format: this.templateFormat,\n examples: this.examples,\n };\n }\n\n static async deserialize(\n data: SerializedFewShotTemplate\n ): Promise<FewShotPromptTemplate> {\n const { example_prompt } = data;\n if (!example_prompt) {\n throw new Error(\"Missing example prompt\");\n }\n const examplePrompt = await PromptTemplate.deserialize(example_prompt);\n\n let examples: Example[];\n\n if (Array.isArray(data.examples)) {\n examples = data.examples;\n } else {\n throw new Error(\n \"Invalid examples format. Only list or string are supported.\"\n );\n }\n\n return new FewShotPromptTemplate({\n inputVariables: data.input_variables,\n examplePrompt,\n examples,\n exampleSeparator: data.example_separator,\n prefix: data.prefix,\n suffix: data.suffix,\n templateFormat: data.template_format,\n });\n }\n}\n\nexport interface FewShotChatMessagePromptTemplateInput extends BasePromptTemplateInput<InputValues> {\n /**\n * Examples to format into the prompt. Exactly one of this or\n * {@link exampleSelector} must be\n * provided.\n */\n examples?: Example[];\n\n /**\n * An {@link BaseMessagePromptTemplate} | {@link BaseChatPromptTemplate} used to format a single example.\n */\n examplePrompt: BaseMessagePromptTemplate | BaseChatPromptTemplate;\n\n /**\n * String separator used to join the prefix, the examples, and suffix.\n *\n * @defaultValue `\"\\n\\n\"`\n */\n exampleSeparator?: string;\n\n /**\n * An {@link BaseExampleSelector} Examples to format into the prompt. Exactly one of this or\n * {@link examples} must be\n * provided.\n */\n exampleSelector?: BaseExampleSelector | undefined;\n\n /**\n * A prompt template string to put before the examples.\n *\n * @defaultValue `\"\"`\n */\n prefix?: string;\n\n /**\n * A prompt template string to put after the examples.\n *\n * @defaultValue `\"\"`\n */\n suffix?: string;\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/**\n * Chat prompt template that contains few-shot examples.\n * @augments BasePromptTemplateInput\n * @augments FewShotChatMessagePromptTemplateInput\n */\nexport class FewShotChatMessagePromptTemplate<\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 BaseChatPromptTemplate\n implements FewShotChatMessagePromptTemplateInput\n{\n lc_serializable = true;\n\n examples?: InputValues[];\n\n exampleSelector?: BaseExampleSelector | undefined;\n\n examplePrompt: BaseMessagePromptTemplate | BaseChatPromptTemplate;\n\n suffix = \"\";\n\n exampleSeparator = \"\\n\\n\";\n\n prefix = \"\";\n\n templateFormat: TemplateFormat = \"f-string\";\n\n validateTemplate = true;\n\n _getPromptType(): \"few_shot_chat\" {\n return \"few_shot_chat\";\n }\n\n static lc_name() {\n return \"FewShotChatMessagePromptTemplate\";\n }\n\n constructor(fields: FewShotChatMessagePromptTemplateInput) {\n super(fields);\n\n this.examples = fields.examples;\n this.examplePrompt = fields.examplePrompt;\n this.exampleSeparator = fields.exampleSeparator ?? \"\\n\\n\";\n this.exampleSelector = fields.exampleSelector;\n this.prefix = fields.prefix ?? \"\";\n this.suffix = fields.suffix ?? \"\";\n this.templateFormat = fields.templateFormat ?? \"f-string\";\n this.validateTemplate = fields.validateTemplate ?? true;\n\n if (this.examples !== undefined && this.exampleSelector !== undefined) {\n throw new Error(\n \"Only one of 'examples' and 'example_selector' should be provided\"\n );\n }\n\n if (this.examples === undefined && this.exampleSelector === undefined) {\n throw new Error(\n \"One of 'examples' and 'example_selector' should be provided\"\n );\n }\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 this.prefix + this.suffix,\n this.templateFormat,\n totalInputVariables\n );\n }\n }\n\n private async getExamples(\n inputVariables: InputValues\n ): Promise<InputValues[]> {\n if (this.examples !== undefined) {\n return this.examples;\n }\n if (this.exampleSelector !== undefined) {\n return this.exampleSelector.selectExamples(inputVariables);\n }\n\n throw new Error(\n \"One of 'examples' and 'example_selector' should be provided\"\n );\n }\n\n /**\n * Formats the list of values and returns a list of formatted messages.\n * @param values The values to format the prompt with.\n * @returns A promise that resolves to a string representing the formatted prompt.\n */\n async formatMessages(\n values: TypedPromptInputValues<RunInput>\n ): Promise<BaseMessage[]> {\n const allValues = await this.mergePartialAndUserVariables(values);\n let examples = await this.getExamples(allValues);\n\n examples = examples.map((example) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result: Record<string, any> = {};\n this.examplePrompt.inputVariables.forEach((inputVariable) => {\n result[inputVariable] = example[inputVariable];\n });\n return result;\n });\n\n const messages: BaseMessage[] = [];\n for (const example of examples) {\n const exampleMessages = await this.examplePrompt.formatMessages(example);\n messages.push(...exampleMessages);\n }\n return messages;\n }\n\n /**\n * Formats the prompt with the given values.\n * @param values The values to format the prompt with.\n * @returns A promise that resolves to a string representing the formatted prompt.\n */\n async format(values: TypedPromptInputValues<RunInput>): Promise<string> {\n const allValues = await this.mergePartialAndUserVariables(values);\n const examples = await this.getExamples(allValues);\n const exampleMessages = await Promise.all(\n examples.map((example) => this.examplePrompt.formatMessages(example))\n );\n const exampleStrings = exampleMessages\n .flat()\n .map((message) => message.content);\n const template = [this.prefix, ...exampleStrings, this.suffix].join(\n this.exampleSeparator\n );\n return renderTemplate(template, this.templateFormat, allValues);\n }\n\n /**\n * Partially formats the prompt with the given values.\n * @param values The values to partially format the prompt with.\n * @returns A promise that resolves to an instance of `FewShotChatMessagePromptTemplate` with the given values partially formatted.\n */\n async partial(\n values: PartialValues<PartialVariableName>\n ): Promise<FewShotChatMessagePromptTemplate<RunInput, PartialVariableName>> {\n const newInputVariables = this.inputVariables.filter(\n (variable) => !(variable in values)\n ) as Exclude<Extract<keyof RunInput, string>, PartialVariableName>[];\n const newPartialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n } as PartialValues<PartialVariableName | PartialVariableName>;\n const promptDict = {\n ...this,\n inputVariables: newInputVariables,\n partialVariables: newPartialVariables,\n };\n return new FewShotChatMessagePromptTemplate<\n InputValues<Exclude<Extract<keyof RunInput, string>, PartialVariableName>>\n >(promptDict);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,IAAa,wBAAb,MAAa,8BACH,yBAEV;CACE,kBAAkB;CAElB;CAEA;CAEA;CAEA,SAAS;CAET,mBAAmB;CAEnB,SAAS;CAET,iBAAiC;CAEjC,mBAAmB;CAEnB,YAAYA,OAAmC;EAC7C,MAAM,MAAM;EACZ,OAAO,OAAO,MAAM,MAAM;AAE1B,MAAI,KAAK,aAAa,UAAa,KAAK,oBAAoB,OAC1D,OAAM,IAAI,MACR;AAIJ,MAAI,KAAK,aAAa,UAAa,KAAK,oBAAoB,OAC1D,OAAM,IAAI,MACR;AAIJ,MAAI,KAAK,kBAAkB;GACzB,IAAIC,sBAAgC,KAAK;AACzC,OAAI,KAAK,kBACP,sBAAsB,oBAAoB,OACxC,OAAO,KAAK,KAAK,iBAAiB,CACnC;GAEH,mBACE,KAAK,SAAS,KAAK,QACnB,KAAK,gBACL,oBACD;EACF;CACF;CAED,iBAA6B;AAC3B,SAAO;CACR;CAED,OAAO,UAAU;AACf,SAAO;CACR;CAED,MAAc,YACZC,gBACw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ptTemplate } from \"./string.js\";\nimport type {\n BasePromptTemplateInput,\n TypedPromptInputValues,\n Example,\n} from \"./base.js\";\nimport type { BaseExampleSelector } from \"../example_selectors/base.js\";\nimport {\n type TemplateFormat,\n checkValidTemplate,\n renderTemplate,\n} from \"./template.js\";\nimport { PromptTemplate } from \"./prompt.js\";\nimport type { SerializedFewShotTemplate } from \"./serde.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport type { BaseMessage } from \"../messages/index.js\";\nimport {\n BaseChatPromptTemplate,\n type BaseMessagePromptTemplate,\n} from \"./chat.js\";\n\nexport interface FewShotPromptTemplateInput extends BasePromptTemplateInput<InputValues> {\n /**\n * Examples to format into the prompt. Exactly one of this or\n * {@link exampleSelector} must be\n * provided.\n */\n examples?: Example[];\n\n /**\n * An {@link BaseExampleSelector} Examples to format into the prompt. Exactly one of this or\n * {@link examples} must be\n * provided.\n */\n exampleSelector?: BaseExampleSelector;\n\n /**\n * An {@link PromptTemplate} used to format a single example.\n */\n examplePrompt: PromptTemplate;\n\n /**\n * String separator used to join the prefix, the examples, and suffix.\n */\n exampleSeparator?: string;\n\n /**\n * A prompt template string to put before the examples.\n *\n * @defaultValue `\"\"`\n */\n prefix?: string;\n\n /**\n * A prompt template string to put after the examples.\n */\n suffix?: string;\n\n /**\n * The format of the prompt template. Options are: 'f-string'\n */\n templateFormat?: TemplateFormat;\n\n /**\n * Whether or not to try validating the template on initialization.\n */\n validateTemplate?: boolean;\n}\n\n/**\n * Prompt template that contains few-shot examples.\n * @augments BasePromptTemplate\n * @augments FewShotPromptTemplateInput\n * @example\n * ```typescript\n * const examplePrompt = PromptTemplate.fromTemplate(\n * \"Input: {input}\\nOutput: {output}\",\n * );\n *\n * const exampleSelector = await SemanticSimilarityExampleSelector.fromExamples(\n * [\n * { input: \"happy\", output: \"sad\" },\n * { input: \"tall\", output: \"short\" },\n * { input: \"energetic\", output: \"lethargic\" },\n * { input: \"sunny\", output: \"gloomy\" },\n * { input: \"windy\", output: \"calm\" },\n * ],\n * new OpenAIEmbeddings(),\n * HNSWLib,\n * { k: 1 },\n * );\n *\n * const dynamicPrompt = new FewShotPromptTemplate({\n * exampleSelector,\n * examplePrompt,\n * prefix: \"Give the antonym of every input\",\n * suffix: \"Input: {adjective}\\nOutput:\",\n * inputVariables: [\"adjective\"],\n * });\n *\n * // Format the dynamic prompt with the input 'rainy'\n * console.log(await dynamicPrompt.format({ adjective: \"rainy\" }));\n *\n * ```\n */\nexport class FewShotPromptTemplate\n extends BaseStringPromptTemplate\n implements FewShotPromptTemplateInput\n{\n lc_serializable = false;\n\n examples?: InputValues[];\n\n exampleSelector?: BaseExampleSelector | undefined;\n\n examplePrompt: PromptTemplate;\n\n suffix = \"\";\n\n exampleSeparator = \"\\n\\n\";\n\n prefix = \"\";\n\n templateFormat: TemplateFormat = \"f-string\";\n\n validateTemplate = true;\n\n constructor(input: FewShotPromptTemplateInput) {\n super(input);\n Object.assign(this, input);\n\n if (this.examples !== undefined && this.exampleSelector !== undefined) {\n throw new Error(\n \"Only one of 'examples' and 'example_selector' should be provided\"\n );\n }\n\n if (this.examples === undefined && this.exampleSelector === undefined) {\n throw new Error(\n \"One of 'examples' and 'example_selector' should be provided\"\n );\n }\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 this.prefix + this.suffix,\n this.templateFormat,\n totalInputVariables\n );\n }\n }\n\n _getPromptType(): \"few_shot\" {\n return \"few_shot\";\n }\n\n static lc_name() {\n return \"FewShotPromptTemplate\";\n }\n\n private async getExamples(\n inputVariables: InputValues\n ): Promise<InputValues[]> {\n if (this.examples !== undefined) {\n return this.examples;\n }\n if (this.exampleSelector !== undefined) {\n return this.exampleSelector.selectExamples(inputVariables);\n }\n\n throw new Error(\n \"One of 'examples' and 'example_selector' should be provided\"\n );\n }\n\n async partial<NewPartialVariableName extends string>(\n values: PartialValues<NewPartialVariableName>\n ) {\n const newInputVariables = this.inputVariables.filter(\n (iv) => !(iv in values)\n );\n const newPartialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n };\n const promptDict = {\n ...this,\n inputVariables: newInputVariables,\n partialVariables: newPartialVariables,\n };\n return new FewShotPromptTemplate(promptDict);\n }\n\n /**\n * Formats the prompt with the given values.\n * @param values The values to format the prompt with.\n * @returns A promise that resolves to a string representing the formatted prompt.\n */\n async format(values: InputValues): Promise<string> {\n const allValues = await this.mergePartialAndUserVariables(values);\n const examples = await this.getExamples(allValues);\n\n const exampleStrings = await Promise.all(\n examples.map((example) => this.examplePrompt.format(example))\n );\n const template = [this.prefix, ...exampleStrings, this.suffix].join(\n this.exampleSeparator\n );\n return renderTemplate(template, this.templateFormat, allValues);\n }\n\n serialize(): SerializedFewShotTemplate {\n if (this.exampleSelector || !this.examples) {\n throw new Error(\n \"Serializing an example selector is not currently supported\"\n );\n }\n if (this.outputParser !== undefined) {\n throw new Error(\n \"Serializing an output parser is not currently supported\"\n );\n }\n return {\n _type: this._getPromptType(),\n input_variables: this.inputVariables,\n example_prompt: this.examplePrompt.serialize(),\n example_separator: this.exampleSeparator,\n suffix: this.suffix,\n prefix: this.prefix,\n template_format: this.templateFormat,\n examples: this.examples,\n };\n }\n\n static async deserialize(\n data: SerializedFewShotTemplate\n ): Promise<FewShotPromptTemplate> {\n const { example_prompt } = data;\n if (!example_prompt) {\n throw new Error(\"Missing example prompt\");\n }\n const examplePrompt = await PromptTemplate.deserialize(example_prompt);\n\n let examples: Example[];\n\n if (Array.isArray(data.examples)) {\n examples = data.examples;\n } else {\n throw new Error(\n \"Invalid examples format. Only list or string are supported.\"\n );\n }\n\n return new FewShotPromptTemplate({\n inputVariables: data.input_variables,\n examplePrompt,\n examples,\n exampleSeparator: data.example_separator,\n prefix: data.prefix,\n suffix: data.suffix,\n templateFormat: data.template_format,\n });\n }\n}\n\nexport interface FewShotChatMessagePromptTemplateInput extends BasePromptTemplateInput<InputValues> {\n /**\n * Examples to format into the prompt. Exactly one of this or\n * {@link exampleSelector} must be\n * provided.\n */\n examples?: Example[];\n\n /**\n * An {@link BaseMessagePromptTemplate} | {@link BaseChatPromptTemplate} used to format a single example.\n */\n examplePrompt: BaseMessagePromptTemplate | BaseChatPromptTemplate;\n\n /**\n * String separator used to join the prefix, the examples, and suffix.\n *\n * @defaultValue `\"\\n\\n\"`\n */\n exampleSeparator?: string;\n\n /**\n * An {@link BaseExampleSelector} Examples to format into the prompt. Exactly one of this or\n * {@link examples} must be\n * provided.\n */\n exampleSelector?: BaseExampleSelector | undefined;\n\n /**\n * A prompt template string to put before the examples.\n *\n * @defaultValue `\"\"`\n */\n prefix?: string;\n\n /**\n * A prompt template string to put after the examples.\n *\n * @defaultValue `\"\"`\n */\n suffix?: string;\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/**\n * Chat prompt template that contains few-shot examples.\n * @augments BasePromptTemplateInput\n * @augments FewShotChatMessagePromptTemplateInput\n */\nexport class FewShotChatMessagePromptTemplate<\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 BaseChatPromptTemplate\n implements FewShotChatMessagePromptTemplateInput\n{\n lc_serializable = true;\n\n examples?: InputValues[];\n\n exampleSelector?: BaseExampleSelector | undefined;\n\n examplePrompt: BaseMessagePromptTemplate | BaseChatPromptTemplate;\n\n suffix = \"\";\n\n exampleSeparator = \"\\n\\n\";\n\n prefix = \"\";\n\n templateFormat: TemplateFormat = \"f-string\";\n\n validateTemplate = true;\n\n _getPromptType(): \"few_shot_chat\" {\n return \"few_shot_chat\";\n }\n\n static lc_name() {\n return \"FewShotChatMessagePromptTemplate\";\n }\n\n constructor(fields: FewShotChatMessagePromptTemplateInput) {\n super(fields);\n\n this.examples = fields.examples;\n this.examplePrompt = fields.examplePrompt;\n this.exampleSeparator = fields.exampleSeparator ?? \"\\n\\n\";\n this.exampleSelector = fields.exampleSelector;\n this.prefix = fields.prefix ?? \"\";\n this.suffix = fields.suffix ?? \"\";\n this.templateFormat = fields.templateFormat ?? \"f-string\";\n this.validateTemplate = fields.validateTemplate ?? true;\n\n if (this.examples !== undefined && this.exampleSelector !== undefined) {\n throw new Error(\n \"Only one of 'examples' and 'example_selector' should be provided\"\n );\n }\n\n if (this.examples === undefined && this.exampleSelector === undefined) {\n throw new Error(\n \"One of 'examples' and 'example_selector' should be provided\"\n );\n }\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 this.prefix + this.suffix,\n this.templateFormat,\n totalInputVariables\n );\n }\n }\n\n private async getExamples(\n inputVariables: InputValues\n ): Promise<InputValues[]> {\n if (this.examples !== undefined) {\n return this.examples;\n }\n if (this.exampleSelector !== undefined) {\n return this.exampleSelector.selectExamples(inputVariables);\n }\n\n throw new Error(\n \"One of 'examples' and 'example_selector' should be provided\"\n );\n }\n\n /**\n * Formats the list of values and returns a list of formatted messages.\n * @param values The values to format the prompt with.\n * @returns A promise that resolves to a string representing the formatted prompt.\n */\n async formatMessages(\n values: TypedPromptInputValues<RunInput>\n ): Promise<BaseMessage[]> {\n const allValues = await this.mergePartialAndUserVariables(values);\n let examples = await this.getExamples(allValues);\n\n examples = examples.map((example) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result: Record<string, any> = {};\n this.examplePrompt.inputVariables.forEach((inputVariable) => {\n result[inputVariable] = example[inputVariable];\n });\n return result;\n });\n\n const messages: BaseMessage[] = [];\n for (const example of examples) {\n const exampleMessages = await this.examplePrompt.formatMessages(example);\n messages.push(...exampleMessages);\n }\n return messages;\n }\n\n /**\n * Formats the prompt with the given values.\n * @param values The values to format the prompt with.\n * @returns A promise that resolves to a string representing the formatted prompt.\n */\n async format(values: TypedPromptInputValues<RunInput>): Promise<string> {\n const allValues = await this.mergePartialAndUserVariables(values);\n const examples = await this.getExamples(allValues);\n const exampleMessages = await Promise.all(\n examples.map((example) => this.examplePrompt.formatMessages(example))\n );\n const exampleStrings = exampleMessages\n .flat()\n .map((message) => message.content);\n const template = [this.prefix, ...exampleStrings, this.suffix].join(\n this.exampleSeparator\n );\n return renderTemplate(template, this.templateFormat, allValues);\n }\n\n /**\n * Partially formats the prompt with the given values.\n * @param values The values to partially format the prompt with.\n * @returns A promise that resolves to an instance of `FewShotChatMessagePromptTemplate` with the given values partially formatted.\n */\n async partial(\n values: PartialValues<PartialVariableName>\n ): Promise<FewShotChatMessagePromptTemplate<RunInput, PartialVariableName>> {\n const newInputVariables = this.inputVariables.filter(\n (variable) => !(variable in values)\n ) as Exclude<Extract<keyof RunInput, string>, PartialVariableName>[];\n const newPartialVariables = {\n ...(this.partialVariables ?? {}),\n ...values,\n } as PartialValues<PartialVariableName | PartialVariableName>;\n const promptDict = {\n ...this,\n inputVariables: newInputVariables,\n partialVariables: newPartialVariables,\n };\n return new FewShotChatMessagePromptTemplate<\n InputValues<Exclude<Extract<keyof RunInput, string>, PartialVariableName>>\n >(promptDict);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,IAAa,wBAAb,MAAa,8BACH,yBAEV;CACE,kBAAkB;CAElB;CAEA;CAEA;CAEA,SAAS;CAET,mBAAmB;CAEnB,SAAS;CAET,iBAAiC;CAEjC,mBAAmB;CAEnB,YAAY,OAAmC;AAC7C,QAAM,MAAM;AACZ,SAAO,OAAO,MAAM,MAAM;AAE1B,MAAI,KAAK,aAAa,UAAa,KAAK,oBAAoB,OAC1D,OAAM,IAAI,MACR,mEACD;AAGH,MAAI,KAAK,aAAa,UAAa,KAAK,oBAAoB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ACJ;AAMD,SAAO,IAAI,iCALQ;GACjB,GAAG;GACH,gBAAgB;GAChB,kBAAkB;GACnB,CAGY"}
@@ -53,12 +53,11 @@ var ImagePromptTemplate = class ImagePromptTemplate extends require_base.BasePro
53
53
  ...this.partialVariables ?? {},
54
54
  ...values
55
55
  };
56
- const promptDict = {
56
+ return new ImagePromptTemplate({
57
57
  ...this,
58
58
  inputVariables: newInputVariables,
59
59
  partialVariables: newPartialVariables
60
- };
61
- return new ImagePromptTemplate(promptDict);
60
+ });
62
61
  }
63
62
  /**
64
63
  * Formats the prompt template with the provided values.
@@ -84,8 +83,7 @@ var ImagePromptTemplate = class ImagePromptTemplate extends require_base.BasePro
84
83
  * @returns A Promise that resolves to a formatted prompt value.
85
84
  */
86
85
  async formatPromptValue(values) {
87
- const formattedPrompt = await this.format(values);
88
- return new require_prompt_values.ImagePromptValue(formattedPrompt);
86
+ return new require_prompt_values.ImagePromptValue(await this.format(values));
89
87
  }
90
88
  };
91
89
 
@@ -1 +1 @@
1
- {"version":3,"file":"image.cjs","names":["BasePromptTemplate","input: ImagePromptTemplateInput<RunInput, PartialVariableName>","totalInputVariables: string[]","checkValidTemplate","values: PartialValues<NewPartialVariableName>","values: TypedPromptInputValues<RunInput>","formatted: Record<string, any>","renderTemplate","output: ImageContent","ImagePromptValue"],"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(formattedPrompt);\n }\n}\n"],"mappings":";;;;;;;;AAsDA,IAAa,sBAAb,MAAa,4BAKHA,gCAAoE;CAC5E,OAAO,UAAU;AACf,SAAO;CACR;CAED,eAAe;EAAC;EAAkB;EAAW;CAAQ;CAErD;CAEA,iBAAiC;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AAkB,MAAM,KAAK,OAAO,OAAO;AACjD,SAAO,IAAII,uCAAiB;CAC7B;AACF"}
1
+ {"version":3,"file":"image.cjs","names":["BasePromptTemplate","renderTemplate","ImagePromptValue"],"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(formattedPrompt);\n }\n}\n"],"mappings":";;;;;;;;AAsDA,IAAa,sBAAb,MAAa,4BAKHA,gCAAoE;CAC5E,OAAO,UAAU;AACf,SAAO;;CAGT,eAAe;EAAC;EAAkB;EAAW;EAAQ;CAErD;CAEA,iBAAiC;CAEjC,mBAAmB;;;;;;CAOnB;CAEA,YAAY,OAAgE;AAC1E,QAAM,MAAM;AACZ,OAAK,WAAW,MAAM;AACtB,OAAK,iBAAiB,MAAM,kBAAkB,KAAK;AACnD,OAAK,mBAAmB,MAAM,oBAAoB,KAAK;AACvD,OAAK,0BAA0B,MAAM;AAErC,MAAI,KAAK,kBAAkB;GACzB,IAAI,sBAAgC,KAAK;AACzC,OAAI,KAAK,iBACP,uBAAsB,oBAAoB,OACxC,OAAO,KAAK,KAAK,iBAAiB,CACnC;AAEH,uCACE,CACE;IAAE,MAAM;IAAa,WAAW,KAAK;IAAU,CAChD,EACD,KAAK,gBACL,oBACD;;;CAIL,iBAA2B;AACzB,SAAO;;;;;;;CAQT,MAAM,QACJ,QACA;EACA,MAAM,oBAAoB,KAAK,eAAe,QAC3C,OAAO,EAAE,MAAM,QACjB;EACD,MAAM,sBAAsB;GAC1B,GAAI,KAAK,oBAAoB,EAAE;GAC/B,GAAG;GACJ;AAMD,SAAO,IAAI,oBALQ;GACjB,GAAG;GACH,gBAAgB;GAChB,kBAAkB;GACnB,CAKY;;;;;;;CAQf,MAAM,OACJ,QACuB;EAEvB,MAAM,YAAiC,EAAE;AACzC,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,SAAS,CACtD,KAAI,OAAO,UAAU,SACnB,WAAU,OAAOC,gCAAe,OAAO,KAAK,gBAAgB,OAAO;MAEnE,WAAU,OAAO;EAGrB,MAAM,MAAM,OAAO,OAAO,UAAU;EACpC,MAAM,SAAS,OAAO,UAAU,UAAU;AAC1C,MAAI,CAAC,IACH,OAAM,IAAI,MAAM,oCAAoC;AAEtD,MAAI,OAAO,QAAQ,SACjB,OAAM,IAAI,MAAM,wBAAwB;EAE1C,MAAM,SAAuB,EAAE,KAAK;AACpC,MAAI,OACF,QAAO,SAAS;AAElB,SAAO;;;;;;;;CAST,MAAM,kBACJ,QAC2B;AAE3B,SAAO,IAAIC,uCADa,MAAM,KAAK,OAAO,OAAO,CACL"}
@@ -5,7 +5,6 @@ import { BasePromptTemplate, BasePromptTemplateInput, TypedPromptInputValues } f
5
5
  import { TemplateFormat } from "./template.cjs";
6
6
 
7
7
  //#region src/prompts/image.d.ts
8
-
9
8
  /**
10
9
  * Inputs to create a {@link ImagePromptTemplate}
11
10
  * @augments BasePromptTemplateInput
@@ -1 +1 @@
1
- {"version":3,"file":"image.d.cts","names":["ContentBlock","ImagePromptValue","ImageContent","InputValues","PartialValues","BasePromptTemplate","BasePromptTemplateInput","TypedPromptInputValues","TemplateFormat","ImagePromptTemplateInput","RunInput","PartialVariableName","Record","ImagePromptTemplate","NewPartialVariableName","FormatOutput","Extract","Exclude","Promise"],"sources":["../../src/prompts/image.d.ts"],"sourcesContent":["import { ContentBlock } from \"../messages/index.js\";\nimport { ImagePromptValue, ImageContent } from \"../prompt_values.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport { BasePromptTemplate, BasePromptTemplateInput, TypedPromptInputValues } from \"./base.js\";\nimport { TemplateFormat } from \"./template.js\";\n/**\n * Inputs to create a {@link ImagePromptTemplate}\n * @augments BasePromptTemplateInput\n */\nexport interface ImagePromptTemplateInput<RunInput extends InputValues = any, PartialVariableName extends string = any> extends BasePromptTemplateInput<RunInput, PartialVariableName> {\n /**\n * The prompt template\n */\n template: Record<string, unknown>;\n /**\n * The format of the prompt template. Options are 'f-string'\n *\n * @defaultValue 'f-string'\n */\n templateFormat?: TemplateFormat;\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}\n/**\n * An image prompt template for a multimodal model.\n */\nexport declare class ImagePromptTemplate<RunInput extends InputValues = any, PartialVariableName extends string = any> extends BasePromptTemplate<RunInput, ImagePromptValue, PartialVariableName> {\n static lc_name(): string;\n lc_namespace: string[];\n template: Record<string, unknown>;\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: ImagePromptTemplateInput<RunInput, PartialVariableName>);\n _getPromptType(): \"prompt\";\n /**\n * Partially applies values to the prompt template.\n * @param values The values to be partially applied to the prompt template.\n * @returns A new instance of ImagePromptTemplate with the partially applied values.\n */\n partial<NewPartialVariableName extends string>(values: PartialValues<NewPartialVariableName>): Promise<ImagePromptTemplate<InputValues<Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>>, any>>;\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<FormatOutput = ImageContent>(values: TypedPromptInputValues<RunInput>): Promise<FormatOutput>;\n /**\n * Formats the prompt given the input values and returns a formatted\n * prompt value.\n * @param values The input values to format the prompt.\n * @returns A Promise that resolves to a formatted prompt value.\n */\n formatPromptValue(values: TypedPromptInputValues<RunInput>): Promise<ImagePromptValue>;\n}\n//# sourceMappingURL=image.d.ts.map"],"mappings":";;;;;;;;;;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,CAAwB,QAAA,EAAU,mBAAA;EAHzB;;;EAOjB,QAAA,EAAU,MAAA;EAOO;;;;;EAAjB,cAAA,GAAiB,cAAA;EAdA;;;;;EAqBjB,gBAAA;EAdU;;;;;EAqBV,uBAAA,GAA0B,YAAA;AAAA;;AAM5B;;cAAa,mBAAA,kBAEM,WAAA,0DAGT,kBAAA,CAAmB,QAAA,EAAU,gBAAA,EAAkB,mBAAA;EAAA,OAChD,OAAA,CAAA;EAIP,YAAA;EAEA,QAAA,EAAU,MAAA;EAEV,cAAA,EAAgB,cAAA;EAEhB,gBAAA;EAFgB;;;;;EAShB,uBAAA,GAA0B,YAAA;EAE1B,WAAA,CAAY,KAAA,EAAO,wBAAA,CAAyB,QAAA,EAAU,mBAAA;EAwBtD,cAAA,CAAA;EAU+C;;;;;EADzC,OAAA,uCAAA,CACJ,MAAA,EAAQ,aAAA,CAAc,sBAAA,IAAuB,OAAA,CAAA,mBAAA,CAAA,WAAA,CAAA,OAAA,CAAA,OAAA,OAAA,QAAA,WAAA,sBAAA;EA0BnB;;;;;EAAtB,MAAA,gBAAsB,YAAA,CAAA,CAC1B,MAAA,EAAQ,sBAAA,CAAuB,QAAA,IAC9B,OAAA,CAAQ,YAAA;EAgCD;;;;;;EADJ,iBAAA,CACJ,MAAA,EAAQ,sBAAA,CAAuB,QAAA,IAC9B,OAAA,CAAQ,gBAAA;AAAA"}
@@ -6,7 +6,6 @@ import { BasePromptTemplate, BasePromptTemplateInput, TypedPromptInputValues } f
6
6
  import { TemplateFormat } from "./template.js";
7
7
 
8
8
  //#region src/prompts/image.d.ts
9
-
10
9
  /**
11
10
  * Inputs to create a {@link ImagePromptTemplate}
12
11
  * @augments BasePromptTemplateInput
@@ -1 +1 @@
1
- {"version":3,"file":"image.d.ts","names":["ContentBlock","ImagePromptValue","ImageContent","InputValues","PartialValues","BasePromptTemplate","BasePromptTemplateInput","TypedPromptInputValues","TemplateFormat","ImagePromptTemplateInput","RunInput","PartialVariableName","Record","ImagePromptTemplate","NewPartialVariableName","FormatOutput","Extract","Exclude","Promise"],"sources":["../../src/prompts/image.d.ts"],"sourcesContent":["import { ContentBlock } from \"../messages/index.js\";\nimport { ImagePromptValue, ImageContent } from \"../prompt_values.js\";\nimport type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport { BasePromptTemplate, BasePromptTemplateInput, TypedPromptInputValues } from \"./base.js\";\nimport { TemplateFormat } from \"./template.js\";\n/**\n * Inputs to create a {@link ImagePromptTemplate}\n * @augments BasePromptTemplateInput\n */\nexport interface ImagePromptTemplateInput<RunInput extends InputValues = any, PartialVariableName extends string = any> extends BasePromptTemplateInput<RunInput, PartialVariableName> {\n /**\n * The prompt template\n */\n template: Record<string, unknown>;\n /**\n * The format of the prompt template. Options are 'f-string'\n *\n * @defaultValue 'f-string'\n */\n templateFormat?: TemplateFormat;\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}\n/**\n * An image prompt template for a multimodal model.\n */\nexport declare class ImagePromptTemplate<RunInput extends InputValues = any, PartialVariableName extends string = any> extends BasePromptTemplate<RunInput, ImagePromptValue, PartialVariableName> {\n static lc_name(): string;\n lc_namespace: string[];\n template: Record<string, unknown>;\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: ImagePromptTemplateInput<RunInput, PartialVariableName>);\n _getPromptType(): \"prompt\";\n /**\n * Partially applies values to the prompt template.\n * @param values The values to be partially applied to the prompt template.\n * @returns A new instance of ImagePromptTemplate with the partially applied values.\n */\n partial<NewPartialVariableName extends string>(values: PartialValues<NewPartialVariableName>): Promise<ImagePromptTemplate<InputValues<Exclude<Extract<keyof RunInput, string>, NewPartialVariableName>>, any>>;\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<FormatOutput = ImageContent>(values: TypedPromptInputValues<RunInput>): Promise<FormatOutput>;\n /**\n * Formats the prompt given the input values and returns a formatted\n * prompt value.\n * @param values The input values to format the prompt.\n * @returns A Promise that resolves to a formatted prompt value.\n */\n formatPromptValue(values: TypedPromptInputValues<RunInput>): Promise<ImagePromptValue>;\n}\n//# sourceMappingURL=image.d.ts.map"],"mappings":";;;;;;;;;;;;AASA;AAA2DG,UAA1CM,wBAA0CN,CAAAA,iBAAAA,WAAAA,GAAAA,GAAAA,EAAAA,4BAAAA,MAAAA,GAAAA,GAAAA,CAAAA,SAAqEG,uBAArEH,CAA6FO,QAA7FP,EAAuGQ,mBAAvGR,CAAAA,CAAAA;EAA6FO;;;EAUnIF,QAAAA,EANPI,MAMOJ,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAYSR;;AAtByH;AA2BvJ;;EAAkJU,cAAAA,CAAAA,EAjB7HF,cAiB6HE;EAAUT;;;;;EAY5GS,gBAAAA,CAAAA,EAAAA,OAAAA;EAAUC;;;;;EAOyFK,uBAAAA,CAAAA,EAxBrHhB,YAwBqHgB;;;;;AAAhDE,cAnB9EL,mBAmB8EK,CAAAA,iBAnBzCf,WAmByCe,GAAAA,GAAAA,EAAAA,4BAAAA,MAAAA,GAAAA,GAAAA,CAAAA,SAnB4Bb,kBAmB5Ba,CAnB+CR,QAmB/CQ,EAnByDjB,gBAmBzDiB,EAnB2EP,mBAmB3EO,CAAAA,CAAAA;EAMzEhB,OAAAA,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAA6CQ,YAAAA,EAAAA,MAAAA,EAAAA;EAAvBH,QAAAA,EAtBlCK,MAsBkCL,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAA2CQ,cAAAA,EArBvEP,cAqBuEO;EAARG,gBAAAA,EAAAA,OAAAA;EAO9BR;;;;;EAhC4F,uBAAA,CAAA,EAWnHV,YAXmH;qBAY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emplate {
53
53
  ...this.partialVariables ?? {},
54
54
  ...values
55
55
  };
56
- const promptDict = {
56
+ return new ImagePromptTemplate({
57
57
  ...this,
58
58
  inputVariables: newInputVariables,
59
59
  partialVariables: newPartialVariables
60
- };
61
- return new ImagePromptTemplate(promptDict);
60
+ });
62
61
  }
63
62
  /**
64
63
  * Formats the prompt template with the provided values.
@@ -84,8 +83,7 @@ var ImagePromptTemplate = class ImagePromptTemplate extends BasePromptTemplate {
84
83
  * @returns A Promise that resolves to a formatted prompt value.
85
84
  */
86
85
  async formatPromptValue(values) {
87
- const formattedPrompt = await this.format(values);
88
- return new ImagePromptValue(formattedPrompt);
86
+ return new ImagePromptValue(await this.format(values));
89
87
  }
90
88
  };
91
89
 
@@ -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 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(formattedPrompt);\n }\n}\n"],"mappings":";;;;;;;;AAsDA,IAAa,sBAAb,MAAa,4BAKH,mBAAoE;CAC5E,OAAO,UAAU;AACf,SAAO;CACR;CAED,eAAe;EAAC;EAAkB;EAAW;CAAQ;CAErD;CAEA,iBAAiC;CAEjC,mBAAmB;;;;;;CAOnB;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":[],"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(formattedPrompt);\n }\n}\n"],"mappings":";;;;;;;;AAsDA,IAAa,sBAAb,MAAa,4BAKH,mBAAoE;CAC5E,OAAO,UAAU;AACf,SAAO;;CAGT,eAAe;EAAC;EAAkB;EAAW;EAAQ;CAErD;CAEA,iBAAiC;CAEjC,mBAAmB;;;;;;CAOnB;CAEA,YAAY,OAAgE;AAC1E,QAAM,MAAM;AACZ,OAAK,WAAW,MAAM;AACtB,OAAK,iBAAiB,MAAM,kBAAkB,KAAK;AACnD,OAAK,mBAAmB,MAAM,oBAAoB,KAAK;AACvD,OAAK,0BAA0B,MAAM;AAErC,MAAI,KAAK,kBAAkB;GACzB,IAAI,sBAAgC,KAAK;AACzC,OAAI,KAAK,iBACP,uBAAsB,oBAAoB,OACxC,OAAO,KAAK,KAAK,iBAAiB,CACnC;AAEH,sBACE,CACE;IAAE,MAAM;IAAa,WAAW,KAAK;IAAU,CAChD,EACD,KAAK,gBACL,oBACD;;;CAIL,iBAA2B;AACzB,SAAO;;;;;;;CAQT,MAAM,QACJ,QACA;EACA,MAAM,oBAAoB,KAAK,eAAe,QAC3C,OAAO,EAAE,MAAM,QACjB;EACD,MAAM,sBAAsB;GAC1B,GAAI,KAAK,oBAAoB,EAAE;GAC/B,GAAG;GACJ;AAMD,SAAO,IAAI,oBALQ;GACjB,GAAG;GACH,gBAAgB;GAChB,kBAAkB;GACnB,CAKY;;;;;;;CAQf,MAAM,OACJ,QACuB;EAEvB,MAAM,YAAiC,EAAE;AACzC,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,SAAS,CACtD,KAAI,OAAO,UAAU,SACnB,WAAU,OAAO,eAAe,OAAO,KAAK,gBAAgB,OAAO;MAEnE,WAAU,OAAO;EAGrB,MAAM,MAAM,OAAO,OAAO,UAAU;EACpC,MAAM,SAAS,OAAO,UAAU,UAAU;AAC1C,MAAI,CAAC,IACH,OAAM,IAAI,MAAM,oCAAoC;AAEtD,MAAI,OAAO,QAAQ,SACjB,OAAM,IAAI,MAAM,wBAAwB;EAE1C,MAAM,SAAuB,EAAE,KAAK;AACpC,MAAI,OACF,QAAO,SAAS;AAElB,SAAO;;;;;;;;CAST,MAAM,kBACJ,QAC2B;AAE3B,SAAO,IAAI,iBADa,MAAM,KAAK,OAAO,OAAO,CACL"}
@@ -1,4 +1,5 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
3
  const require_base = require('./base.cjs');
3
4
  const require_string = require('./string.cjs');
4
5
  const require_template = require('./template.cjs');
@@ -11,8 +12,7 @@ const require_pipeline = require('./pipeline.cjs');
11
12
  const require_structured = require('./structured.cjs');
12
13
 
13
14
  //#region src/prompts/index.ts
14
- var prompts_exports = {};
15
- require_rolldown_runtime.__export(prompts_exports, {
15
+ var prompts_exports = /* @__PURE__ */ require_runtime.__exportAll({
16
16
  AIMessagePromptTemplate: () => require_chat.AIMessagePromptTemplate,
17
17
  BaseChatPromptTemplate: () => require_chat.BaseChatPromptTemplate,
18
18
  BaseMessagePromptTemplate: () => require_chat.BaseMessagePromptTemplate,
@@ -1,4 +1,4 @@
1
- import { __export } from "../_virtual/rolldown_runtime.js";
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { BasePromptTemplate } from "./base.js";
3
3
  import { BaseStringPromptTemplate } from "./string.js";
4
4
  import { DEFAULT_FORMATTER_MAPPING, DEFAULT_PARSER_MAPPING, checkValidTemplate, interpolateFString, interpolateMustache, parseFString, parseMustache, parseTemplate, renderTemplate } from "./template.js";
@@ -11,8 +11,7 @@ import { PipelinePromptTemplate } from "./pipeline.js";
11
11
  import { StructuredPrompt } from "./structured.js";
12
12
 
13
13
  //#region src/prompts/index.ts
14
- var prompts_exports = {};
15
- __export(prompts_exports, {
14
+ var prompts_exports = /* @__PURE__ */ __exportAll({
16
15
  AIMessagePromptTemplate: () => AIMessagePromptTemplate,
17
16
  BaseChatPromptTemplate: () => BaseChatPromptTemplate,
18
17
  BaseMessagePromptTemplate: () => BaseMessagePromptTemplate,
@@ -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 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;EACv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AAmB;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","ChatPromptTemplate"],"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;;CAGT;CAEA;CAEA,YAAY,OAAwD;AAClE,QAAM;GAAE,GAAG;GAAO,gBAAgB,EAAE;GAAE,CAAC;AACvC,OAAK,kBAAkB,MAAM;AAC7B,OAAK,cAAc,MAAM;AACzB,OAAK,iBAAiB,KAAK,oBAAoB;;;;;;CAOjD,AAAU,qBAAqB;EAC7B,MAAM,qBAAqB,KAAK,gBAAgB,KAC7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Input } from "./base.cjs";
3
3
  import { SerializedBasePromptTemplate } from "./serde.cjs";
4
4
 
5
5
  //#region src/prompts/pipeline.d.ts
6
-
7
6
  /**
8
7
  * Type that includes the name of the prompt and the prompt itself.
9
8
  */
@@ -1 +1 @@
1
- {"version":3,"file":"pipeline.d.cts","names":["InputValues","PartialValues","SerializedBasePromptTemplate","BasePromptTemplate","BasePromptTemplateInput","PipelinePromptParams","PromptTemplateType","PipelinePromptTemplateInput","Omit","PipelinePromptTemplate","Promise"],"sources":["../../src/prompts/pipeline.d.ts"],"sourcesContent":["import type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport type { SerializedBasePromptTemplate } from \"./serde.js\";\nimport { BasePromptTemplate, type BasePromptTemplateInput } from \"./base.js\";\n/**\n * Type that includes the name of the prompt and the prompt itself.\n */\nexport type PipelinePromptParams<PromptTemplateType extends BasePromptTemplate> = {\n name: string;\n prompt: PromptTemplateType;\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<PromptTemplateType extends BasePromptTemplate> = Omit<BasePromptTemplateInput, \"inputVariables\"> & {\n pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];\n finalPrompt: PromptTemplateType;\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 declare class PipelinePromptTemplate<PromptTemplateType extends BasePromptTemplate> extends BasePromptTemplate {\n static lc_name(): string;\n pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];\n finalPrompt: PromptTemplateType;\n constructor(input: PipelinePromptTemplateInput<PromptTemplateType>);\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(): string[];\n protected static extractRequiredInputValues(allValues: InputValues, requiredValueNames: string[]): InputValues;\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 formatPipelinePrompts(values: InputValues): Promise<InputValues>;\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 formatPromptValue(values: InputValues): Promise<PromptTemplateType[\"PromptValueReturnType\"]>;\n format(values: InputValues): Promise<string>;\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 partial(values: PartialValues): Promise<PipelinePromptTemplate<PromptTemplateType>>;\n serialize(): SerializedBasePromptTemplate;\n _getPromptType(): string;\n}\n//# sourceMappingURL=pipeline.d.ts.map"],"mappings":";;;;;;;;AAMA;AASYO,KATAF,oBASAE,CAAAA,2BATgDJ,kBASrB,CAAA,GAAA;EAA4BA,IAAAA,EAAAA,MAAAA;EAA2BC,MAAAA,EAPlFE,kBAOkFF;CAALI;;;;AAEtD;AA+CnC;AAAuEL,KAjD3DI,2BAiD2DJ,CAAAA,2BAjDJA,kBAiDIA,CAAAA,GAjDkBK,IAiDlBL,CAj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AA;EAML,MAAA,CAAO,MAAA,EAAQ,WAAA,GAAc,OAAA;EAvCxB;;;;;;EAiDL,OAAA,CACJ,MAAA,EAAQ,aAAA,GACP,OAAA,CAAQ,sBAAA,CAAuB,kBAAA;EAYlC,SAAA,CAAA,GAAa,4BAAA;EAIb,cAAA,CAAA;AAAA"}
@@ -3,7 +3,6 @@ import { BasePromptTemplate, BasePromptTemplateInput } from "./base.js";
3
3
  import { SerializedBasePromptTemplate } from "./serde.js";
4
4
 
5
5
  //#region src/prompts/pipeline.d.ts
6
-
7
6
  /**
8
7
  * Type that includes the name of the prompt and the prompt itself.
9
8
  */
@@ -1 +1 @@
1
- {"version":3,"file":"pipeline.d.ts","names":["InputValues","PartialValues","SerializedBasePromptTemplate","BasePromptTemplate","BasePromptTemplateInput","PipelinePromptParams","PromptTemplateType","PipelinePromptTemplateInput","Omit","PipelinePromptTemplate","Promise"],"sources":["../../src/prompts/pipeline.d.ts"],"sourcesContent":["import type { InputValues, PartialValues } from \"../utils/types/index.js\";\nimport type { SerializedBasePromptTemplate } from \"./serde.js\";\nimport { BasePromptTemplate, type BasePromptTemplateInput } from \"./base.js\";\n/**\n * Type that includes the name of the prompt and the prompt itself.\n */\nexport type PipelinePromptParams<PromptTemplateType extends BasePromptTemplate> = {\n name: string;\n prompt: PromptTemplateType;\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<PromptTemplateType extends BasePromptTemplate> = Omit<BasePromptTemplateInput, \"inputVariables\"> & {\n pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];\n finalPrompt: PromptTemplateType;\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 declare class PipelinePromptTemplate<PromptTemplateType extends BasePromptTemplate> extends BasePromptTemplate {\n static lc_name(): string;\n pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];\n finalPrompt: PromptTemplateType;\n constructor(input: PipelinePromptTemplateInput<PromptTemplateType>);\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(): string[];\n protected static extractRequiredInputValues(allValues: InputValues, requiredValueNames: string[]): InputValues;\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 formatPipelinePrompts(values: InputValues): Promise<InputValues>;\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 formatPromptValue(values: InputValues): Promise<PromptTemplateType[\"PromptValueReturnType\"]>;\n format(values: InputValues): Promise<string>;\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 partial(values: PartialValues): Promise<PipelinePromptTemplate<PromptTemplateType>>;\n serialize(): SerializedBasePromptTemplate;\n _getPromptType(): string;\n}\n//# sourceMappingURL=pipeline.d.ts.map"],"mappings":";;;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,UAeU,kBAAA,CAAA;EAAA,iBAcO,0BAAA,CACf,SAAA,EAAW,WAAA,EACX,kBAAA,aAA4B,WAAA;EA3BX;;;;;EAAA,UAwCH,qBAAA,CACd,MAAA,EAAQ,WAAA,GACP,OAAA,CAAQ,WAAA;EAhBT;;;;;EA+CI,iBAAA,CACJ,MAAA,EAAQ,WAAA,GACP,OAAA,CAAQ,kBAAA;EAML,MAAA,CAAO,MAAA,EAAQ,WAAA,GAAc,OAAA;EAvCxB;;;;;;EAiDL,OAAA,CACJ,MAAA,EAAQ,aAAA,GACP,OAAA,CAAQ,sBAAA,CAAuB,kBAAA;EAYlC,SAAA,CAAA,GAAa,4BAAA;EAIb,cAAA,CAAA;AAAA"}
@@ -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 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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M,KAAK,sBAAsB,OAAO,CAAC;CACzE;;;;;;;CAQD,MAAM,QACJC,QACqD;EACrD,MAAM,aAAa,EAAE,GAAG,KAAM;EAC9B,WAAW,iBAAiB,KAAK,eAAe,OAC9C,CAAC,OAAO,EAAE,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.js","names":[],"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;;CAGT;CAEA;CAEA,YAAY,OAAwD;AAClE,QAAM;GAAE,GAAG;GAAO,gBAAgB,EAAE;GAAE,CAA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;AACD,SAAO,IAAI,uBAA2C,WAAW;;CAGnE,YAA0C;AACxC,QAAM,IAAI,MAAM,mBAAmB;;CAGrC,iBAAyB;AACvB,SAAO"}
@@ -67,18 +67,17 @@ var PromptTemplate = class PromptTemplate extends require_string.BaseStringPromp
67
67
  * @returns The final prompt template generated.
68
68
  */
69
69
  static fromExamples(examples, suffix, inputVariables, exampleSeparator = "\n\n", prefix = "") {
70
- const template = [
71
- prefix,
72
- ...examples,
73
- suffix
74
- ].join(exampleSeparator);
75
70
  return new PromptTemplate({
76
71
  inputVariables,
77
- template
72
+ template: [
73
+ prefix,
74
+ ...examples,
75
+ suffix
76
+ ].join(exampleSeparator)
78
77
  });
79
78
  }
80
79
  static fromTemplate(template, options) {
81
- const { templateFormat = "f-string",...rest } = options ?? {};
80
+ const { templateFormat = "f-string", ...rest } = options ?? {};
82
81
  const names = /* @__PURE__ */ new Set();
83
82
  require_template.parseTemplate(template, templateFormat).forEach((node) => {
84
83
  if (node.type === "variable") names.add(node.name);
@@ -101,12 +100,11 @@ var PromptTemplate = class PromptTemplate extends require_string.BaseStringPromp
101
100
  ...this.partialVariables ?? {},
102
101
  ...values
103
102
  };
104
- const promptDict = {
103
+ return new PromptTemplate({
105
104
  ...this,
106
105
  inputVariables: newInputVariables,
107
106
  partialVariables: newPartialVariables
108
- };
109
- return new PromptTemplate(promptDict);
107
+ });
110
108
  }
111
109
  serialize() {
112
110
  if (this.outputParser !== void 0) throw new Error("Cannot serialize a prompt template with an output parser");
@@ -119,12 +117,11 @@ var PromptTemplate = class PromptTemplate extends require_string.BaseStringPromp
119
117
  }
120
118
  static async deserialize(data) {
121
119
  if (!data.template) throw new Error("Prompt template must have a template");
122
- const res = new PromptTemplate({
120
+ return new PromptTemplate({
123
121
  inputVariables: data.input_variables,
124
122
  template: data.template,
125
123
  templateFormat: data.template_format
126
124
  });
127
- return res;
128
125
  }
129
126
  };
130
127