@langchain/core 1.0.0-alpha.6 → 1.0.0

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 (245) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/LICENSE +6 -6
  3. package/README.md +2 -23
  4. package/dist/agents.d.ts.map +1 -1
  5. package/dist/caches/base.d.cts.map +1 -1
  6. package/dist/callbacks/base.d.cts.map +1 -1
  7. package/dist/callbacks/base.d.ts.map +1 -1
  8. package/dist/callbacks/manager.cjs +9 -64
  9. package/dist/callbacks/manager.cjs.map +1 -1
  10. package/dist/callbacks/manager.d.cts +1 -23
  11. package/dist/callbacks/manager.d.cts.map +1 -1
  12. package/dist/callbacks/manager.d.ts +1 -23
  13. package/dist/callbacks/manager.d.ts.map +1 -1
  14. package/dist/callbacks/manager.js +10 -63
  15. package/dist/callbacks/manager.js.map +1 -1
  16. package/dist/chat_history.cjs +0 -4
  17. package/dist/chat_history.cjs.map +1 -1
  18. package/dist/chat_history.d.cts +1 -3
  19. package/dist/chat_history.d.cts.map +1 -1
  20. package/dist/chat_history.d.ts +1 -3
  21. package/dist/chat_history.d.ts.map +1 -1
  22. package/dist/chat_history.js +0 -4
  23. package/dist/chat_history.js.map +1 -1
  24. package/dist/document_loaders/base.cjs +1 -13
  25. package/dist/document_loaders/base.cjs.map +1 -1
  26. package/dist/document_loaders/base.d.cts +0 -9
  27. package/dist/document_loaders/base.d.cts.map +1 -1
  28. package/dist/document_loaders/base.d.ts +0 -9
  29. package/dist/document_loaders/base.d.ts.map +1 -1
  30. package/dist/document_loaders/base.js +1 -13
  31. package/dist/document_loaders/base.js.map +1 -1
  32. package/dist/document_loaders/langsmith.d.cts +1 -1
  33. package/dist/language_models/base.cjs.map +1 -1
  34. package/dist/language_models/base.d.cts +0 -16
  35. package/dist/language_models/base.d.cts.map +1 -1
  36. package/dist/language_models/base.d.ts +0 -16
  37. package/dist/language_models/base.d.ts.map +1 -1
  38. package/dist/language_models/base.js.map +1 -1
  39. package/dist/language_models/chat_models.cjs +10 -83
  40. package/dist/language_models/chat_models.cjs.map +1 -1
  41. package/dist/language_models/chat_models.d.cts +21 -55
  42. package/dist/language_models/chat_models.d.cts.map +1 -1
  43. package/dist/language_models/chat_models.d.ts +21 -55
  44. package/dist/language_models/chat_models.d.ts.map +1 -1
  45. package/dist/language_models/chat_models.js +11 -83
  46. package/dist/language_models/chat_models.js.map +1 -1
  47. package/dist/language_models/llms.cjs +0 -56
  48. package/dist/language_models/llms.cjs.map +1 -1
  49. package/dist/language_models/llms.d.cts +1 -43
  50. package/dist/language_models/llms.d.cts.map +1 -1
  51. package/dist/language_models/llms.d.ts +1 -43
  52. package/dist/language_models/llms.d.ts.map +1 -1
  53. package/dist/language_models/llms.js +0 -56
  54. package/dist/language_models/llms.js.map +1 -1
  55. package/dist/load/import_map.cjs +1 -7
  56. package/dist/load/import_map.cjs.map +1 -1
  57. package/dist/load/import_map.js +1 -7
  58. package/dist/load/import_map.js.map +1 -1
  59. package/dist/messages/ai.cjs +4 -0
  60. package/dist/messages/ai.cjs.map +1 -1
  61. package/dist/messages/ai.js +4 -0
  62. package/dist/messages/ai.js.map +1 -1
  63. package/dist/messages/block_translators/anthropic.cjs +191 -144
  64. package/dist/messages/block_translators/anthropic.cjs.map +1 -1
  65. package/dist/messages/block_translators/anthropic.js +191 -144
  66. package/dist/messages/block_translators/anthropic.js.map +1 -1
  67. package/dist/messages/block_translators/index.cjs +2 -2
  68. package/dist/messages/block_translators/index.cjs.map +1 -1
  69. package/dist/messages/block_translators/index.js +4 -4
  70. package/dist/messages/block_translators/index.js.map +1 -1
  71. package/dist/messages/block_translators/openai.cjs +78 -22
  72. package/dist/messages/block_translators/openai.cjs.map +1 -1
  73. package/dist/messages/block_translators/openai.js +78 -22
  74. package/dist/messages/block_translators/openai.js.map +1 -1
  75. package/dist/messages/content/tools.cjs +1 -5
  76. package/dist/messages/content/tools.cjs.map +1 -1
  77. package/dist/messages/content/tools.d.cts +1 -85
  78. package/dist/messages/content/tools.d.cts.map +1 -1
  79. package/dist/messages/content/tools.d.ts +1 -85
  80. package/dist/messages/content/tools.d.ts.map +1 -1
  81. package/dist/messages/content/tools.js +1 -5
  82. package/dist/messages/content/tools.js.map +1 -1
  83. package/dist/messages/metadata.cjs.map +1 -1
  84. package/dist/messages/metadata.d.cts +3 -0
  85. package/dist/messages/metadata.d.cts.map +1 -1
  86. package/dist/messages/metadata.d.ts +3 -0
  87. package/dist/messages/metadata.d.ts.map +1 -1
  88. package/dist/messages/metadata.js.map +1 -1
  89. package/dist/messages/tool.cjs +2 -0
  90. package/dist/messages/tool.cjs.map +1 -1
  91. package/dist/messages/tool.d.cts +2 -0
  92. package/dist/messages/tool.d.cts.map +1 -1
  93. package/dist/messages/tool.d.ts +2 -0
  94. package/dist/messages/tool.d.ts.map +1 -1
  95. package/dist/messages/tool.js +2 -0
  96. package/dist/messages/tool.js.map +1 -1
  97. package/dist/output_parsers/json.cjs +5 -0
  98. package/dist/output_parsers/json.cjs.map +1 -1
  99. package/dist/output_parsers/json.d.cts +2 -0
  100. package/dist/output_parsers/json.d.cts.map +1 -1
  101. package/dist/output_parsers/json.d.ts +2 -0
  102. package/dist/output_parsers/json.d.ts.map +1 -1
  103. package/dist/output_parsers/json.js +5 -0
  104. package/dist/output_parsers/json.js.map +1 -1
  105. package/dist/prompts/base.cjs +0 -36
  106. package/dist/prompts/base.cjs.map +1 -1
  107. package/dist/prompts/base.d.cts +0 -16
  108. package/dist/prompts/base.d.cts.map +1 -1
  109. package/dist/prompts/base.d.ts +0 -16
  110. package/dist/prompts/base.d.ts.map +1 -1
  111. package/dist/prompts/base.js +0 -36
  112. package/dist/prompts/base.js.map +1 -1
  113. package/dist/prompts/chat.cjs +1 -5
  114. package/dist/prompts/chat.cjs.map +1 -1
  115. package/dist/prompts/chat.d.cts +1 -4
  116. package/dist/prompts/chat.d.cts.map +1 -1
  117. package/dist/prompts/chat.d.ts +1 -4
  118. package/dist/prompts/chat.d.ts.map +1 -1
  119. package/dist/prompts/chat.js +1 -5
  120. package/dist/prompts/chat.js.map +1 -1
  121. package/dist/prompts/dict.d.cts +1 -1
  122. package/dist/prompts/dict.d.ts +1 -1
  123. package/dist/prompts/few_shot.d.cts +2 -2
  124. package/dist/prompts/few_shot.d.ts +2 -2
  125. package/dist/prompts/image.d.cts +1 -1
  126. package/dist/prompts/image.d.ts +1 -1
  127. package/dist/prompts/index.d.cts +2 -2
  128. package/dist/prompts/index.d.ts +2 -2
  129. package/dist/prompts/pipeline.d.cts +1 -1
  130. package/dist/prompts/pipeline.d.ts +1 -1
  131. package/dist/prompts/prompt.d.cts +2 -2
  132. package/dist/prompts/prompt.d.ts +2 -2
  133. package/dist/retrievers/index.cjs +3 -18
  134. package/dist/retrievers/index.cjs.map +1 -1
  135. package/dist/retrievers/index.d.cts +2 -27
  136. package/dist/retrievers/index.d.cts.map +1 -1
  137. package/dist/retrievers/index.d.ts +2 -27
  138. package/dist/retrievers/index.d.ts.map +1 -1
  139. package/dist/retrievers/index.js +3 -18
  140. package/dist/retrievers/index.js.map +1 -1
  141. package/dist/runnables/base.cjs +24 -63
  142. package/dist/runnables/base.cjs.map +1 -1
  143. package/dist/runnables/base.d.cts +10 -39
  144. package/dist/runnables/base.d.cts.map +1 -1
  145. package/dist/runnables/base.d.ts +10 -39
  146. package/dist/runnables/base.d.ts.map +1 -1
  147. package/dist/runnables/base.js +24 -63
  148. package/dist/runnables/base.js.map +1 -1
  149. package/dist/runnables/graph.cjs +1 -1
  150. package/dist/runnables/graph.cjs.map +1 -1
  151. package/dist/runnables/graph.js +2 -2
  152. package/dist/runnables/graph.js.map +1 -1
  153. package/dist/runnables/graph_mermaid.cjs +1 -10
  154. package/dist/runnables/graph_mermaid.cjs.map +1 -1
  155. package/dist/runnables/graph_mermaid.js +1 -10
  156. package/dist/runnables/graph_mermaid.js.map +1 -1
  157. package/dist/runnables/history.cjs +1 -1
  158. package/dist/runnables/history.cjs.map +1 -1
  159. package/dist/runnables/history.d.cts +2 -2
  160. package/dist/runnables/history.d.cts.map +1 -1
  161. package/dist/runnables/history.d.ts +2 -2
  162. package/dist/runnables/history.d.ts.map +1 -1
  163. package/dist/runnables/history.js +1 -1
  164. package/dist/runnables/history.js.map +1 -1
  165. package/dist/stores.cjs.map +1 -1
  166. package/dist/stores.d.cts +3 -29
  167. package/dist/stores.d.cts.map +1 -1
  168. package/dist/stores.d.ts +3 -29
  169. package/dist/stores.d.ts.map +1 -1
  170. package/dist/stores.js.map +1 -1
  171. package/dist/tools/index.cjs +12 -4
  172. package/dist/tools/index.cjs.map +1 -1
  173. package/dist/tools/index.js +12 -4
  174. package/dist/tools/index.js.map +1 -1
  175. package/dist/tools/types.cjs.map +1 -1
  176. package/dist/tools/types.d.cts +4 -0
  177. package/dist/tools/types.d.cts.map +1 -1
  178. package/dist/tools/types.d.ts +4 -0
  179. package/dist/tools/types.d.ts.map +1 -1
  180. package/dist/tools/types.js.map +1 -1
  181. package/dist/tracers/base.cjs +1 -1
  182. package/dist/tracers/base.cjs.map +1 -1
  183. package/dist/tracers/base.d.cts +1 -1
  184. package/dist/tracers/base.js +2 -2
  185. package/dist/tracers/base.js.map +1 -1
  186. package/dist/tracers/log_stream.d.cts +1 -1
  187. package/dist/tracers/log_stream.d.ts +1 -1
  188. package/dist/tracers/tracer_langchain.cjs +1 -0
  189. package/dist/tracers/tracer_langchain.cjs.map +1 -1
  190. package/dist/tracers/tracer_langchain.d.cts +2 -2
  191. package/dist/tracers/tracer_langchain.js +1 -0
  192. package/dist/tracers/tracer_langchain.js.map +1 -1
  193. package/dist/utils/env.cjs +1 -9
  194. package/dist/utils/env.cjs.map +1 -1
  195. package/dist/utils/env.d.cts +2 -6
  196. package/dist/utils/env.d.cts.map +1 -1
  197. package/dist/utils/env.d.ts +2 -6
  198. package/dist/utils/env.d.ts.map +1 -1
  199. package/dist/utils/env.js +2 -9
  200. package/dist/utils/env.js.map +1 -1
  201. package/dist/utils/testing/message_history.cjs +1 -1
  202. package/dist/utils/testing/message_history.cjs.map +1 -1
  203. package/dist/utils/testing/message_history.d.cts +1 -1
  204. package/dist/utils/testing/message_history.d.cts.map +1 -1
  205. package/dist/utils/testing/message_history.d.ts +1 -1
  206. package/dist/utils/testing/message_history.d.ts.map +1 -1
  207. package/dist/utils/testing/message_history.js +1 -1
  208. package/dist/utils/testing/message_history.js.map +1 -1
  209. package/dist/utils/types/index.cjs +6 -0
  210. package/dist/utils/types/index.d.cts +2 -2
  211. package/dist/utils/types/index.d.ts +2 -2
  212. package/dist/utils/types/index.js +5 -2
  213. package/dist/utils/types/zod.cjs +23 -0
  214. package/dist/utils/types/zod.cjs.map +1 -1
  215. package/dist/utils/types/zod.d.cts +11 -1
  216. package/dist/utils/types/zod.d.cts.map +1 -1
  217. package/dist/utils/types/zod.d.ts +11 -1
  218. package/dist/utils/types/zod.d.ts.map +1 -1
  219. package/dist/utils/types/zod.js +21 -1
  220. package/dist/utils/types/zod.js.map +1 -1
  221. package/package.json +121 -154
  222. package/dist/runnables/remote.cjs +0 -399
  223. package/dist/runnables/remote.cjs.map +0 -1
  224. package/dist/runnables/remote.d.cts +0 -73
  225. package/dist/runnables/remote.d.cts.map +0 -1
  226. package/dist/runnables/remote.d.ts +0 -73
  227. package/dist/runnables/remote.d.ts.map +0 -1
  228. package/dist/runnables/remote.js +0 -393
  229. package/dist/runnables/remote.js.map +0 -1
  230. package/dist/tracers/initialize.cjs +0 -46
  231. package/dist/tracers/initialize.cjs.map +0 -1
  232. package/dist/tracers/initialize.d.cts +0 -26
  233. package/dist/tracers/initialize.d.cts.map +0 -1
  234. package/dist/tracers/initialize.d.ts +0 -26
  235. package/dist/tracers/initialize.d.ts.map +0 -1
  236. package/dist/tracers/initialize.js +0 -39
  237. package/dist/tracers/initialize.js.map +0 -1
  238. package/dist/tracers/tracer_langchain_v1.cjs +0 -168
  239. package/dist/tracers/tracer_langchain_v1.cjs.map +0 -1
  240. package/dist/tracers/tracer_langchain_v1.d.cts +0 -64
  241. package/dist/tracers/tracer_langchain_v1.d.cts.map +0 -1
  242. package/dist/tracers/tracer_langchain_v1.d.ts +0 -64
  243. package/dist/tracers/tracer_langchain_v1.d.ts.map +0 -1
  244. package/dist/tracers/tracer_langchain_v1.js +0 -162
  245. package/dist/tracers/tracer_langchain_v1.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tool.js","names":["x: unknown","fields:\n | $InferMessageContent<TStructure, \"tool\">\n | ToolMessageFields<TStructure>","tool_call_id?: string","name?: string","toolMessageFields: ToolMessageFields<TStructure>","message: unknown","fields: ToolMessageFields<TStructure>","chunk: ToolMessageChunk<TStructure>","rawToolCalls: Record<string, any>[]","toolCalls: ToolCall[]","invalidToolCalls: InvalidToolCall[]","x: BaseMessageChunk"],"sources":["../../src/messages/tool.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n type BaseMessageFields,\n mergeContent,\n _mergeDicts,\n _mergeObj,\n _mergeStatus,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface ToolMessageFields<\n TStructure extends MessageStructure = MessageStructure\n> extends BaseMessageFields<TStructure, \"tool\"> {\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n tool_call_id: string;\n status?: \"success\" | \"error\";\n}\n\n/**\n * Marker parameter for objects that tools can return directly.\n *\n * If a custom BaseTool is invoked with a ToolCall and the output of custom code is\n * not an instance of DirectToolOutput, the output will automatically be coerced to\n * a string and wrapped in a ToolMessage.\n */\nexport interface DirectToolOutput {\n readonly lc_direct_tool_output: true;\n}\n\nexport function isDirectToolOutput(x: unknown): x is DirectToolOutput {\n return (\n x != null &&\n typeof x === \"object\" &&\n \"lc_direct_tool_output\" in x &&\n x.lc_direct_tool_output === true\n );\n}\n\n/**\n * Represents a tool message in a conversation.\n */\nexport class ToolMessage<TStructure extends MessageStructure = MessageStructure>\n extends BaseMessage<TStructure, \"tool\">\n implements DirectToolOutput\n{\n static lc_name() {\n return \"ToolMessage\";\n }\n\n get lc_aliases(): Record<string, string> {\n // exclude snake case conversion to pascal case\n return { tool_call_id: \"tool_call_id\" };\n }\n\n lc_direct_tool_output = true as const;\n\n readonly type = \"tool\" as const;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n tool_call_id: string;\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(\n fields: $InferMessageContent<TStructure, \"tool\"> | ToolMessageFields,\n tool_call_id: string,\n name?: string\n );\n\n constructor(fields: ToolMessageFields<TStructure>);\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"tool\">\n | ToolMessageFields<TStructure>,\n tool_call_id?: string,\n name?: string\n ) {\n const toolMessageFields: ToolMessageFields<TStructure> =\n typeof fields === \"string\" || Array.isArray(fields)\n ? { content: fields, name, tool_call_id: tool_call_id! }\n : fields;\n super(toolMessageFields);\n this.tool_call_id = toolMessageFields.tool_call_id;\n this.artifact = toolMessageFields.artifact;\n this.status = toolMessageFields.status;\n }\n\n static isInstance(message: unknown): message is ToolMessage {\n return super.isInstance(message) && message.type === \"tool\";\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\n/**\n * Represents a chunk of a tool message, which can be concatenated\n * with other tool message chunks.\n */\nexport class ToolMessageChunk<\n TStructure extends MessageStructure = MessageStructure\n> extends BaseMessageChunk<TStructure, \"tool\"> {\n readonly type = \"tool\" as const;\n\n tool_call_id: string;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(fields: ToolMessageFields<TStructure>) {\n super(fields);\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n\n static lc_name() {\n return \"ToolMessageChunk\";\n }\n\n concat(chunk: ToolMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n artifact: _mergeObj(this.artifact, chunk.artifact),\n tool_call_id: this.tool_call_id,\n id: this.id ?? chunk.id,\n status: _mergeStatus(this.status, chunk.status),\n });\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\nexport interface ToolCall<\n TName extends string = string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TArgs extends Record<string, any> = Record<string, any>\n> {\n readonly type?: \"tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n}\n\n/**\n * A chunk of a tool call (e.g., as part of a stream).\n * When merging ToolCallChunks (e.g., via AIMessageChunk.__add__),\n * all string attributes are concatenated. Chunks are only merged if their\n * values of `index` are equal and not None.\n *\n * @example\n * ```ts\n * const leftChunks = [\n * {\n * name: \"foo\",\n * args: '{\"a\":',\n * index: 0\n * }\n * ];\n *\n * const leftAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: leftChunks\n * });\n *\n * const rightChunks = [\n * {\n * name: undefined,\n * args: '1}',\n * index: 0\n * }\n * ];\n *\n * const rightAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: rightChunks\n * });\n *\n * const result = leftAIMessageChunk.concat(rightAIMessageChunk);\n * // result.tool_call_chunks is equal to:\n * // [\n * // {\n * // name: \"foo\",\n * // args: '{\"a\":1}'\n * // index: 0\n * // }\n * // ]\n * ```\n */\nexport interface ToolCallChunk<TName extends string = string> {\n readonly type?: \"tool_call_chunk\";\n /**\n * If provided, a substring of an identifier for the tool call\n */\n id?: string;\n /**\n * If provided, a substring of the name of the tool to be called\n */\n name?: TName;\n /**\n * If provided, a JSON substring of the arguments to the tool call\n */\n args?: string;\n /**\n * If provided, the index of the tool call in a sequence\n */\n index?: number;\n}\n\nexport interface InvalidToolCall<TName extends string = string> {\n readonly type?: \"invalid_tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n}\n\nexport function defaultToolCallParser(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCalls: Record<string, any>[]\n): [ToolCall[], InvalidToolCall[]] {\n const toolCalls: ToolCall[] = [];\n const invalidToolCalls: InvalidToolCall[] = [];\n for (const toolCall of rawToolCalls) {\n if (!toolCall.function) {\n continue;\n } else {\n const functionName = toolCall.function.name;\n try {\n const functionArgs = JSON.parse(toolCall.function.arguments);\n toolCalls.push({\n name: functionName || \"\",\n args: functionArgs || {},\n id: toolCall.id,\n });\n } catch {\n invalidToolCalls.push({\n name: functionName,\n args: toolCall.function.arguments,\n id: toolCall.id,\n error: \"Malformed args.\",\n });\n }\n }\n }\n return [toolCalls, invalidToolCalls];\n}\n\n/**\n * @deprecated Use {@link ToolMessage.isInstance} instead\n */\nexport function isToolMessage(x: unknown): x is ToolMessage {\n return (\n typeof x === \"object\" &&\n x !== null &&\n \"getType\" in x &&\n typeof x.getType === \"function\" &&\n x.getType() === \"tool\"\n );\n}\n\n/**\n * @deprecated Use {@link ToolMessageChunk.isInstance} instead\n */\nexport function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk {\n return x._getType() === \"tool\";\n}\n"],"mappings":";;;;;;;;;;;;;AAuCA,SAAgB,mBAAmBA,GAAmC;AACpE,QACE,KAAK,QACL,OAAO,MAAM,YACb,2BAA2B,KAC3B,EAAE,0BAA0B;AAE/B;;;;AAKD,IAAa,cAAb,cACU,YAEV;CACE,OAAO,UAAU;AACf,SAAO;CACR;CAED,IAAI,aAAqC;AAEvC,SAAO,EAAE,cAAc,eAAgB;CACxC;CAED,wBAAwB;CAExB,AAAS,OAAO;;;;;CAMhB;CAEA;;;;;;;;CAUA;CAUA,YACEC,QAGAC,cACAC,MACA;EACA,MAAMC,oBACJ,OAAO,WAAW,YAAY,MAAM,QAAQ,OAAO,GAC/C;GAAE,SAAS;GAAQ;GAAoB;EAAe,IACtD;EACN,MAAM,kBAAkB;EACxB,KAAK,eAAe,kBAAkB;EACtC,KAAK,WAAW,kBAAkB;EAClC,KAAK,SAAS,kBAAkB;CACjC;CAED,OAAO,WAAWC,SAA0C;AAC1D,SAAO,MAAM,WAAW,QAAQ,IAAI,QAAQ,SAAS;CACtD;CAED,IAAa,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EAChB;CACF;AACF;;;;;AAMD,IAAa,mBAAb,cAEU,iBAAqC;CAC7C,AAAS,OAAO;CAEhB;;;;;CAMA;;;;;;;;CAUA;CAEA,YAAYC,QAAuC;EACjD,MAAM,OAAO;EACb,KAAK,eAAe,OAAO;EAC3B,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO;CACtB;CAED,OAAO,UAAU;AACf,SAAO;CACR;CAED,OAAOC,OAAqC;EAC1C,MAAM,MAAM,KAAK;AACjB,SAAO,IAAI,IAAI;GACb,SAAS,aAAa,KAAK,SAAS,MAAM,QAAQ;GAClD,mBAAmB,YACjB,KAAK,mBACL,MAAM,kBACP;GACD,mBAAmB,YACjB,KAAK,mBACL,MAAM,kBACP;GACD,UAAU,UAAU,KAAK,UAAU,MAAM,SAAS;GAClD,cAAc,KAAK;GACnB,IAAI,KAAK,MAAM,MAAM;GACrB,QAAQ,aAAa,KAAK,QAAQ,MAAM,OAAO;EAChD;CACF;CAED,IAAa,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EAChB;CACF;AACF;AAgHD,SAAgB,sBAEdC,cACiC;CACjC,MAAMC,YAAwB,CAAE;CAChC,MAAMC,mBAAsC,CAAE;AAC9C,MAAK,MAAM,YAAY,aACrB,KAAI,CAAC,SAAS,SACZ;MACK;EACL,MAAM,eAAe,SAAS,SAAS;AACvC,MAAI;GACF,MAAM,eAAe,KAAK,MAAM,SAAS,SAAS,UAAU;GAC5D,UAAU,KAAK;IACb,MAAM,gBAAgB;IACtB,MAAM,gBAAgB,CAAE;IACxB,IAAI,SAAS;GACd,EAAC;EACH,QAAO;GACN,iBAAiB,KAAK;IACpB,MAAM;IACN,MAAM,SAAS,SAAS;IACxB,IAAI,SAAS;IACb,OAAO;GACR,EAAC;EACH;CACF;AAEH,QAAO,CAAC,WAAW,gBAAiB;AACrC;;;;AAKD,SAAgB,cAAcV,GAA8B;AAC1D,QACE,OAAO,MAAM,YACb,MAAM,QACN,aAAa,KACb,OAAO,EAAE,YAAY,cACrB,EAAE,SAAS,KAAK;AAEnB;;;;AAKD,SAAgB,mBAAmBW,GAA4C;AAC7E,QAAO,EAAE,UAAU,KAAK;AACzB"}
1
+ {"version":3,"file":"tool.js","names":["x: unknown","fields:\n | $InferMessageContent<TStructure, \"tool\">\n | ToolMessageFields<TStructure>","tool_call_id?: string","name?: string","toolMessageFields: ToolMessageFields<TStructure>","message: unknown","fields: ToolMessageFields<TStructure>","chunk: ToolMessageChunk<TStructure>","rawToolCalls: Record<string, any>[]","toolCalls: ToolCall[]","invalidToolCalls: InvalidToolCall[]","x: BaseMessageChunk"],"sources":["../../src/messages/tool.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageChunk,\n type BaseMessageFields,\n mergeContent,\n _mergeDicts,\n _mergeObj,\n _mergeStatus,\n} from \"./base.js\";\nimport { $InferMessageContent, MessageStructure } from \"./message.js\";\nimport { Constructor } from \"./utils.js\";\n\nexport interface ToolMessageFields<\n TStructure extends MessageStructure = MessageStructure\n> extends BaseMessageFields<TStructure, \"tool\"> {\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n tool_call_id: string;\n status?: \"success\" | \"error\";\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Marker parameter for objects that tools can return directly.\n *\n * If a custom BaseTool is invoked with a ToolCall and the output of custom code is\n * not an instance of DirectToolOutput, the output will automatically be coerced to\n * a string and wrapped in a ToolMessage.\n */\nexport interface DirectToolOutput {\n readonly lc_direct_tool_output: true;\n}\n\nexport function isDirectToolOutput(x: unknown): x is DirectToolOutput {\n return (\n x != null &&\n typeof x === \"object\" &&\n \"lc_direct_tool_output\" in x &&\n x.lc_direct_tool_output === true\n );\n}\n\n/**\n * Represents a tool message in a conversation.\n */\nexport class ToolMessage<TStructure extends MessageStructure = MessageStructure>\n extends BaseMessage<TStructure, \"tool\">\n implements DirectToolOutput\n{\n static lc_name() {\n return \"ToolMessage\";\n }\n\n get lc_aliases(): Record<string, string> {\n // exclude snake case conversion to pascal case\n return { tool_call_id: \"tool_call_id\" };\n }\n\n lc_direct_tool_output = true as const;\n\n readonly type = \"tool\" as const;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n tool_call_id: string;\n\n metadata?: Record<string, unknown>;\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(\n fields: $InferMessageContent<TStructure, \"tool\"> | ToolMessageFields,\n tool_call_id: string,\n name?: string\n );\n\n constructor(fields: ToolMessageFields<TStructure>);\n\n constructor(\n fields:\n | $InferMessageContent<TStructure, \"tool\">\n | ToolMessageFields<TStructure>,\n tool_call_id?: string,\n name?: string\n ) {\n const toolMessageFields: ToolMessageFields<TStructure> =\n typeof fields === \"string\" || Array.isArray(fields)\n ? { content: fields, name, tool_call_id: tool_call_id! }\n : fields;\n super(toolMessageFields);\n this.tool_call_id = toolMessageFields.tool_call_id;\n this.artifact = toolMessageFields.artifact;\n this.status = toolMessageFields.status;\n this.metadata = toolMessageFields.metadata;\n }\n\n static isInstance(message: unknown): message is ToolMessage {\n return super.isInstance(message) && message.type === \"tool\";\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\n/**\n * Represents a chunk of a tool message, which can be concatenated\n * with other tool message chunks.\n */\nexport class ToolMessageChunk<\n TStructure extends MessageStructure = MessageStructure\n> extends BaseMessageChunk<TStructure, \"tool\"> {\n readonly type = \"tool\" as const;\n\n tool_call_id: string;\n\n /**\n * Status of the tool invocation.\n * @version 0.2.19\n */\n status?: \"success\" | \"error\";\n\n /**\n * Artifact of the Tool execution which is not meant to be sent to the model.\n *\n * Should only be specified if it is different from the message content, e.g. if only\n * a subset of the full tool output is being passed as message content but the full\n * output is needed in other parts of the code.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n artifact?: any;\n\n constructor(fields: ToolMessageFields<TStructure>) {\n super(fields);\n this.tool_call_id = fields.tool_call_id;\n this.artifact = fields.artifact;\n this.status = fields.status;\n }\n\n static lc_name() {\n return \"ToolMessageChunk\";\n }\n\n concat(chunk: ToolMessageChunk<TStructure>) {\n const Cls = this.constructor as Constructor<this>;\n return new Cls({\n content: mergeContent(this.content, chunk.content),\n additional_kwargs: _mergeDicts(\n this.additional_kwargs,\n chunk.additional_kwargs\n ),\n response_metadata: _mergeDicts(\n this.response_metadata,\n chunk.response_metadata\n ),\n artifact: _mergeObj(this.artifact, chunk.artifact),\n tool_call_id: this.tool_call_id,\n id: this.id ?? chunk.id,\n status: _mergeStatus(this.status, chunk.status),\n });\n }\n\n override get _printableFields(): Record<string, unknown> {\n return {\n ...super._printableFields,\n tool_call_id: this.tool_call_id,\n artifact: this.artifact,\n };\n }\n}\n\nexport interface ToolCall<\n TName extends string = string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TArgs extends Record<string, any> = Record<string, any>\n> {\n readonly type?: \"tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n}\n\n/**\n * A chunk of a tool call (e.g., as part of a stream).\n * When merging ToolCallChunks (e.g., via AIMessageChunk.__add__),\n * all string attributes are concatenated. Chunks are only merged if their\n * values of `index` are equal and not None.\n *\n * @example\n * ```ts\n * const leftChunks = [\n * {\n * name: \"foo\",\n * args: '{\"a\":',\n * index: 0\n * }\n * ];\n *\n * const leftAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: leftChunks\n * });\n *\n * const rightChunks = [\n * {\n * name: undefined,\n * args: '1}',\n * index: 0\n * }\n * ];\n *\n * const rightAIMessageChunk = new AIMessageChunk({\n * content: \"\",\n * tool_call_chunks: rightChunks\n * });\n *\n * const result = leftAIMessageChunk.concat(rightAIMessageChunk);\n * // result.tool_call_chunks is equal to:\n * // [\n * // {\n * // name: \"foo\",\n * // args: '{\"a\":1}'\n * // index: 0\n * // }\n * // ]\n * ```\n */\nexport interface ToolCallChunk<TName extends string = string> {\n readonly type?: \"tool_call_chunk\";\n /**\n * If provided, a substring of an identifier for the tool call\n */\n id?: string;\n /**\n * If provided, a substring of the name of the tool to be called\n */\n name?: TName;\n /**\n * If provided, a JSON substring of the arguments to the tool call\n */\n args?: string;\n /**\n * If provided, the index of the tool call in a sequence\n */\n index?: number;\n}\n\nexport interface InvalidToolCall<TName extends string = string> {\n readonly type?: \"invalid_tool_call\";\n /**\n * If provided, an identifier associated with the tool call\n */\n id?: string;\n /**\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n}\n\nexport function defaultToolCallParser(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rawToolCalls: Record<string, any>[]\n): [ToolCall[], InvalidToolCall[]] {\n const toolCalls: ToolCall[] = [];\n const invalidToolCalls: InvalidToolCall[] = [];\n for (const toolCall of rawToolCalls) {\n if (!toolCall.function) {\n continue;\n } else {\n const functionName = toolCall.function.name;\n try {\n const functionArgs = JSON.parse(toolCall.function.arguments);\n toolCalls.push({\n name: functionName || \"\",\n args: functionArgs || {},\n id: toolCall.id,\n });\n } catch {\n invalidToolCalls.push({\n name: functionName,\n args: toolCall.function.arguments,\n id: toolCall.id,\n error: \"Malformed args.\",\n });\n }\n }\n }\n return [toolCalls, invalidToolCalls];\n}\n\n/**\n * @deprecated Use {@link ToolMessage.isInstance} instead\n */\nexport function isToolMessage(x: unknown): x is ToolMessage {\n return (\n typeof x === \"object\" &&\n x !== null &&\n \"getType\" in x &&\n typeof x.getType === \"function\" &&\n x.getType() === \"tool\"\n );\n}\n\n/**\n * @deprecated Use {@link ToolMessageChunk.isInstance} instead\n */\nexport function isToolMessageChunk(x: BaseMessageChunk): x is ToolMessageChunk {\n return x._getType() === \"tool\";\n}\n"],"mappings":";;;;;;;;;;;;;AAwCA,SAAgB,mBAAmBA,GAAmC;AACpE,QACE,KAAK,QACL,OAAO,MAAM,YACb,2BAA2B,KAC3B,EAAE,0BAA0B;AAE/B;;;;AAKD,IAAa,cAAb,cACU,YAEV;CACE,OAAO,UAAU;AACf,SAAO;CACR;CAED,IAAI,aAAqC;AAEvC,SAAO,EAAE,cAAc,eAAgB;CACxC;CAED,wBAAwB;CAExB,AAAS,OAAO;;;;;CAMhB;CAEA;CAEA;;;;;;;;CAUA;CAUA,YACEC,QAGAC,cACAC,MACA;EACA,MAAMC,oBACJ,OAAO,WAAW,YAAY,MAAM,QAAQ,OAAO,GAC/C;GAAE,SAAS;GAAQ;GAAoB;EAAe,IACtD;EACN,MAAM,kBAAkB;EACxB,KAAK,eAAe,kBAAkB;EACtC,KAAK,WAAW,kBAAkB;EAClC,KAAK,SAAS,kBAAkB;EAChC,KAAK,WAAW,kBAAkB;CACnC;CAED,OAAO,WAAWC,SAA0C;AAC1D,SAAO,MAAM,WAAW,QAAQ,IAAI,QAAQ,SAAS;CACtD;CAED,IAAa,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EAChB;CACF;AACF;;;;;AAMD,IAAa,mBAAb,cAEU,iBAAqC;CAC7C,AAAS,OAAO;CAEhB;;;;;CAMA;;;;;;;;CAUA;CAEA,YAAYC,QAAuC;EACjD,MAAM,OAAO;EACb,KAAK,eAAe,OAAO;EAC3B,KAAK,WAAW,OAAO;EACvB,KAAK,SAAS,OAAO;CACtB;CAED,OAAO,UAAU;AACf,SAAO;CACR;CAED,OAAOC,OAAqC;EAC1C,MAAM,MAAM,KAAK;AACjB,SAAO,IAAI,IAAI;GACb,SAAS,aAAa,KAAK,SAAS,MAAM,QAAQ;GAClD,mBAAmB,YACjB,KAAK,mBACL,MAAM,kBACP;GACD,mBAAmB,YACjB,KAAK,mBACL,MAAM,kBACP;GACD,UAAU,UAAU,KAAK,UAAU,MAAM,SAAS;GAClD,cAAc,KAAK;GACnB,IAAI,KAAK,MAAM,MAAM;GACrB,QAAQ,aAAa,KAAK,QAAQ,MAAM,OAAO;EAChD;CACF;CAED,IAAa,mBAA4C;AACvD,SAAO;GACL,GAAG,MAAM;GACT,cAAc,KAAK;GACnB,UAAU,KAAK;EAChB;CACF;AACF;AAgHD,SAAgB,sBAEdC,cACiC;CACjC,MAAMC,YAAwB,CAAE;CAChC,MAAMC,mBAAsC,CAAE;AAC9C,MAAK,MAAM,YAAY,aACrB,KAAI,CAAC,SAAS,SACZ;MACK;EACL,MAAM,eAAe,SAAS,SAAS;AACvC,MAAI;GACF,MAAM,eAAe,KAAK,MAAM,SAAS,SAAS,UAAU;GAC5D,UAAU,KAAK;IACb,MAAM,gBAAgB;IACtB,MAAM,gBAAgB,CAAE;IACxB,IAAI,SAAS;GACd,EAAC;EACH,QAAO;GACN,iBAAiB,KAAK;IACpB,MAAM;IACN,MAAM,SAAS,SAAS;IACxB,IAAI,SAAS;IACb,OAAO;GACR,EAAC;EACH;CACF;AAEH,QAAO,CAAC,WAAW,gBAAiB;AACrC;;;;AAKD,SAAgB,cAAcV,GAA8B;AAC1D,QACE,OAAO,MAAM,YACb,MAAM,QACN,aAAa,KACb,OAAO,EAAE,YAAY,cACrB,EAAE,SAAS,KAAK;AAEnB;;;;AAKD,SAAgB,mBAAmBW,GAA4C;AAC7E,QAAO,EAAE,UAAU,KAAK;AACzB"}
@@ -13,6 +13,11 @@ var JsonOutputParser = class extends require_transform.BaseCumulativeTransformOu
13
13
  }
14
14
  lc_namespace = ["langchain_core", "output_parsers"];
15
15
  lc_serializable = true;
16
+ /** @internal */
17
+ _concatOutputChunks(first, second) {
18
+ if (this.diff) return super._concatOutputChunks(first, second);
19
+ return second;
20
+ }
16
21
  _diff(prev, next) {
17
22
  if (!next) return void 0;
18
23
  if (!prev) return [{
@@ -1 +1 @@
1
- {"version":3,"file":"json.cjs","names":["BaseCumulativeTransformOutputParser","prev: unknown | undefined","next: unknown","compare","generations: ChatGeneration[] | Generation[]","parseJsonMarkdown","text: string"],"sources":["../../src/output_parsers/json.ts"],"sourcesContent":["import { BaseCumulativeTransformOutputParser } from \"./transform.js\";\nimport { Operation, compare } from \"../utils/json_patch.js\";\nimport { ChatGeneration, Generation } from \"../outputs.js\";\nimport { parseJsonMarkdown, parsePartialJson } from \"../utils/json.js\";\n\n/**\n * Class for parsing the output of an LLM into a JSON object.\n */\nexport class JsonOutputParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputParser\";\n }\n\n lc_namespace = [\"langchain_core\", \"output_parsers\"];\n\n lc_serializable = true;\n\n protected _diff(\n prev: unknown | undefined,\n next: unknown\n ): Operation[] | undefined {\n if (!next) {\n return undefined;\n }\n if (!prev) {\n return [{ op: \"replace\", path: \"\", value: next }];\n }\n return compare(prev, next);\n }\n\n // This should actually return Partial<T>, but there's no way\n // to specify emitted chunks as instances separate from the main output type.\n async parsePartialResult(\n generations: ChatGeneration[] | Generation[]\n ): Promise<T | undefined> {\n return parseJsonMarkdown(generations[0].text);\n }\n\n async parse(text: string): Promise<T> {\n return parseJsonMarkdown(text, JSON.parse);\n }\n\n getFormatInstructions(): string {\n return \"\";\n }\n}\n\nexport { parsePartialJson, parseJsonMarkdown };\n"],"mappings":";;;;;;;;;AAQA,IAAa,mBAAb,cAGUA,sDAAuC;CAC/C,OAAO,UAAU;AACf,SAAO;CACR;CAED,eAAe,CAAC,kBAAkB,gBAAiB;CAEnD,kBAAkB;CAElB,AAAU,MACRC,MACAC,MACyB;AACzB,MAAI,CAAC,KACH,QAAO;AAET,MAAI,CAAC,KACH,QAAO,CAAC;GAAE,IAAI;GAAW,MAAM;GAAI,OAAO;EAAM,CAAC;AAEnD,SAAOC,uBAAQ,MAAM,KAAK;CAC3B;CAID,MAAM,mBACJC,aACwB;AACxB,SAAOC,+BAAkB,YAAY,GAAG,KAAK;CAC9C;CAED,MAAM,MAAMC,MAA0B;AACpC,SAAOD,+BAAkB,MAAM,KAAK,MAAM;CAC3C;CAED,wBAAgC;AAC9B,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"json.cjs","names":["BaseCumulativeTransformOutputParser","first: T","second: T","prev: unknown | undefined","next: unknown","compare","generations: ChatGeneration[] | Generation[]","parseJsonMarkdown","text: string"],"sources":["../../src/output_parsers/json.ts"],"sourcesContent":["import { BaseCumulativeTransformOutputParser } from \"./transform.js\";\nimport { Operation, compare } from \"../utils/json_patch.js\";\nimport { ChatGeneration, Generation } from \"../outputs.js\";\nimport { parseJsonMarkdown, parsePartialJson } from \"../utils/json.js\";\n\n/**\n * Class for parsing the output of an LLM into a JSON object.\n */\nexport class JsonOutputParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputParser\";\n }\n\n lc_namespace = [\"langchain_core\", \"output_parsers\"];\n\n lc_serializable = true;\n\n /** @internal */\n override _concatOutputChunks<T>(first: T, second: T): T {\n if (this.diff) {\n return super._concatOutputChunks(first, second);\n }\n return second;\n }\n\n protected _diff(\n prev: unknown | undefined,\n next: unknown\n ): Operation[] | undefined {\n if (!next) {\n return undefined;\n }\n if (!prev) {\n return [{ op: \"replace\", path: \"\", value: next }];\n }\n return compare(prev, next);\n }\n\n // This should actually return Partial<T>, but there's no way\n // to specify emitted chunks as instances separate from the main output type.\n async parsePartialResult(\n generations: ChatGeneration[] | Generation[]\n ): Promise<T | undefined> {\n return parseJsonMarkdown(generations[0].text);\n }\n\n async parse(text: string): Promise<T> {\n return parseJsonMarkdown(text, JSON.parse);\n }\n\n getFormatInstructions(): string {\n return \"\";\n }\n}\n\nexport { parsePartialJson, parseJsonMarkdown };\n"],"mappings":";;;;;;;;;AAQA,IAAa,mBAAb,cAGUA,sDAAuC;CAC/C,OAAO,UAAU;AACf,SAAO;CACR;CAED,eAAe,CAAC,kBAAkB,gBAAiB;CAEnD,kBAAkB;;CAGlB,AAAS,oBAAuBC,OAAUC,QAAc;AACtD,MAAI,KAAK,KACP,QAAO,MAAM,oBAAoB,OAAO,OAAO;AAEjD,SAAO;CACR;CAED,AAAU,MACRC,MACAC,MACyB;AACzB,MAAI,CAAC,KACH,QAAO;AAET,MAAI,CAAC,KACH,QAAO,CAAC;GAAE,IAAI;GAAW,MAAM;GAAI,OAAO;EAAM,CAAC;AAEnD,SAAOC,uBAAQ,MAAM,KAAK;CAC3B;CAID,MAAM,mBACJC,aACwB;AACxB,SAAOC,+BAAkB,YAAY,GAAG,KAAK;CAC9C;CAED,MAAM,MAAMC,MAA0B;AACpC,SAAOD,+BAAkB,MAAM,KAAK,MAAM;CAC3C;CAED,wBAAgC;AAC9B,SAAO;CACR;AACF"}
@@ -14,6 +14,8 @@ T extends Record<string, any> = Record<string, any>> extends BaseCumulativeTrans
14
14
  static lc_name(): string;
15
15
  lc_namespace: string[];
16
16
  lc_serializable: boolean;
17
+ /** @internal */
18
+ _concatOutputChunks<T>(first: T, second: T): T;
17
19
  protected _diff(prev: unknown | undefined, next: unknown): Operation[] | undefined;
18
20
  // This should actually return Partial<T>, but there's no way
19
21
  // to specify emitted chunks as instances separate from the main output type.
@@ -1 +1 @@
1
- {"version":3,"file":"json.d.cts","names":["BaseCumulativeTransformOutputParser","Operation","ChatGeneration","Generation","parseJsonMarkdown","parsePartialJson","JsonOutputParser","Record","T","Promise"],"sources":["../../src/output_parsers/json.d.ts"],"sourcesContent":["import { BaseCumulativeTransformOutputParser } from \"./transform.js\";\nimport { Operation } from \"../utils/json_patch.js\";\nimport { ChatGeneration, Generation } from \"../outputs.js\";\nimport { parseJsonMarkdown, parsePartialJson } from \"../utils/json.js\";\n/**\n * Class for parsing the output of an LLM into a JSON object.\n */\nexport declare class JsonOutputParser<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nT extends Record<string, any> = Record<string, any>> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name(): string;\n lc_namespace: string[];\n lc_serializable: boolean;\n protected _diff(prev: unknown | undefined, next: unknown): Operation[] | undefined;\n // This should actually return Partial<T>, but there's no way\n // to specify emitted chunks as instances separate from the main output type.\n parsePartialResult(generations: ChatGeneration[] | Generation[]): Promise<T | undefined>;\n parse(text: string): Promise<T>;\n getFormatInstructions(): string;\n}\nexport { parsePartialJson, parseJsonMarkdown };\n"],"mappings":";;;;;;;;;AAOA;AAAqC,cAAhBM,gBAAgB;;UAE3BC,MAAsBA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAAAA,MAAAA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,CAAAA,SAA6BP,mCAA7BO,CAAiEC,CAAjED,CAAAA,CAAAA;EAAM,OAA2DC,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAC,YAInCP,EAAAA,MAAAA,EAAAA;EAAS,eAGpCC,EAAAA,OAAAA;EAAc,UAAKC,KAAAA,CAAAA,IAAAA,EAAAA,OAAAA,GAAAA,SAAAA,EAAAA,IAAAA,EAAAA,OAAAA,CAAAA,EAHQF,SAGRE,EAAAA,GAAAA,SAAAA;EAAU;EAAc;EAAF,kBAC5CK,CAAAA,WAAAA,EADGN,cACHM,EAAAA,GADsBL,UACtBK,EAAAA,CAAAA,EADqCC,OACrCD,CAD6CA,CAC7CA,GAAAA,SAAAA,CAAAA;EAAC,KAATC,CAAAA,IAAAA,EAAAA,MAAAA,CAAAA,EAAAA,OAAAA,CAAQD,CAARC,CAAAA;EAAO,qBAR6BT,CAAAA,CAAAA,EAAAA,MAAAA;AAAmC"}
1
+ {"version":3,"file":"json.d.cts","names":["BaseCumulativeTransformOutputParser","Operation","ChatGeneration","Generation","parseJsonMarkdown","parsePartialJson","JsonOutputParser","Record","T","Promise"],"sources":["../../src/output_parsers/json.d.ts"],"sourcesContent":["import { BaseCumulativeTransformOutputParser } from \"./transform.js\";\nimport { Operation } from \"../utils/json_patch.js\";\nimport { ChatGeneration, Generation } from \"../outputs.js\";\nimport { parseJsonMarkdown, parsePartialJson } from \"../utils/json.js\";\n/**\n * Class for parsing the output of an LLM into a JSON object.\n */\nexport declare class JsonOutputParser<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nT extends Record<string, any> = Record<string, any>> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name(): string;\n lc_namespace: string[];\n lc_serializable: boolean;\n /** @internal */\n _concatOutputChunks<T>(first: T, second: T): T;\n protected _diff(prev: unknown | undefined, next: unknown): Operation[] | undefined;\n // This should actually return Partial<T>, but there's no way\n // to specify emitted chunks as instances separate from the main output type.\n parsePartialResult(generations: ChatGeneration[] | Generation[]): Promise<T | undefined>;\n parse(text: string): Promise<T>;\n getFormatInstructions(): string;\n}\nexport { parsePartialJson, parseJsonMarkdown };\n"],"mappings":";;;;;;;;;AAOA;AAAqC,cAAhBM,gBAAgB;;UAE3BC,MAAsBA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAAAA,MAAAA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,CAAAA,SAA6BP,mCAA7BO,CAAiEC,CAAjED,CAAAA,CAAAA;EAAM,OAA2DC,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAC,YAKhEA,EAAAA,MAAAA,EAAAA;EAAC,eAAUA,EAAAA,OAAAA;EAAC;EAAI,mBACaP,CAAAA,CAAAA,CAAAA,CAAAA,KAAAA,EAD7BO,CAC6BP,EAAAA,MAAAA,EADlBO,CACkBP,CAAAA,EADdO,CACcP;EAAS,UAGpCC,KAAAA,CAAAA,IAAAA,EAAAA,OAAAA,GAAAA,SAAAA,EAAAA,IAAAA,EAAAA,OAAAA,CAAAA,EAH2BD,SAG3BC,EAAAA,GAAAA,SAAAA;EAAc;EAAe;EAAc,kBAATO,CAAAA,WAAAA,EAAlCP,cAAkCO,EAAAA,GAAfN,UAAeM,EAAAA,CAAAA,EAAAA,OAAAA,CAAQD,CAARC,GAAAA,SAAAA,CAAAA;EAAO,KAC5CD,CAAAA,IAAAA,EAAAA,MAAAA,CAAAA,EAARC,OAAQD,CAAAA,CAAAA,CAAAA;EAAC,qBAATC,CAAAA,CAAAA,EAAAA,MAAAA"}
@@ -14,6 +14,8 @@ T extends Record<string, any> = Record<string, any>> extends BaseCumulativeTrans
14
14
  static lc_name(): string;
15
15
  lc_namespace: string[];
16
16
  lc_serializable: boolean;
17
+ /** @internal */
18
+ _concatOutputChunks<T>(first: T, second: T): T;
17
19
  protected _diff(prev: unknown | undefined, next: unknown): Operation[] | undefined;
18
20
  // This should actually return Partial<T>, but there's no way
19
21
  // to specify emitted chunks as instances separate from the main output type.
@@ -1 +1 @@
1
- {"version":3,"file":"json.d.ts","names":["BaseCumulativeTransformOutputParser","Operation","ChatGeneration","Generation","parseJsonMarkdown","parsePartialJson","JsonOutputParser","Record","T","Promise"],"sources":["../../src/output_parsers/json.d.ts"],"sourcesContent":["import { BaseCumulativeTransformOutputParser } from \"./transform.js\";\nimport { Operation } from \"../utils/json_patch.js\";\nimport { ChatGeneration, Generation } from \"../outputs.js\";\nimport { parseJsonMarkdown, parsePartialJson } from \"../utils/json.js\";\n/**\n * Class for parsing the output of an LLM into a JSON object.\n */\nexport declare class JsonOutputParser<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nT extends Record<string, any> = Record<string, any>> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name(): string;\n lc_namespace: string[];\n lc_serializable: boolean;\n protected _diff(prev: unknown | undefined, next: unknown): Operation[] | undefined;\n // This should actually return Partial<T>, but there's no way\n // to specify emitted chunks as instances separate from the main output type.\n parsePartialResult(generations: ChatGeneration[] | Generation[]): Promise<T | undefined>;\n parse(text: string): Promise<T>;\n getFormatInstructions(): string;\n}\nexport { parsePartialJson, parseJsonMarkdown };\n"],"mappings":";;;;;;;;;AAOA;AAAqC,cAAhBM,gBAAgB;;UAE3BC,MAAsBA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAAAA,MAAAA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,CAAAA,SAA6BP,mCAA7BO,CAAiEC,CAAjED,CAAAA,CAAAA;EAAM,OAA2DC,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAC,YAInCP,EAAAA,MAAAA,EAAAA;EAAS,eAGpCC,EAAAA,OAAAA;EAAc,UAAKC,KAAAA,CAAAA,IAAAA,EAAAA,OAAAA,GAAAA,SAAAA,EAAAA,IAAAA,EAAAA,OAAAA,CAAAA,EAHQF,SAGRE,EAAAA,GAAAA,SAAAA;EAAU;EAAc;EAAF,kBAC5CK,CAAAA,WAAAA,EADGN,cACHM,EAAAA,GADsBL,UACtBK,EAAAA,CAAAA,EADqCC,OACrCD,CAD6CA,CAC7CA,GAAAA,SAAAA,CAAAA;EAAC,KAATC,CAAAA,IAAAA,EAAAA,MAAAA,CAAAA,EAAAA,OAAAA,CAAQD,CAARC,CAAAA;EAAO,qBAR6BT,CAAAA,CAAAA,EAAAA,MAAAA;AAAmC"}
1
+ {"version":3,"file":"json.d.ts","names":["BaseCumulativeTransformOutputParser","Operation","ChatGeneration","Generation","parseJsonMarkdown","parsePartialJson","JsonOutputParser","Record","T","Promise"],"sources":["../../src/output_parsers/json.d.ts"],"sourcesContent":["import { BaseCumulativeTransformOutputParser } from \"./transform.js\";\nimport { Operation } from \"../utils/json_patch.js\";\nimport { ChatGeneration, Generation } from \"../outputs.js\";\nimport { parseJsonMarkdown, parsePartialJson } from \"../utils/json.js\";\n/**\n * Class for parsing the output of an LLM into a JSON object.\n */\nexport declare class JsonOutputParser<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nT extends Record<string, any> = Record<string, any>> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name(): string;\n lc_namespace: string[];\n lc_serializable: boolean;\n /** @internal */\n _concatOutputChunks<T>(first: T, second: T): T;\n protected _diff(prev: unknown | undefined, next: unknown): Operation[] | undefined;\n // This should actually return Partial<T>, but there's no way\n // to specify emitted chunks as instances separate from the main output type.\n parsePartialResult(generations: ChatGeneration[] | Generation[]): Promise<T | undefined>;\n parse(text: string): Promise<T>;\n getFormatInstructions(): string;\n}\nexport { parsePartialJson, parseJsonMarkdown };\n"],"mappings":";;;;;;;;;AAOA;AAAqC,cAAhBM,gBAAgB;;UAE3BC,MAAsBA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAAAA,MAAAA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,CAAAA,SAA6BP,mCAA7BO,CAAiEC,CAAjED,CAAAA,CAAAA;EAAM,OAA2DC,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAC,YAKhEA,EAAAA,MAAAA,EAAAA;EAAC,eAAUA,EAAAA,OAAAA;EAAC;EAAI,mBACaP,CAAAA,CAAAA,CAAAA,CAAAA,KAAAA,EAD7BO,CAC6BP,EAAAA,MAAAA,EADlBO,CACkBP,CAAAA,EADdO,CACcP;EAAS,UAGpCC,KAAAA,CAAAA,IAAAA,EAAAA,OAAAA,GAAAA,SAAAA,EAAAA,IAAAA,EAAAA,OAAAA,CAAAA,EAH2BD,SAG3BC,EAAAA,GAAAA,SAAAA;EAAc;EAAe;EAAc,kBAATO,CAAAA,WAAAA,EAAlCP,cAAkCO,EAAAA,GAAfN,UAAeM,EAAAA,CAAAA,EAAAA,OAAAA,CAAQD,CAARC,GAAAA,SAAAA,CAAAA;EAAO,KAC5CD,CAAAA,IAAAA,EAAAA,MAAAA,CAAAA,EAARC,OAAQD,CAAAA,CAAAA,CAAAA;EAAC,qBAATC,CAAAA,CAAAA,EAAAA,MAAAA"}
@@ -13,6 +13,11 @@ var JsonOutputParser = class extends BaseCumulativeTransformOutputParser {
13
13
  }
14
14
  lc_namespace = ["langchain_core", "output_parsers"];
15
15
  lc_serializable = true;
16
+ /** @internal */
17
+ _concatOutputChunks(first, second) {
18
+ if (this.diff) return super._concatOutputChunks(first, second);
19
+ return second;
20
+ }
16
21
  _diff(prev, next) {
17
22
  if (!next) return void 0;
18
23
  if (!prev) return [{
@@ -1 +1 @@
1
- {"version":3,"file":"json.js","names":["prev: unknown | undefined","next: unknown","generations: ChatGeneration[] | Generation[]","text: string"],"sources":["../../src/output_parsers/json.ts"],"sourcesContent":["import { BaseCumulativeTransformOutputParser } from \"./transform.js\";\nimport { Operation, compare } from \"../utils/json_patch.js\";\nimport { ChatGeneration, Generation } from \"../outputs.js\";\nimport { parseJsonMarkdown, parsePartialJson } from \"../utils/json.js\";\n\n/**\n * Class for parsing the output of an LLM into a JSON object.\n */\nexport class JsonOutputParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputParser\";\n }\n\n lc_namespace = [\"langchain_core\", \"output_parsers\"];\n\n lc_serializable = true;\n\n protected _diff(\n prev: unknown | undefined,\n next: unknown\n ): Operation[] | undefined {\n if (!next) {\n return undefined;\n }\n if (!prev) {\n return [{ op: \"replace\", path: \"\", value: next }];\n }\n return compare(prev, next);\n }\n\n // This should actually return Partial<T>, but there's no way\n // to specify emitted chunks as instances separate from the main output type.\n async parsePartialResult(\n generations: ChatGeneration[] | Generation[]\n ): Promise<T | undefined> {\n return parseJsonMarkdown(generations[0].text);\n }\n\n async parse(text: string): Promise<T> {\n return parseJsonMarkdown(text, JSON.parse);\n }\n\n getFormatInstructions(): string {\n return \"\";\n }\n}\n\nexport { parsePartialJson, parseJsonMarkdown };\n"],"mappings":";;;;;;;;;AAQA,IAAa,mBAAb,cAGU,oCAAuC;CAC/C,OAAO,UAAU;AACf,SAAO;CACR;CAED,eAAe,CAAC,kBAAkB,gBAAiB;CAEnD,kBAAkB;CAElB,AAAU,MACRA,MACAC,MACyB;AACzB,MAAI,CAAC,KACH,QAAO;AAET,MAAI,CAAC,KACH,QAAO,CAAC;GAAE,IAAI;GAAW,MAAM;GAAI,OAAO;EAAM,CAAC;AAEnD,SAAO,QAAQ,MAAM,KAAK;CAC3B;CAID,MAAM,mBACJC,aACwB;AACxB,SAAO,kBAAkB,YAAY,GAAG,KAAK;CAC9C;CAED,MAAM,MAAMC,MAA0B;AACpC,SAAO,kBAAkB,MAAM,KAAK,MAAM;CAC3C;CAED,wBAAgC;AAC9B,SAAO;CACR;AACF"}
1
+ {"version":3,"file":"json.js","names":["first: T","second: T","prev: unknown | undefined","next: unknown","generations: ChatGeneration[] | Generation[]","text: string"],"sources":["../../src/output_parsers/json.ts"],"sourcesContent":["import { BaseCumulativeTransformOutputParser } from \"./transform.js\";\nimport { Operation, compare } from \"../utils/json_patch.js\";\nimport { ChatGeneration, Generation } from \"../outputs.js\";\nimport { parseJsonMarkdown, parsePartialJson } from \"../utils/json.js\";\n\n/**\n * Class for parsing the output of an LLM into a JSON object.\n */\nexport class JsonOutputParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>\n> extends BaseCumulativeTransformOutputParser<T> {\n static lc_name() {\n return \"JsonOutputParser\";\n }\n\n lc_namespace = [\"langchain_core\", \"output_parsers\"];\n\n lc_serializable = true;\n\n /** @internal */\n override _concatOutputChunks<T>(first: T, second: T): T {\n if (this.diff) {\n return super._concatOutputChunks(first, second);\n }\n return second;\n }\n\n protected _diff(\n prev: unknown | undefined,\n next: unknown\n ): Operation[] | undefined {\n if (!next) {\n return undefined;\n }\n if (!prev) {\n return [{ op: \"replace\", path: \"\", value: next }];\n }\n return compare(prev, next);\n }\n\n // This should actually return Partial<T>, but there's no way\n // to specify emitted chunks as instances separate from the main output type.\n async parsePartialResult(\n generations: ChatGeneration[] | Generation[]\n ): Promise<T | undefined> {\n return parseJsonMarkdown(generations[0].text);\n }\n\n async parse(text: string): Promise<T> {\n return parseJsonMarkdown(text, JSON.parse);\n }\n\n getFormatInstructions(): string {\n return \"\";\n }\n}\n\nexport { parsePartialJson, parseJsonMarkdown };\n"],"mappings":";;;;;;;;;AAQA,IAAa,mBAAb,cAGU,oCAAuC;CAC/C,OAAO,UAAU;AACf,SAAO;CACR;CAED,eAAe,CAAC,kBAAkB,gBAAiB;CAEnD,kBAAkB;;CAGlB,AAAS,oBAAuBA,OAAUC,QAAc;AACtD,MAAI,KAAK,KACP,QAAO,MAAM,oBAAoB,OAAO,OAAO;AAEjD,SAAO;CACR;CAED,AAAU,MACRC,MACAC,MACyB;AACzB,MAAI,CAAC,KACH,QAAO;AAET,MAAI,CAAC,KACH,QAAO,CAAC;GAAE,IAAI;GAAW,MAAM;GAAI,OAAO;EAAM,CAAC;AAEnD,SAAO,QAAQ,MAAM,KAAK;CAC3B;CAID,MAAM,mBACJC,aACwB;AACxB,SAAO,kBAAkB,YAAY,GAAG,KAAK;CAC9C;CAED,MAAM,MAAMC,MAA0B;AACpC,SAAO,kBAAkB,MAAM,KAAK,MAAM;CAC3C;CAED,wBAAgC;AAC9B,SAAO;CACR;AACF"}
@@ -65,42 +65,6 @@ var BasePromptTemplate = class extends require_base.Runnable {
65
65
  runType: "prompt"
66
66
  });
67
67
  }
68
- /**
69
- * Return a json-like object representing this prompt template.
70
- * @deprecated
71
- */
72
- serialize() {
73
- throw new Error("Use .toJSON() instead");
74
- }
75
- /**
76
- * @deprecated
77
- * Load a prompt template from a json-like object describing it.
78
- *
79
- * @remarks
80
- * Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can
81
- * reference remote resources that we read asynchronously with a web
82
- * request.
83
- */
84
- static async deserialize(data) {
85
- switch (data._type) {
86
- case "prompt": {
87
- const { PromptTemplate } = await Promise.resolve().then(() => require("./prompt.cjs"));
88
- return PromptTemplate.deserialize(data);
89
- }
90
- case void 0: {
91
- const { PromptTemplate } = await Promise.resolve().then(() => require("./prompt.cjs"));
92
- return PromptTemplate.deserialize({
93
- ...data,
94
- _type: "prompt"
95
- });
96
- }
97
- case "few_shot": {
98
- const { FewShotPromptTemplate } = await Promise.resolve().then(() => require("./few_shot.cjs"));
99
- return FewShotPromptTemplate.deserialize(data);
100
- }
101
- default: throw new Error(`Invalid prompt type in config: ${data._type}`);
102
- }
103
- }
104
68
  };
105
69
 
106
70
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"base.cjs","names":["Runnable","input: BasePromptTemplateInput","userVariables: TypedPromptInputValues<RunInput>","partialValues: Record<string, string>","input: RunInput","options?: BaseCallbackConfig","input","data: SerializedBasePromptTemplate"],"sources":["../../src/prompts/base.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\n\nimport type {\n InputValues,\n PartialValues,\n StringWithAutocomplete,\n} from \"../utils/types/index.js\";\nimport { type BasePromptValueInterface } from \"../prompt_values.js\";\nimport { BaseOutputParser } from \"../output_parsers/index.js\";\nimport type { SerializedFields } from \"../load/map_keys.js\";\nimport { Runnable } from \"../runnables/base.js\";\nimport { BaseCallbackConfig } from \"../callbacks/manager.js\";\nimport type { SerializedBasePromptTemplate } from \"../prompts/serde.js\";\n\nexport type TypedPromptInputValues<RunInput> = InputValues<\n StringWithAutocomplete<Extract<keyof RunInput, string>>\n>;\n\nexport type Example = Record<string, string>;\n\n/**\n * Input common to all prompt templates.\n */\nexport interface BasePromptTemplateInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n InputVariables extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n> {\n /**\n * A list of variable names the prompt template expects\n */\n inputVariables: Array<Extract<keyof InputVariables, string>>;\n\n /**\n * How to parse the output of calling an LLM on this formatted prompt\n */\n outputParser?: BaseOutputParser;\n\n /** Partial variables */\n partialVariables?: PartialValues<PartialVariableName>;\n}\n\n/**\n * Base class for prompt templates. Exposes a format method that returns a\n * string prompt given a set of input values.\n */\nexport abstract class BasePromptTemplate<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n RunOutput extends BasePromptValueInterface = BasePromptValueInterface,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n >\n extends Runnable<RunInput, RunOutput>\n implements BasePromptTemplateInput\n{\n declare PromptValueReturnType: RunOutput;\n\n lc_serializable = true;\n\n lc_namespace = [\"langchain_core\", \"prompts\", this._getPromptType()];\n\n get lc_attributes(): SerializedFields | undefined {\n return {\n partialVariables: undefined, // python doesn't support this yet\n };\n }\n\n inputVariables: Array<Extract<keyof RunInput, string>>;\n\n outputParser?: BaseOutputParser;\n\n partialVariables: PartialValues<PartialVariableName>;\n\n /**\n * Metadata to be used for tracing.\n */\n metadata?: Record<string, unknown>;\n\n /** Tags to be used for tracing. */\n tags?: string[];\n\n constructor(input: BasePromptTemplateInput) {\n super(input);\n const { inputVariables } = input;\n if (inputVariables.includes(\"stop\")) {\n throw new Error(\n \"Cannot have an input variable named 'stop', as it is used internally, please rename.\"\n );\n }\n Object.assign(this, input);\n }\n\n abstract partial(\n values: PartialValues\n ): Promise<BasePromptTemplate<RunInput, RunOutput, PartialVariableName>>;\n\n /**\n * Merges partial variables and user variables.\n * @param userVariables The user variables to merge with the partial variables.\n * @returns A Promise that resolves to an object containing the merged variables.\n */\n async mergePartialAndUserVariables(\n userVariables: TypedPromptInputValues<RunInput>\n ): Promise<\n InputValues<Extract<keyof RunInput, string> | PartialVariableName>\n > {\n const partialVariables = this.partialVariables ?? {};\n const partialValues: Record<string, string> = {};\n\n for (const [key, value] of Object.entries(partialVariables)) {\n if (typeof value === \"string\") {\n partialValues[key] = value;\n } else {\n partialValues[key] = await (value as () => Promise<string>)();\n }\n }\n\n const allKwargs = {\n ...(partialValues as Record<PartialVariableName, string>),\n ...userVariables,\n };\n return allKwargs;\n }\n\n /**\n * Invokes the prompt template with the given input and options.\n * @param input The input to invoke the prompt template with.\n * @param options Optional configuration for the callback.\n * @returns A Promise that resolves to the output of the prompt template.\n */\n async invoke(\n input: RunInput,\n options?: BaseCallbackConfig\n ): Promise<RunOutput> {\n const metadata = {\n ...this.metadata,\n ...options?.metadata,\n };\n const tags = [...(this.tags ?? []), ...(options?.tags ?? [])];\n return this._callWithConfig(\n (input: RunInput) => this.formatPromptValue(input),\n input,\n { ...options, tags, metadata, runType: \"prompt\" }\n );\n }\n\n /**\n * Format the prompt given the input values.\n *\n * @param values - A dictionary of arguments to be passed to the prompt template.\n * @returns A formatted prompt string.\n *\n * @example\n * ```ts\n * prompt.format({ foo: \"bar\" });\n * ```\n */\n abstract format(values: TypedPromptInputValues<RunInput>): Promise<string>;\n\n /**\n * Format the prompt given the input values and return a formatted prompt value.\n * @param values\n * @returns A formatted PromptValue.\n */\n abstract formatPromptValue(\n values: TypedPromptInputValues<RunInput>\n ): Promise<RunOutput>;\n\n /**\n * Return the string type key uniquely identifying this class of prompt template.\n */\n abstract _getPromptType(): string;\n\n /**\n * Return a json-like object representing this prompt template.\n * @deprecated\n */\n serialize(): SerializedBasePromptTemplate {\n throw new Error(\"Use .toJSON() instead\");\n }\n\n /**\n * @deprecated\n * Load a prompt template from a json-like object describing it.\n *\n * @remarks\n * Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can\n * reference remote resources that we read asynchronously with a web\n * request.\n */\n static async deserialize(\n data: SerializedBasePromptTemplate\n ): Promise<\n BasePromptTemplate<InputValues, BasePromptValueInterface, string>\n > {\n switch (data._type) {\n case \"prompt\": {\n const { PromptTemplate } = await import(\"./prompt.js\");\n return PromptTemplate.deserialize(data);\n }\n case undefined: {\n const { PromptTemplate } = await import(\"./prompt.js\");\n return PromptTemplate.deserialize({ ...data, _type: \"prompt\" });\n }\n case \"few_shot\": {\n const { FewShotPromptTemplate } = await import(\"./few_shot.js\");\n return FewShotPromptTemplate.deserialize(data);\n }\n default:\n throw new Error(\n `Invalid prompt type in config: ${\n (data as SerializedBasePromptTemplate)._type\n }`\n );\n }\n }\n}\n"],"mappings":";;;;;;;AAgDA,IAAsB,qBAAtB,cAOUA,sBAEV;CAGE,kBAAkB;CAElB,eAAe;EAAC;EAAkB;EAAW,KAAK,gBAAgB;CAAC;CAEnE,IAAI,gBAA8C;AAChD,SAAO,EACL,kBAAkB,OACnB;CACF;CAED;CAEA;CAEA;;;;CAKA;;CAGA;CAEA,YAAYC,OAAgC;EAC1C,MAAM,MAAM;EACZ,MAAM,EAAE,gBAAgB,GAAG;AAC3B,MAAI,eAAe,SAAS,OAAO,CACjC,OAAM,IAAI,MACR;EAGJ,OAAO,OAAO,MAAM,MAAM;CAC3B;;;;;;CAWD,MAAM,6BACJC,eAGA;EACA,MAAM,mBAAmB,KAAK,oBAAoB,CAAE;EACpD,MAAMC,gBAAwC,CAAE;AAEhD,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,iBAAiB,CACzD,KAAI,OAAO,UAAU,UACnB,cAAc,OAAO;OAErB,cAAc,OAAO,MAAO,OAAiC;EAIjE,MAAM,YAAY;GAChB,GAAI;GACJ,GAAG;EACJ;AACD,SAAO;CACR;;;;;;;CAQD,MAAM,OACJC,OACAC,SACoB;EACpB,MAAM,WAAW;GACf,GAAG,KAAK;GACR,GAAG,SAAS;EACb;EACD,MAAM,OAAO,CAAC,GAAI,KAAK,QAAQ,CAAE,GAAG,GAAI,SAAS,QAAQ,CAAE,CAAE;AAC7D,SAAO,KAAK,gBACV,CAACD,YAAoB,KAAK,kBAAkBE,QAAM,EAClD,OACA;GAAE,GAAG;GAAS;GAAM;GAAU,SAAS;EAAU,EAClD;CACF;;;;;CAiCD,YAA0C;AACxC,QAAM,IAAI,MAAM;CACjB;;;;;;;;;;CAWD,aAAa,YACXC,MAGA;AACA,UAAQ,KAAK,OAAb;GACE,KAAK,UAAU;IACb,MAAM,EAAE,gBAAgB,GAAG,2CAAM;AACjC,WAAO,eAAe,YAAY,KAAK;GACxC;GACD,KAAK,QAAW;IACd,MAAM,EAAE,gBAAgB,GAAG,2CAAM;AACjC,WAAO,eAAe,YAAY;KAAE,GAAG;KAAM,OAAO;IAAU,EAAC;GAChE;GACD,KAAK,YAAY;IACf,MAAM,EAAE,uBAAuB,GAAG,2CAAM;AACxC,WAAO,sBAAsB,YAAY,KAAK;GAC/C;GACD,QACE,OAAM,IAAI,MACR,CAAC,+BAA+B,EAC7B,KAAsC,OACvC;EAEP;CACF;AACF"}
1
+ {"version":3,"file":"base.cjs","names":["Runnable","input: BasePromptTemplateInput","userVariables: TypedPromptInputValues<RunInput>","partialValues: Record<string, string>","input: RunInput","options?: BaseCallbackConfig","input"],"sources":["../../src/prompts/base.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\n\nimport type {\n InputValues,\n PartialValues,\n StringWithAutocomplete,\n} from \"../utils/types/index.js\";\nimport { type BasePromptValueInterface } from \"../prompt_values.js\";\nimport { BaseOutputParser } from \"../output_parsers/index.js\";\nimport type { SerializedFields } from \"../load/map_keys.js\";\nimport { Runnable } from \"../runnables/base.js\";\nimport { BaseCallbackConfig } from \"../callbacks/manager.js\";\n\nexport type TypedPromptInputValues<RunInput> = InputValues<\n StringWithAutocomplete<Extract<keyof RunInput, string>>\n>;\n\nexport type Example = Record<string, string>;\n\n/**\n * Input common to all prompt templates.\n */\nexport interface BasePromptTemplateInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n InputVariables extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n> {\n /**\n * A list of variable names the prompt template expects\n */\n inputVariables: Array<Extract<keyof InputVariables, string>>;\n\n /**\n * How to parse the output of calling an LLM on this formatted prompt\n */\n outputParser?: BaseOutputParser;\n\n /** Partial variables */\n partialVariables?: PartialValues<PartialVariableName>;\n}\n\n/**\n * Base class for prompt templates. Exposes a format method that returns a\n * string prompt given a set of input values.\n */\nexport abstract class BasePromptTemplate<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n RunOutput extends BasePromptValueInterface = BasePromptValueInterface,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n >\n extends Runnable<RunInput, RunOutput>\n implements BasePromptTemplateInput\n{\n declare PromptValueReturnType: RunOutput;\n\n lc_serializable = true;\n\n lc_namespace = [\"langchain_core\", \"prompts\", this._getPromptType()];\n\n get lc_attributes(): SerializedFields | undefined {\n return {\n partialVariables: undefined, // python doesn't support this yet\n };\n }\n\n inputVariables: Array<Extract<keyof RunInput, string>>;\n\n outputParser?: BaseOutputParser;\n\n partialVariables: PartialValues<PartialVariableName>;\n\n /**\n * Metadata to be used for tracing.\n */\n metadata?: Record<string, unknown>;\n\n /** Tags to be used for tracing. */\n tags?: string[];\n\n constructor(input: BasePromptTemplateInput) {\n super(input);\n const { inputVariables } = input;\n if (inputVariables.includes(\"stop\")) {\n throw new Error(\n \"Cannot have an input variable named 'stop', as it is used internally, please rename.\"\n );\n }\n Object.assign(this, input);\n }\n\n abstract partial(\n values: PartialValues\n ): Promise<BasePromptTemplate<RunInput, RunOutput, PartialVariableName>>;\n\n /**\n * Merges partial variables and user variables.\n * @param userVariables The user variables to merge with the partial variables.\n * @returns A Promise that resolves to an object containing the merged variables.\n */\n async mergePartialAndUserVariables(\n userVariables: TypedPromptInputValues<RunInput>\n ): Promise<\n InputValues<Extract<keyof RunInput, string> | PartialVariableName>\n > {\n const partialVariables = this.partialVariables ?? {};\n const partialValues: Record<string, string> = {};\n\n for (const [key, value] of Object.entries(partialVariables)) {\n if (typeof value === \"string\") {\n partialValues[key] = value;\n } else {\n partialValues[key] = await (value as () => Promise<string>)();\n }\n }\n\n const allKwargs = {\n ...(partialValues as Record<PartialVariableName, string>),\n ...userVariables,\n };\n return allKwargs;\n }\n\n /**\n * Invokes the prompt template with the given input and options.\n * @param input The input to invoke the prompt template with.\n * @param options Optional configuration for the callback.\n * @returns A Promise that resolves to the output of the prompt template.\n */\n async invoke(\n input: RunInput,\n options?: BaseCallbackConfig\n ): Promise<RunOutput> {\n const metadata = {\n ...this.metadata,\n ...options?.metadata,\n };\n const tags = [...(this.tags ?? []), ...(options?.tags ?? [])];\n return this._callWithConfig(\n (input: RunInput) => this.formatPromptValue(input),\n input,\n { ...options, tags, metadata, runType: \"prompt\" }\n );\n }\n\n /**\n * Format the prompt given the input values.\n *\n * @param values - A dictionary of arguments to be passed to the prompt template.\n * @returns A formatted prompt string.\n *\n * @example\n * ```ts\n * prompt.format({ foo: \"bar\" });\n * ```\n */\n abstract format(values: TypedPromptInputValues<RunInput>): Promise<string>;\n\n /**\n * Format the prompt given the input values and return a formatted prompt value.\n * @param values\n * @returns A formatted PromptValue.\n */\n abstract formatPromptValue(\n values: TypedPromptInputValues<RunInput>\n ): Promise<RunOutput>;\n\n /**\n * Return the string type key uniquely identifying this class of prompt template.\n */\n abstract _getPromptType(): string;\n}\n"],"mappings":";;;;;;;AA+CA,IAAsB,qBAAtB,cAOUA,sBAEV;CAGE,kBAAkB;CAElB,eAAe;EAAC;EAAkB;EAAW,KAAK,gBAAgB;CAAC;CAEnE,IAAI,gBAA8C;AAChD,SAAO,EACL,kBAAkB,OACnB;CACF;CAED;CAEA;CAEA;;;;CAKA;;CAGA;CAEA,YAAYC,OAAgC;EAC1C,MAAM,MAAM;EACZ,MAAM,EAAE,gBAAgB,GAAG;AAC3B,MAAI,eAAe,SAAS,OAAO,CACjC,OAAM,IAAI,MACR;EAGJ,OAAO,OAAO,MAAM,MAAM;CAC3B;;;;;;CAWD,MAAM,6BACJC,eAGA;EACA,MAAM,mBAAmB,KAAK,oBAAoB,CAAE;EACpD,MAAMC,gBAAwC,CAAE;AAEhD,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,iBAAiB,CACzD,KAAI,OAAO,UAAU,UACnB,cAAc,OAAO;OAErB,cAAc,OAAO,MAAO,OAAiC;EAIjE,MAAM,YAAY;GAChB,GAAI;GACJ,GAAG;EACJ;AACD,SAAO;CACR;;;;;;;CAQD,MAAM,OACJC,OACAC,SACoB;EACpB,MAAM,WAAW;GACf,GAAG,KAAK;GACR,GAAG,SAAS;EACb;EACD,MAAM,OAAO,CAAC,GAAI,KAAK,QAAQ,CAAE,GAAG,GAAI,SAAS,QAAQ,CAAE,CAAE;AAC7D,SAAO,KAAK,gBACV,CAACD,YAAoB,KAAK,kBAAkBE,QAAM,EAClD,OACA;GAAE,GAAG;GAAS;GAAM;GAAU,SAAS;EAAU,EAClD;CACF;AA4BF"}
@@ -4,7 +4,6 @@ import { BaseCallbackConfig } from "../callbacks/manager.cjs";
4
4
  import { Runnable } from "../runnables/base.cjs";
5
5
  import { BasePromptValueInterface } from "../prompt_values.cjs";
6
6
  import { BaseOutputParser } from "../output_parsers/base.cjs";
7
- import { SerializedBasePromptTemplate } from "./serde.cjs";
8
7
 
9
8
  //#region src/prompts/base.d.ts
10
9
  type TypedPromptInputValues<RunInput> = InputValues<StringWithAutocomplete<Extract<keyof RunInput, string>>>;
@@ -87,21 +86,6 @@ PartialVariableName extends string = any> extends Runnable<RunInput, RunOutput>
87
86
  * Return the string type key uniquely identifying this class of prompt template.
88
87
  */
89
88
  abstract _getPromptType(): string;
90
- /**
91
- * Return a json-like object representing this prompt template.
92
- * @deprecated
93
- */
94
- serialize(): SerializedBasePromptTemplate;
95
- /**
96
- * @deprecated
97
- * Load a prompt template from a json-like object describing it.
98
- *
99
- * @remarks
100
- * Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can
101
- * reference remote resources that we read asynchronously with a web
102
- * request.
103
- */
104
- static deserialize(data: SerializedBasePromptTemplate): Promise<BasePromptTemplate<InputValues, BasePromptValueInterface, string>>;
105
89
  }
106
90
  //#endregion
107
91
  export { BasePromptTemplate, BasePromptTemplateInput, Example, TypedPromptInputValues };
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.cts","names":["InputValues","PartialValues","StringWithAutocomplete","BasePromptValueInterface","BaseOutputParser","SerializedFields","Runnable","BaseCallbackConfig","SerializedBasePromptTemplate","TypedPromptInputValues","RunInput","Extract","Example","Record","BasePromptTemplateInput","InputVariables","Array","PartialVariableName","BasePromptTemplate","RunOutput","Promise"],"sources":["../../src/prompts/base.d.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\nimport type { InputValues, PartialValues, StringWithAutocomplete } from \"../utils/types/index.js\";\nimport { type BasePromptValueInterface } from \"../prompt_values.js\";\nimport { BaseOutputParser } from \"../output_parsers/index.js\";\nimport type { SerializedFields } from \"../load/map_keys.js\";\nimport { Runnable } from \"../runnables/base.js\";\nimport { BaseCallbackConfig } from \"../callbacks/manager.js\";\nimport type { SerializedBasePromptTemplate } from \"../prompts/serde.js\";\nexport type TypedPromptInputValues<RunInput> = InputValues<StringWithAutocomplete<Extract<keyof RunInput, string>>>;\nexport type Example = Record<string, string>;\n/**\n * Input common to all prompt templates.\n */\nexport interface BasePromptTemplateInput<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nInputVariables extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any> {\n /**\n * A list of variable names the prompt template expects\n */\n inputVariables: Array<Extract<keyof InputVariables, string>>;\n /**\n * How to parse the output of calling an LLM on this formatted prompt\n */\n outputParser?: BaseOutputParser;\n /** Partial variables */\n partialVariables?: PartialValues<PartialVariableName>;\n}\n/**\n * Base class for prompt templates. Exposes a format method that returns a\n * string prompt given a set of input values.\n */\nexport declare abstract class BasePromptTemplate<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, RunOutput extends BasePromptValueInterface = BasePromptValueInterface, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any> extends Runnable<RunInput, RunOutput> implements BasePromptTemplateInput {\n PromptValueReturnType: RunOutput;\n lc_serializable: boolean;\n lc_namespace: string[];\n get lc_attributes(): SerializedFields | undefined;\n inputVariables: Array<Extract<keyof RunInput, string>>;\n outputParser?: BaseOutputParser;\n partialVariables: PartialValues<PartialVariableName>;\n /**\n * Metadata to be used for tracing.\n */\n metadata?: Record<string, unknown>;\n /** Tags to be used for tracing. */\n tags?: string[];\n constructor(input: BasePromptTemplateInput);\n abstract partial(values: PartialValues): Promise<BasePromptTemplate<RunInput, RunOutput, PartialVariableName>>;\n /**\n * Merges partial variables and user variables.\n * @param userVariables The user variables to merge with the partial variables.\n * @returns A Promise that resolves to an object containing the merged variables.\n */\n mergePartialAndUserVariables(userVariables: TypedPromptInputValues<RunInput>): Promise<InputValues<Extract<keyof RunInput, string> | PartialVariableName>>;\n /**\n * Invokes the prompt template with the given input and options.\n * @param input The input to invoke the prompt template with.\n * @param options Optional configuration for the callback.\n * @returns A Promise that resolves to the output of the prompt template.\n */\n invoke(input: RunInput, options?: BaseCallbackConfig): Promise<RunOutput>;\n /**\n * Format the prompt given the input values.\n *\n * @param values - A dictionary of arguments to be passed to the prompt template.\n * @returns A formatted prompt string.\n *\n * @example\n * ```ts\n * prompt.format({ foo: \"bar\" });\n * ```\n */\n abstract format(values: TypedPromptInputValues<RunInput>): Promise<string>;\n /**\n * Format the prompt given the input values and return a formatted prompt value.\n * @param values\n * @returns A formatted PromptValue.\n */\n abstract formatPromptValue(values: TypedPromptInputValues<RunInput>): Promise<RunOutput>;\n /**\n * Return the string type key uniquely identifying this class of prompt template.\n */\n abstract _getPromptType(): string;\n /**\n * Return a json-like object representing this prompt template.\n * @deprecated\n */\n serialize(): SerializedBasePromptTemplate;\n /**\n * @deprecated\n * Load a prompt template from a json-like object describing it.\n *\n * @remarks\n * Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can\n * reference remote resources that we read asynchronously with a web\n * request.\n */\n static deserialize(data: SerializedBasePromptTemplate): Promise<BasePromptTemplate<InputValues, BasePromptValueInterface, string>>;\n}\n"],"mappings":";;;;;;;;;AASYS,KAAAA,sBAAsB,CAAA,QAAA,CAAA,GAAaT,WAAb,CAAyBE,sBAAzB,CAAgDS,OAAhD,CAAA,MAA8DD,QAA9D,EAAA,MAAA,CAAA,CAAA,CAAA;AAAA,KACtBE,OAAAA,GAAUC,MADY,CAAA,MAAA,EAAA,MAAA,CAAA;;;;AAAab,UAK9Bc,uBAL8Bd;AAAW;AAC1D,uBAMuBA,WANK,GAAA,GAAA;AAI5B;4BAAwC,MAAA,GAAA,GAAA,CAAA,CAAA;EAAA;;;EAQP,cAAbgB,EAAAA,KAAAA,CAAML,OAANK,CAAAA,MAAoBD,cAApBC,EAAAA,MAAAA,CAAAA,CAAAA;EAAK;;;EAMW,YAAA,CAAA,EAFjBZ,gBAEiB;EAMNc;EAAkB,gBAAA,CAAA,EANzBjB,aAMyB,CANXgB,mBAMW,CAAA;;;;;;AAKrBE,uBALGD,kBAKHC;;iBAHVnB,WAOuBU,GAAAA,GAAAA,EAAAA,kBAPcP,wBAOdO,GAPyCP,wBAOzCO;;4BAApBM,MAAAA,GAAAA,GAAAA,CAAAA,SAL8BV,QAK9BU,CALuCN,QAKvCM,EALiDG,SAKjDH,CAAAA,YALuEF,uBAKvEE,CAAAA;EAAK,qBACNZ,EALQe,SAKRf;EAAgB,eACCa,EAAAA,OAAAA;EAAmB,YAAjChB,EAAAA,MAAAA,EAAAA;EAAa,IAIpBY,aAAAA,CAAAA,CAAAA,EAPUR,gBAOVQ,GAAAA,SAAAA;EAAM,cAGEC,EATHE,KASGF,CATGH,OASHG,CAAAA,MATiBJ,QASjBI,EAAAA,MAAAA,CAAAA,CAAAA;EAAuB,YACjBb,CAAAA,EATVG,gBASUH;EAAa,gBAA8BS,EARlDT,aAQkDS,CARpCO,mBAQoCP,CAAAA;EAAQ;;;EAAT,QAA1BU,CAAAA,EAJ9BP,MAI8BO,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAAO;EAM2B,IAA/BX,CAAAA,EAAAA,MAAAA,EAAAA;EAAsB,WAA+CC,CAAAA,KAAAA,EAP9FI,uBAO8FJ;EAAQ,SAAtBC,OAAAA,CAAAA,MAAAA,EAN1EV,aAM0EU,CAAAA,EAN1DS,OAM0DT,CANlDO,kBAMkDP,CAN/BD,QAM+BC,EANrBQ,SAMqBR,EANVM,mBAMUN,CAAAA,CAAAA;EAAO;;;;;EAOtD,4BAAWQ,CAAAA,aAAAA,EAPnBV,sBAOmBU,CAPIT,QAOJS,CAAAA,CAAAA,EAPgBC,OAOhBD,CAPwBnB,WAOxBmB,CAPoCR,OAOpCQ,CAAAA,MAPkDT,QAOlDS,EAAAA,MAAAA,CAAAA,GAPsEF,mBAOtEE,CAAAA,CAAAA;EAAS;;;;;;EAkBf,MAAqBA,CAAAA,KAAAA,EAlBhET,QAkBgES,EAAAA,OAAAA,CAAAA,EAlB5CZ,kBAkB4CY,CAAAA,EAlBvBC,OAkBuBD,CAlBfA,SAkBeA,CAAAA;EAAS;;;;;;;;;AA9CuB;;0BAwCtFV,uBAAuBC,YAAYU;;;;;;qCAMxBX,uBAAuBC,YAAYU,QAAQD;;;;;;;;;eASjEX;;;;;;;;;;2BAUYA,+BAA+BY,QAAQF,mBAAmBlB,aAAaG"}
1
+ {"version":3,"file":"base.d.cts","names":["InputValues","PartialValues","StringWithAutocomplete","BasePromptValueInterface","BaseOutputParser","SerializedFields","Runnable","BaseCallbackConfig","TypedPromptInputValues","RunInput","Extract","Example","Record","BasePromptTemplateInput","InputVariables","Array","PartialVariableName","BasePromptTemplate","RunOutput","Promise"],"sources":["../../src/prompts/base.d.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\nimport type { InputValues, PartialValues, StringWithAutocomplete } from \"../utils/types/index.js\";\nimport { type BasePromptValueInterface } from \"../prompt_values.js\";\nimport { BaseOutputParser } from \"../output_parsers/index.js\";\nimport type { SerializedFields } from \"../load/map_keys.js\";\nimport { Runnable } from \"../runnables/base.js\";\nimport { BaseCallbackConfig } from \"../callbacks/manager.js\";\nexport type TypedPromptInputValues<RunInput> = InputValues<StringWithAutocomplete<Extract<keyof RunInput, string>>>;\nexport type Example = Record<string, string>;\n/**\n * Input common to all prompt templates.\n */\nexport interface BasePromptTemplateInput<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nInputVariables extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any> {\n /**\n * A list of variable names the prompt template expects\n */\n inputVariables: Array<Extract<keyof InputVariables, string>>;\n /**\n * How to parse the output of calling an LLM on this formatted prompt\n */\n outputParser?: BaseOutputParser;\n /** Partial variables */\n partialVariables?: PartialValues<PartialVariableName>;\n}\n/**\n * Base class for prompt templates. Exposes a format method that returns a\n * string prompt given a set of input values.\n */\nexport declare abstract class BasePromptTemplate<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, RunOutput extends BasePromptValueInterface = BasePromptValueInterface, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any> extends Runnable<RunInput, RunOutput> implements BasePromptTemplateInput {\n PromptValueReturnType: RunOutput;\n lc_serializable: boolean;\n lc_namespace: string[];\n get lc_attributes(): SerializedFields | undefined;\n inputVariables: Array<Extract<keyof RunInput, string>>;\n outputParser?: BaseOutputParser;\n partialVariables: PartialValues<PartialVariableName>;\n /**\n * Metadata to be used for tracing.\n */\n metadata?: Record<string, unknown>;\n /** Tags to be used for tracing. */\n tags?: string[];\n constructor(input: BasePromptTemplateInput);\n abstract partial(values: PartialValues): Promise<BasePromptTemplate<RunInput, RunOutput, PartialVariableName>>;\n /**\n * Merges partial variables and user variables.\n * @param userVariables The user variables to merge with the partial variables.\n * @returns A Promise that resolves to an object containing the merged variables.\n */\n mergePartialAndUserVariables(userVariables: TypedPromptInputValues<RunInput>): Promise<InputValues<Extract<keyof RunInput, string> | PartialVariableName>>;\n /**\n * Invokes the prompt template with the given input and options.\n * @param input The input to invoke the prompt template with.\n * @param options Optional configuration for the callback.\n * @returns A Promise that resolves to the output of the prompt template.\n */\n invoke(input: RunInput, options?: BaseCallbackConfig): Promise<RunOutput>;\n /**\n * Format the prompt given the input values.\n *\n * @param values - A dictionary of arguments to be passed to the prompt template.\n * @returns A formatted prompt string.\n *\n * @example\n * ```ts\n * prompt.format({ foo: \"bar\" });\n * ```\n */\n abstract format(values: TypedPromptInputValues<RunInput>): Promise<string>;\n /**\n * Format the prompt given the input values and return a formatted prompt value.\n * @param values\n * @returns A formatted PromptValue.\n */\n abstract formatPromptValue(values: TypedPromptInputValues<RunInput>): Promise<RunOutput>;\n /**\n * Return the string type key uniquely identifying this class of prompt template.\n */\n abstract _getPromptType(): string;\n}\n"],"mappings":";;;;;;;;AAQYQ,KAAAA,sBAAsB,CAAA,QAAA,CAAA,GAAaR,WAAb,CAAyBE,sBAAzB,CAAgDQ,OAAhD,CAAA,MAA8DD,QAA9D,EAAA,MAAA,CAAA,CAAA,CAAA;AAAA,KACtBE,OAAAA,GAAUC,MADY,CAAA,MAAA,EAAA,MAAA,CAAA;;;;AAAaZ,UAK9Ba,uBAL8Bb;AAAW;AAC1D,uBAMuBA,WANK,GAAA,GAAA;AAI5B;4BAAwC,MAAA,GAAA,GAAA,CAAA,CAAA;EAAA;;;EAQP,cAAbe,EAAAA,KAAAA,CAAML,OAANK,CAAAA,MAAoBD,cAApBC,EAAAA,MAAAA,CAAAA,CAAAA;EAAK;;;EAMW,YAAA,CAAA,EAFjBX,gBAEiB;EAMNa;EAAkB,gBAAA,CAAA,EANzBhB,aAMyB,CANXe,mBAMW,CAAA;;;;;;AAKrBE,uBALGD,kBAKHC;;iBAHVlB,WAOuBS,GAAAA,GAAAA,EAAAA,kBAPcN,wBAOdM,GAPyCN,wBAOzCM;;4BAApBM,MAAAA,GAAAA,GAAAA,CAAAA,SAL8BT,QAK9BS,CALuCN,QAKvCM,EALiDG,SAKjDH,CAAAA,YALuEF,uBAKvEE,CAAAA;EAAK,qBACNX,EALQc,SAKRd;EAAgB,eACCY,EAAAA,OAAAA;EAAmB,YAAjCf,EAAAA,MAAAA,EAAAA;EAAa,IAIpBW,aAAAA,CAAAA,CAAAA,EAPUP,gBAOVO,GAAAA,SAAAA;EAAM,cAGEC,EATHE,KASGF,CATGH,OASHG,CAAAA,MATiBJ,QASjBI,EAAAA,MAAAA,CAAAA,CAAAA;EAAuB,YACjBZ,CAAAA,EATVG,gBASUH;EAAa,gBAA8BQ,EARlDR,aAQkDQ,CARpCO,mBAQoCP,CAAAA;EAAQ;;;EAAT,QAA1BU,CAAAA,EAJ9BP,MAI8BO,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAAO;EAM2B,IAA/BX,CAAAA,EAAAA,MAAAA,EAAAA;EAAsB,WAA+CC,CAAAA,KAAAA,EAP9FI,uBAO8FJ;EAAQ,SAAtBC,OAAAA,CAAAA,MAAAA,EAN1ET,aAM0ES,CAAAA,EAN1DS,OAM0DT,CANlDO,kBAMkDP,CAN/BD,QAM+BC,EANrBQ,SAMqBR,EANVM,mBAMUN,CAAAA,CAAAA;EAAO;;;;;EAOtD,4BAAWQ,CAAAA,aAAAA,EAPnBV,sBAOmBU,CAPIT,QAOJS,CAAAA,CAAAA,EAPgBC,OAOhBD,CAPwBlB,WAOxBkB,CAPoCR,OAOpCQ,CAAAA,MAPkDT,QAOlDS,EAAAA,MAAAA,CAAAA,GAPsEF,mBAOtEE,CAAAA,CAAAA;EAAS;;;;;;EAkBf,MAAqBA,CAAAA,KAAAA,EAlBhET,QAkBgES,EAAAA,OAAAA,CAAAA,EAlB5CX,kBAkB4CW,CAAAA,EAlBvBC,OAkBuBD,CAlBfA,SAkBeA,CAAAA;EAAS;;;AA9CuB;;;;;;;;0BAwCtFV,uBAAuBC,YAAYU;;;;;;qCAMxBX,uBAAuBC,YAAYU,QAAQD"}
@@ -4,7 +4,6 @@ import { BaseCallbackConfig } from "../callbacks/manager.js";
4
4
  import { Runnable } from "../runnables/base.js";
5
5
  import { BasePromptValueInterface } from "../prompt_values.js";
6
6
  import { BaseOutputParser } from "../output_parsers/base.js";
7
- import { SerializedBasePromptTemplate } from "./serde.js";
8
7
 
9
8
  //#region src/prompts/base.d.ts
10
9
  type TypedPromptInputValues<RunInput> = InputValues<StringWithAutocomplete<Extract<keyof RunInput, string>>>;
@@ -87,21 +86,6 @@ PartialVariableName extends string = any> extends Runnable<RunInput, RunOutput>
87
86
  * Return the string type key uniquely identifying this class of prompt template.
88
87
  */
89
88
  abstract _getPromptType(): string;
90
- /**
91
- * Return a json-like object representing this prompt template.
92
- * @deprecated
93
- */
94
- serialize(): SerializedBasePromptTemplate;
95
- /**
96
- * @deprecated
97
- * Load a prompt template from a json-like object describing it.
98
- *
99
- * @remarks
100
- * Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can
101
- * reference remote resources that we read asynchronously with a web
102
- * request.
103
- */
104
- static deserialize(data: SerializedBasePromptTemplate): Promise<BasePromptTemplate<InputValues, BasePromptValueInterface, string>>;
105
89
  }
106
90
  //#endregion
107
91
  export { BasePromptTemplate, BasePromptTemplateInput, Example, TypedPromptInputValues };
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","names":["InputValues","PartialValues","StringWithAutocomplete","BasePromptValueInterface","BaseOutputParser","SerializedFields","Runnable","BaseCallbackConfig","SerializedBasePromptTemplate","TypedPromptInputValues","RunInput","Extract","Example","Record","BasePromptTemplateInput","InputVariables","Array","PartialVariableName","BasePromptTemplate","RunOutput","Promise"],"sources":["../../src/prompts/base.d.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\nimport type { InputValues, PartialValues, StringWithAutocomplete } from \"../utils/types/index.js\";\nimport { type BasePromptValueInterface } from \"../prompt_values.js\";\nimport { BaseOutputParser } from \"../output_parsers/index.js\";\nimport type { SerializedFields } from \"../load/map_keys.js\";\nimport { Runnable } from \"../runnables/base.js\";\nimport { BaseCallbackConfig } from \"../callbacks/manager.js\";\nimport type { SerializedBasePromptTemplate } from \"../prompts/serde.js\";\nexport type TypedPromptInputValues<RunInput> = InputValues<StringWithAutocomplete<Extract<keyof RunInput, string>>>;\nexport type Example = Record<string, string>;\n/**\n * Input common to all prompt templates.\n */\nexport interface BasePromptTemplateInput<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nInputVariables extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any> {\n /**\n * A list of variable names the prompt template expects\n */\n inputVariables: Array<Extract<keyof InputVariables, string>>;\n /**\n * How to parse the output of calling an LLM on this formatted prompt\n */\n outputParser?: BaseOutputParser;\n /** Partial variables */\n partialVariables?: PartialValues<PartialVariableName>;\n}\n/**\n * Base class for prompt templates. Exposes a format method that returns a\n * string prompt given a set of input values.\n */\nexport declare abstract class BasePromptTemplate<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, RunOutput extends BasePromptValueInterface = BasePromptValueInterface, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any> extends Runnable<RunInput, RunOutput> implements BasePromptTemplateInput {\n PromptValueReturnType: RunOutput;\n lc_serializable: boolean;\n lc_namespace: string[];\n get lc_attributes(): SerializedFields | undefined;\n inputVariables: Array<Extract<keyof RunInput, string>>;\n outputParser?: BaseOutputParser;\n partialVariables: PartialValues<PartialVariableName>;\n /**\n * Metadata to be used for tracing.\n */\n metadata?: Record<string, unknown>;\n /** Tags to be used for tracing. */\n tags?: string[];\n constructor(input: BasePromptTemplateInput);\n abstract partial(values: PartialValues): Promise<BasePromptTemplate<RunInput, RunOutput, PartialVariableName>>;\n /**\n * Merges partial variables and user variables.\n * @param userVariables The user variables to merge with the partial variables.\n * @returns A Promise that resolves to an object containing the merged variables.\n */\n mergePartialAndUserVariables(userVariables: TypedPromptInputValues<RunInput>): Promise<InputValues<Extract<keyof RunInput, string> | PartialVariableName>>;\n /**\n * Invokes the prompt template with the given input and options.\n * @param input The input to invoke the prompt template with.\n * @param options Optional configuration for the callback.\n * @returns A Promise that resolves to the output of the prompt template.\n */\n invoke(input: RunInput, options?: BaseCallbackConfig): Promise<RunOutput>;\n /**\n * Format the prompt given the input values.\n *\n * @param values - A dictionary of arguments to be passed to the prompt template.\n * @returns A formatted prompt string.\n *\n * @example\n * ```ts\n * prompt.format({ foo: \"bar\" });\n * ```\n */\n abstract format(values: TypedPromptInputValues<RunInput>): Promise<string>;\n /**\n * Format the prompt given the input values and return a formatted prompt value.\n * @param values\n * @returns A formatted PromptValue.\n */\n abstract formatPromptValue(values: TypedPromptInputValues<RunInput>): Promise<RunOutput>;\n /**\n * Return the string type key uniquely identifying this class of prompt template.\n */\n abstract _getPromptType(): string;\n /**\n * Return a json-like object representing this prompt template.\n * @deprecated\n */\n serialize(): SerializedBasePromptTemplate;\n /**\n * @deprecated\n * Load a prompt template from a json-like object describing it.\n *\n * @remarks\n * Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can\n * reference remote resources that we read asynchronously with a web\n * request.\n */\n static deserialize(data: SerializedBasePromptTemplate): Promise<BasePromptTemplate<InputValues, BasePromptValueInterface, string>>;\n}\n"],"mappings":";;;;;;;;;AASYS,KAAAA,sBAAsB,CAAA,QAAA,CAAA,GAAaT,WAAb,CAAyBE,sBAAzB,CAAgDS,OAAhD,CAAA,MAA8DD,QAA9D,EAAA,MAAA,CAAA,CAAA,CAAA;AAAA,KACtBE,OAAAA,GAAUC,MADY,CAAA,MAAA,EAAA,MAAA,CAAA;;;;AAAab,UAK9Bc,uBAL8Bd;AAAW;AAC1D,uBAMuBA,WANK,GAAA,GAAA;AAI5B;4BAAwC,MAAA,GAAA,GAAA,CAAA,CAAA;EAAA;;;EAQP,cAAbgB,EAAAA,KAAAA,CAAML,OAANK,CAAAA,MAAoBD,cAApBC,EAAAA,MAAAA,CAAAA,CAAAA;EAAK;;;EAMW,YAAA,CAAA,EAFjBZ,gBAEiB;EAMNc;EAAkB,gBAAA,CAAA,EANzBjB,aAMyB,CANXgB,mBAMW,CAAA;;;;;;AAKrBE,uBALGD,kBAKHC;;iBAHVnB,WAOuBU,GAAAA,GAAAA,EAAAA,kBAPcP,wBAOdO,GAPyCP,wBAOzCO;;4BAApBM,MAAAA,GAAAA,GAAAA,CAAAA,SAL8BV,QAK9BU,CALuCN,QAKvCM,EALiDG,SAKjDH,CAAAA,YALuEF,uBAKvEE,CAAAA;EAAK,qBACNZ,EALQe,SAKRf;EAAgB,eACCa,EAAAA,OAAAA;EAAmB,YAAjChB,EAAAA,MAAAA,EAAAA;EAAa,IAIpBY,aAAAA,CAAAA,CAAAA,EAPUR,gBAOVQ,GAAAA,SAAAA;EAAM,cAGEC,EATHE,KASGF,CATGH,OASHG,CAAAA,MATiBJ,QASjBI,EAAAA,MAAAA,CAAAA,CAAAA;EAAuB,YACjBb,CAAAA,EATVG,gBASUH;EAAa,gBAA8BS,EARlDT,aAQkDS,CARpCO,mBAQoCP,CAAAA;EAAQ;;;EAAT,QAA1BU,CAAAA,EAJ9BP,MAI8BO,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAAO;EAM2B,IAA/BX,CAAAA,EAAAA,MAAAA,EAAAA;EAAsB,WAA+CC,CAAAA,KAAAA,EAP9FI,uBAO8FJ;EAAQ,SAAtBC,OAAAA,CAAAA,MAAAA,EAN1EV,aAM0EU,CAAAA,EAN1DS,OAM0DT,CANlDO,kBAMkDP,CAN/BD,QAM+BC,EANrBQ,SAMqBR,EANVM,mBAMUN,CAAAA,CAAAA;EAAO;;;;;EAOtD,4BAAWQ,CAAAA,aAAAA,EAPnBV,sBAOmBU,CAPIT,QAOJS,CAAAA,CAAAA,EAPgBC,OAOhBD,CAPwBnB,WAOxBmB,CAPoCR,OAOpCQ,CAAAA,MAPkDT,QAOlDS,EAAAA,MAAAA,CAAAA,GAPsEF,mBAOtEE,CAAAA,CAAAA;EAAS;;;;;;EAkBf,MAAqBA,CAAAA,KAAAA,EAlBhET,QAkBgES,EAAAA,OAAAA,CAAAA,EAlB5CZ,kBAkB4CY,CAAAA,EAlBvBC,OAkBuBD,CAlBfA,SAkBeA,CAAAA;EAAS;;;;;;;;;AA9CuB;;0BAwCtFV,uBAAuBC,YAAYU;;;;;;qCAMxBX,uBAAuBC,YAAYU,QAAQD;;;;;;;;;eASjEX;;;;;;;;;;2BAUYA,+BAA+BY,QAAQF,mBAAmBlB,aAAaG"}
1
+ {"version":3,"file":"base.d.ts","names":["InputValues","PartialValues","StringWithAutocomplete","BasePromptValueInterface","BaseOutputParser","SerializedFields","Runnable","BaseCallbackConfig","TypedPromptInputValues","RunInput","Extract","Example","Record","BasePromptTemplateInput","InputVariables","Array","PartialVariableName","BasePromptTemplate","RunOutput","Promise"],"sources":["../../src/prompts/base.d.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\nimport type { InputValues, PartialValues, StringWithAutocomplete } from \"../utils/types/index.js\";\nimport { type BasePromptValueInterface } from \"../prompt_values.js\";\nimport { BaseOutputParser } from \"../output_parsers/index.js\";\nimport type { SerializedFields } from \"../load/map_keys.js\";\nimport { Runnable } from \"../runnables/base.js\";\nimport { BaseCallbackConfig } from \"../callbacks/manager.js\";\nexport type TypedPromptInputValues<RunInput> = InputValues<StringWithAutocomplete<Extract<keyof RunInput, string>>>;\nexport type Example = Record<string, string>;\n/**\n * Input common to all prompt templates.\n */\nexport interface BasePromptTemplateInput<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nInputVariables extends InputValues = any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any> {\n /**\n * A list of variable names the prompt template expects\n */\n inputVariables: Array<Extract<keyof InputVariables, string>>;\n /**\n * How to parse the output of calling an LLM on this formatted prompt\n */\n outputParser?: BaseOutputParser;\n /** Partial variables */\n partialVariables?: PartialValues<PartialVariableName>;\n}\n/**\n * Base class for prompt templates. Exposes a format method that returns a\n * string prompt given a set of input values.\n */\nexport declare abstract class BasePromptTemplate<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunInput extends InputValues = any, RunOutput extends BasePromptValueInterface = BasePromptValueInterface, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nPartialVariableName extends string = any> extends Runnable<RunInput, RunOutput> implements BasePromptTemplateInput {\n PromptValueReturnType: RunOutput;\n lc_serializable: boolean;\n lc_namespace: string[];\n get lc_attributes(): SerializedFields | undefined;\n inputVariables: Array<Extract<keyof RunInput, string>>;\n outputParser?: BaseOutputParser;\n partialVariables: PartialValues<PartialVariableName>;\n /**\n * Metadata to be used for tracing.\n */\n metadata?: Record<string, unknown>;\n /** Tags to be used for tracing. */\n tags?: string[];\n constructor(input: BasePromptTemplateInput);\n abstract partial(values: PartialValues): Promise<BasePromptTemplate<RunInput, RunOutput, PartialVariableName>>;\n /**\n * Merges partial variables and user variables.\n * @param userVariables The user variables to merge with the partial variables.\n * @returns A Promise that resolves to an object containing the merged variables.\n */\n mergePartialAndUserVariables(userVariables: TypedPromptInputValues<RunInput>): Promise<InputValues<Extract<keyof RunInput, string> | PartialVariableName>>;\n /**\n * Invokes the prompt template with the given input and options.\n * @param input The input to invoke the prompt template with.\n * @param options Optional configuration for the callback.\n * @returns A Promise that resolves to the output of the prompt template.\n */\n invoke(input: RunInput, options?: BaseCallbackConfig): Promise<RunOutput>;\n /**\n * Format the prompt given the input values.\n *\n * @param values - A dictionary of arguments to be passed to the prompt template.\n * @returns A formatted prompt string.\n *\n * @example\n * ```ts\n * prompt.format({ foo: \"bar\" });\n * ```\n */\n abstract format(values: TypedPromptInputValues<RunInput>): Promise<string>;\n /**\n * Format the prompt given the input values and return a formatted prompt value.\n * @param values\n * @returns A formatted PromptValue.\n */\n abstract formatPromptValue(values: TypedPromptInputValues<RunInput>): Promise<RunOutput>;\n /**\n * Return the string type key uniquely identifying this class of prompt template.\n */\n abstract _getPromptType(): string;\n}\n"],"mappings":";;;;;;;;AAQYQ,KAAAA,sBAAsB,CAAA,QAAA,CAAA,GAAaR,WAAb,CAAyBE,sBAAzB,CAAgDQ,OAAhD,CAAA,MAA8DD,QAA9D,EAAA,MAAA,CAAA,CAAA,CAAA;AAAA,KACtBE,OAAAA,GAAUC,MADY,CAAA,MAAA,EAAA,MAAA,CAAA;;;;AAAaZ,UAK9Ba,uBAL8Bb;AAAW;AAC1D,uBAMuBA,WANK,GAAA,GAAA;AAI5B;4BAAwC,MAAA,GAAA,GAAA,CAAA,CAAA;EAAA;;;EAQP,cAAbe,EAAAA,KAAAA,CAAML,OAANK,CAAAA,MAAoBD,cAApBC,EAAAA,MAAAA,CAAAA,CAAAA;EAAK;;;EAMW,YAAA,CAAA,EAFjBX,gBAEiB;EAMNa;EAAkB,gBAAA,CAAA,EANzBhB,aAMyB,CANXe,mBAMW,CAAA;;;;;;AAKrBE,uBALGD,kBAKHC;;iBAHVlB,WAOuBS,GAAAA,GAAAA,EAAAA,kBAPcN,wBAOdM,GAPyCN,wBAOzCM;;4BAApBM,MAAAA,GAAAA,GAAAA,CAAAA,SAL8BT,QAK9BS,CALuCN,QAKvCM,EALiDG,SAKjDH,CAAAA,YALuEF,uBAKvEE,CAAAA;EAAK,qBACNX,EALQc,SAKRd;EAAgB,eACCY,EAAAA,OAAAA;EAAmB,YAAjCf,EAAAA,MAAAA,EAAAA;EAAa,IAIpBW,aAAAA,CAAAA,CAAAA,EAPUP,gBAOVO,GAAAA,SAAAA;EAAM,cAGEC,EATHE,KASGF,CATGH,OASHG,CAAAA,MATiBJ,QASjBI,EAAAA,MAAAA,CAAAA,CAAAA;EAAuB,YACjBZ,CAAAA,EATVG,gBASUH;EAAa,gBAA8BQ,EARlDR,aAQkDQ,CARpCO,mBAQoCP,CAAAA;EAAQ;;;EAAT,QAA1BU,CAAAA,EAJ9BP,MAI8BO,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAAO;EAM2B,IAA/BX,CAAAA,EAAAA,MAAAA,EAAAA;EAAsB,WAA+CC,CAAAA,KAAAA,EAP9FI,uBAO8FJ;EAAQ,SAAtBC,OAAAA,CAAAA,MAAAA,EAN1ET,aAM0ES,CAAAA,EAN1DS,OAM0DT,CANlDO,kBAMkDP,CAN/BD,QAM+BC,EANrBQ,SAMqBR,EANVM,mBAMUN,CAAAA,CAAAA;EAAO;;;;;EAOtD,4BAAWQ,CAAAA,aAAAA,EAPnBV,sBAOmBU,CAPIT,QAOJS,CAAAA,CAAAA,EAPgBC,OAOhBD,CAPwBlB,WAOxBkB,CAPoCR,OAOpCQ,CAAAA,MAPkDT,QAOlDS,EAAAA,MAAAA,CAAAA,GAPsEF,mBAOtEE,CAAAA,CAAAA;EAAS;;;;;;EAkBf,MAAqBA,CAAAA,KAAAA,EAlBhET,QAkBgES,EAAAA,OAAAA,CAAAA,EAlB5CX,kBAkB4CW,CAAAA,EAlBvBC,OAkBuBD,CAlBfA,SAkBeA,CAAAA;EAAS;;;AA9CuB;;;;;;;;0BAwCtFV,uBAAuBC,YAAYU;;;;;;qCAMxBX,uBAAuBC,YAAYU,QAAQD"}
@@ -65,42 +65,6 @@ var BasePromptTemplate = class extends Runnable {
65
65
  runType: "prompt"
66
66
  });
67
67
  }
68
- /**
69
- * Return a json-like object representing this prompt template.
70
- * @deprecated
71
- */
72
- serialize() {
73
- throw new Error("Use .toJSON() instead");
74
- }
75
- /**
76
- * @deprecated
77
- * Load a prompt template from a json-like object describing it.
78
- *
79
- * @remarks
80
- * Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can
81
- * reference remote resources that we read asynchronously with a web
82
- * request.
83
- */
84
- static async deserialize(data) {
85
- switch (data._type) {
86
- case "prompt": {
87
- const { PromptTemplate } = await import("./prompt.js");
88
- return PromptTemplate.deserialize(data);
89
- }
90
- case void 0: {
91
- const { PromptTemplate } = await import("./prompt.js");
92
- return PromptTemplate.deserialize({
93
- ...data,
94
- _type: "prompt"
95
- });
96
- }
97
- case "few_shot": {
98
- const { FewShotPromptTemplate } = await import("./few_shot.js");
99
- return FewShotPromptTemplate.deserialize(data);
100
- }
101
- default: throw new Error(`Invalid prompt type in config: ${data._type}`);
102
- }
103
- }
104
68
  };
105
69
 
106
70
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","names":["input: BasePromptTemplateInput","userVariables: TypedPromptInputValues<RunInput>","partialValues: Record<string, string>","input: RunInput","options?: BaseCallbackConfig","input","data: SerializedBasePromptTemplate"],"sources":["../../src/prompts/base.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\n\nimport type {\n InputValues,\n PartialValues,\n StringWithAutocomplete,\n} from \"../utils/types/index.js\";\nimport { type BasePromptValueInterface } from \"../prompt_values.js\";\nimport { BaseOutputParser } from \"../output_parsers/index.js\";\nimport type { SerializedFields } from \"../load/map_keys.js\";\nimport { Runnable } from \"../runnables/base.js\";\nimport { BaseCallbackConfig } from \"../callbacks/manager.js\";\nimport type { SerializedBasePromptTemplate } from \"../prompts/serde.js\";\n\nexport type TypedPromptInputValues<RunInput> = InputValues<\n StringWithAutocomplete<Extract<keyof RunInput, string>>\n>;\n\nexport type Example = Record<string, string>;\n\n/**\n * Input common to all prompt templates.\n */\nexport interface BasePromptTemplateInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n InputVariables extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n> {\n /**\n * A list of variable names the prompt template expects\n */\n inputVariables: Array<Extract<keyof InputVariables, string>>;\n\n /**\n * How to parse the output of calling an LLM on this formatted prompt\n */\n outputParser?: BaseOutputParser;\n\n /** Partial variables */\n partialVariables?: PartialValues<PartialVariableName>;\n}\n\n/**\n * Base class for prompt templates. Exposes a format method that returns a\n * string prompt given a set of input values.\n */\nexport abstract class BasePromptTemplate<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n RunOutput extends BasePromptValueInterface = BasePromptValueInterface,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n >\n extends Runnable<RunInput, RunOutput>\n implements BasePromptTemplateInput\n{\n declare PromptValueReturnType: RunOutput;\n\n lc_serializable = true;\n\n lc_namespace = [\"langchain_core\", \"prompts\", this._getPromptType()];\n\n get lc_attributes(): SerializedFields | undefined {\n return {\n partialVariables: undefined, // python doesn't support this yet\n };\n }\n\n inputVariables: Array<Extract<keyof RunInput, string>>;\n\n outputParser?: BaseOutputParser;\n\n partialVariables: PartialValues<PartialVariableName>;\n\n /**\n * Metadata to be used for tracing.\n */\n metadata?: Record<string, unknown>;\n\n /** Tags to be used for tracing. */\n tags?: string[];\n\n constructor(input: BasePromptTemplateInput) {\n super(input);\n const { inputVariables } = input;\n if (inputVariables.includes(\"stop\")) {\n throw new Error(\n \"Cannot have an input variable named 'stop', as it is used internally, please rename.\"\n );\n }\n Object.assign(this, input);\n }\n\n abstract partial(\n values: PartialValues\n ): Promise<BasePromptTemplate<RunInput, RunOutput, PartialVariableName>>;\n\n /**\n * Merges partial variables and user variables.\n * @param userVariables The user variables to merge with the partial variables.\n * @returns A Promise that resolves to an object containing the merged variables.\n */\n async mergePartialAndUserVariables(\n userVariables: TypedPromptInputValues<RunInput>\n ): Promise<\n InputValues<Extract<keyof RunInput, string> | PartialVariableName>\n > {\n const partialVariables = this.partialVariables ?? {};\n const partialValues: Record<string, string> = {};\n\n for (const [key, value] of Object.entries(partialVariables)) {\n if (typeof value === \"string\") {\n partialValues[key] = value;\n } else {\n partialValues[key] = await (value as () => Promise<string>)();\n }\n }\n\n const allKwargs = {\n ...(partialValues as Record<PartialVariableName, string>),\n ...userVariables,\n };\n return allKwargs;\n }\n\n /**\n * Invokes the prompt template with the given input and options.\n * @param input The input to invoke the prompt template with.\n * @param options Optional configuration for the callback.\n * @returns A Promise that resolves to the output of the prompt template.\n */\n async invoke(\n input: RunInput,\n options?: BaseCallbackConfig\n ): Promise<RunOutput> {\n const metadata = {\n ...this.metadata,\n ...options?.metadata,\n };\n const tags = [...(this.tags ?? []), ...(options?.tags ?? [])];\n return this._callWithConfig(\n (input: RunInput) => this.formatPromptValue(input),\n input,\n { ...options, tags, metadata, runType: \"prompt\" }\n );\n }\n\n /**\n * Format the prompt given the input values.\n *\n * @param values - A dictionary of arguments to be passed to the prompt template.\n * @returns A formatted prompt string.\n *\n * @example\n * ```ts\n * prompt.format({ foo: \"bar\" });\n * ```\n */\n abstract format(values: TypedPromptInputValues<RunInput>): Promise<string>;\n\n /**\n * Format the prompt given the input values and return a formatted prompt value.\n * @param values\n * @returns A formatted PromptValue.\n */\n abstract formatPromptValue(\n values: TypedPromptInputValues<RunInput>\n ): Promise<RunOutput>;\n\n /**\n * Return the string type key uniquely identifying this class of prompt template.\n */\n abstract _getPromptType(): string;\n\n /**\n * Return a json-like object representing this prompt template.\n * @deprecated\n */\n serialize(): SerializedBasePromptTemplate {\n throw new Error(\"Use .toJSON() instead\");\n }\n\n /**\n * @deprecated\n * Load a prompt template from a json-like object describing it.\n *\n * @remarks\n * Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can\n * reference remote resources that we read asynchronously with a web\n * request.\n */\n static async deserialize(\n data: SerializedBasePromptTemplate\n ): Promise<\n BasePromptTemplate<InputValues, BasePromptValueInterface, string>\n > {\n switch (data._type) {\n case \"prompt\": {\n const { PromptTemplate } = await import(\"./prompt.js\");\n return PromptTemplate.deserialize(data);\n }\n case undefined: {\n const { PromptTemplate } = await import(\"./prompt.js\");\n return PromptTemplate.deserialize({ ...data, _type: \"prompt\" });\n }\n case \"few_shot\": {\n const { FewShotPromptTemplate } = await import(\"./few_shot.js\");\n return FewShotPromptTemplate.deserialize(data);\n }\n default:\n throw new Error(\n `Invalid prompt type in config: ${\n (data as SerializedBasePromptTemplate)._type\n }`\n );\n }\n }\n}\n"],"mappings":";;;;;;;AAgDA,IAAsB,qBAAtB,cAOU,SAEV;CAGE,kBAAkB;CAElB,eAAe;EAAC;EAAkB;EAAW,KAAK,gBAAgB;CAAC;CAEnE,IAAI,gBAA8C;AAChD,SAAO,EACL,kBAAkB,OACnB;CACF;CAED;CAEA;CAEA;;;;CAKA;;CAGA;CAEA,YAAYA,OAAgC;EAC1C,MAAM,MAAM;EACZ,MAAM,EAAE,gBAAgB,GAAG;AAC3B,MAAI,eAAe,SAAS,OAAO,CACjC,OAAM,IAAI,MACR;EAGJ,OAAO,OAAO,MAAM,MAAM;CAC3B;;;;;;CAWD,MAAM,6BACJC,eAGA;EACA,MAAM,mBAAmB,KAAK,oBAAoB,CAAE;EACpD,MAAMC,gBAAwC,CAAE;AAEhD,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,iBAAiB,CACzD,KAAI,OAAO,UAAU,UACnB,cAAc,OAAO;OAErB,cAAc,OAAO,MAAO,OAAiC;EAIjE,MAAM,YAAY;GAChB,GAAI;GACJ,GAAG;EACJ;AACD,SAAO;CACR;;;;;;;CAQD,MAAM,OACJC,OACAC,SACoB;EACpB,MAAM,WAAW;GACf,GAAG,KAAK;GACR,GAAG,SAAS;EACb;EACD,MAAM,OAAO,CAAC,GAAI,KAAK,QAAQ,CAAE,GAAG,GAAI,SAAS,QAAQ,CAAE,CAAE;AAC7D,SAAO,KAAK,gBACV,CAACD,YAAoB,KAAK,kBAAkBE,QAAM,EAClD,OACA;GAAE,GAAG;GAAS;GAAM;GAAU,SAAS;EAAU,EAClD;CACF;;;;;CAiCD,YAA0C;AACxC,QAAM,IAAI,MAAM;CACjB;;;;;;;;;;CAWD,aAAa,YACXC,MAGA;AACA,UAAQ,KAAK,OAAb;GACE,KAAK,UAAU;IACb,MAAM,EAAE,gBAAgB,GAAG,MAAM,OAAO;AACxC,WAAO,eAAe,YAAY,KAAK;GACxC;GACD,KAAK,QAAW;IACd,MAAM,EAAE,gBAAgB,GAAG,MAAM,OAAO;AACxC,WAAO,eAAe,YAAY;KAAE,GAAG;KAAM,OAAO;IAAU,EAAC;GAChE;GACD,KAAK,YAAY;IACf,MAAM,EAAE,uBAAuB,GAAG,MAAM,OAAO;AAC/C,WAAO,sBAAsB,YAAY,KAAK;GAC/C;GACD,QACE,OAAM,IAAI,MACR,CAAC,+BAA+B,EAC7B,KAAsC,OACvC;EAEP;CACF;AACF"}
1
+ {"version":3,"file":"base.js","names":["input: BasePromptTemplateInput","userVariables: TypedPromptInputValues<RunInput>","partialValues: Record<string, string>","input: RunInput","options?: BaseCallbackConfig","input"],"sources":["../../src/prompts/base.ts"],"sourcesContent":["// Default generic \"any\" values are for backwards compatibility.\n// Replace with \"string\" when we are comfortable with a breaking change.\n\nimport type {\n InputValues,\n PartialValues,\n StringWithAutocomplete,\n} from \"../utils/types/index.js\";\nimport { type BasePromptValueInterface } from \"../prompt_values.js\";\nimport { BaseOutputParser } from \"../output_parsers/index.js\";\nimport type { SerializedFields } from \"../load/map_keys.js\";\nimport { Runnable } from \"../runnables/base.js\";\nimport { BaseCallbackConfig } from \"../callbacks/manager.js\";\n\nexport type TypedPromptInputValues<RunInput> = InputValues<\n StringWithAutocomplete<Extract<keyof RunInput, string>>\n>;\n\nexport type Example = Record<string, string>;\n\n/**\n * Input common to all prompt templates.\n */\nexport interface BasePromptTemplateInput<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n InputVariables extends InputValues = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n> {\n /**\n * A list of variable names the prompt template expects\n */\n inputVariables: Array<Extract<keyof InputVariables, string>>;\n\n /**\n * How to parse the output of calling an LLM on this formatted prompt\n */\n outputParser?: BaseOutputParser;\n\n /** Partial variables */\n partialVariables?: PartialValues<PartialVariableName>;\n}\n\n/**\n * Base class for prompt templates. Exposes a format method that returns a\n * string prompt given a set of input values.\n */\nexport abstract class BasePromptTemplate<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput extends InputValues = any,\n RunOutput extends BasePromptValueInterface = BasePromptValueInterface,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PartialVariableName extends string = any\n >\n extends Runnable<RunInput, RunOutput>\n implements BasePromptTemplateInput\n{\n declare PromptValueReturnType: RunOutput;\n\n lc_serializable = true;\n\n lc_namespace = [\"langchain_core\", \"prompts\", this._getPromptType()];\n\n get lc_attributes(): SerializedFields | undefined {\n return {\n partialVariables: undefined, // python doesn't support this yet\n };\n }\n\n inputVariables: Array<Extract<keyof RunInput, string>>;\n\n outputParser?: BaseOutputParser;\n\n partialVariables: PartialValues<PartialVariableName>;\n\n /**\n * Metadata to be used for tracing.\n */\n metadata?: Record<string, unknown>;\n\n /** Tags to be used for tracing. */\n tags?: string[];\n\n constructor(input: BasePromptTemplateInput) {\n super(input);\n const { inputVariables } = input;\n if (inputVariables.includes(\"stop\")) {\n throw new Error(\n \"Cannot have an input variable named 'stop', as it is used internally, please rename.\"\n );\n }\n Object.assign(this, input);\n }\n\n abstract partial(\n values: PartialValues\n ): Promise<BasePromptTemplate<RunInput, RunOutput, PartialVariableName>>;\n\n /**\n * Merges partial variables and user variables.\n * @param userVariables The user variables to merge with the partial variables.\n * @returns A Promise that resolves to an object containing the merged variables.\n */\n async mergePartialAndUserVariables(\n userVariables: TypedPromptInputValues<RunInput>\n ): Promise<\n InputValues<Extract<keyof RunInput, string> | PartialVariableName>\n > {\n const partialVariables = this.partialVariables ?? {};\n const partialValues: Record<string, string> = {};\n\n for (const [key, value] of Object.entries(partialVariables)) {\n if (typeof value === \"string\") {\n partialValues[key] = value;\n } else {\n partialValues[key] = await (value as () => Promise<string>)();\n }\n }\n\n const allKwargs = {\n ...(partialValues as Record<PartialVariableName, string>),\n ...userVariables,\n };\n return allKwargs;\n }\n\n /**\n * Invokes the prompt template with the given input and options.\n * @param input The input to invoke the prompt template with.\n * @param options Optional configuration for the callback.\n * @returns A Promise that resolves to the output of the prompt template.\n */\n async invoke(\n input: RunInput,\n options?: BaseCallbackConfig\n ): Promise<RunOutput> {\n const metadata = {\n ...this.metadata,\n ...options?.metadata,\n };\n const tags = [...(this.tags ?? []), ...(options?.tags ?? [])];\n return this._callWithConfig(\n (input: RunInput) => this.formatPromptValue(input),\n input,\n { ...options, tags, metadata, runType: \"prompt\" }\n );\n }\n\n /**\n * Format the prompt given the input values.\n *\n * @param values - A dictionary of arguments to be passed to the prompt template.\n * @returns A formatted prompt string.\n *\n * @example\n * ```ts\n * prompt.format({ foo: \"bar\" });\n * ```\n */\n abstract format(values: TypedPromptInputValues<RunInput>): Promise<string>;\n\n /**\n * Format the prompt given the input values and return a formatted prompt value.\n * @param values\n * @returns A formatted PromptValue.\n */\n abstract formatPromptValue(\n values: TypedPromptInputValues<RunInput>\n ): Promise<RunOutput>;\n\n /**\n * Return the string type key uniquely identifying this class of prompt template.\n */\n abstract _getPromptType(): string;\n}\n"],"mappings":";;;;;;;AA+CA,IAAsB,qBAAtB,cAOU,SAEV;CAGE,kBAAkB;CAElB,eAAe;EAAC;EAAkB;EAAW,KAAK,gBAAgB;CAAC;CAEnE,IAAI,gBAA8C;AAChD,SAAO,EACL,kBAAkB,OACnB;CACF;CAED;CAEA;CAEA;;;;CAKA;;CAGA;CAEA,YAAYA,OAAgC;EAC1C,MAAM,MAAM;EACZ,MAAM,EAAE,gBAAgB,GAAG;AAC3B,MAAI,eAAe,SAAS,OAAO,CACjC,OAAM,IAAI,MACR;EAGJ,OAAO,OAAO,MAAM,MAAM;CAC3B;;;;;;CAWD,MAAM,6BACJC,eAGA;EACA,MAAM,mBAAmB,KAAK,oBAAoB,CAAE;EACpD,MAAMC,gBAAwC,CAAE;AAEhD,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,iBAAiB,CACzD,KAAI,OAAO,UAAU,UACnB,cAAc,OAAO;OAErB,cAAc,OAAO,MAAO,OAAiC;EAIjE,MAAM,YAAY;GAChB,GAAI;GACJ,GAAG;EACJ;AACD,SAAO;CACR;;;;;;;CAQD,MAAM,OACJC,OACAC,SACoB;EACpB,MAAM,WAAW;GACf,GAAG,KAAK;GACR,GAAG,SAAS;EACb;EACD,MAAM,OAAO,CAAC,GAAI,KAAK,QAAQ,CAAE,GAAG,GAAI,SAAS,QAAQ,CAAE,CAAE;AAC7D,SAAO,KAAK,gBACV,CAACD,YAAoB,KAAK,kBAAkBE,QAAM,EAClD,OACA;GAAE,GAAG;GAAS;GAAM;GAAU,SAAS;EAAU,EAClD;CACF;AA4BF"}
@@ -278,7 +278,7 @@ var _StringImageMessagePromptTemplate = class extends BaseMessagePromptTemplate
278
278
  const formatted = await prompt.format(inputs);
279
279
  let additionalContentFields;
280
280
  if ("additionalContentFields" in prompt) additionalContentFields = prompt.additionalContentFields;
281
- content.push({
281
+ if (formatted !== "") content.push({
282
282
  ...additionalContentFields,
283
283
  type: "text",
284
284
  text: formatted
@@ -536,10 +536,6 @@ var ChatPromptTemplate = class ChatPromptTemplate extends BaseChatPromptTemplate
536
536
  templateFormat: extra?.templateFormat
537
537
  });
538
538
  }
539
- /** @deprecated Renamed to .fromMessages */
540
- static fromPromptMessages(promptMessages) {
541
- return this.fromMessages(promptMessages);
542
- }
543
539
  };
544
540
 
545
541
  //#endregion