langchain 0.2.10 → 0.2.11

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 (345) hide show
  1. package/chat_models/universal.cjs +1 -0
  2. package/chat_models/universal.d.cts +1 -0
  3. package/chat_models/universal.d.ts +1 -0
  4. package/chat_models/universal.js +1 -0
  5. package/dist/chat_models/universal.cjs +600 -0
  6. package/dist/chat_models/universal.d.ts +115 -0
  7. package/dist/chat_models/universal.js +595 -0
  8. package/dist/document_loaders/web/assemblyai.cjs +9 -1
  9. package/dist/document_loaders/web/assemblyai.js +9 -1
  10. package/dist/experimental/chrome_ai/app/dist/bundle.cjs +1250 -0
  11. package/dist/experimental/chrome_ai/app/dist/bundle.d.ts +1 -0
  12. package/dist/experimental/chrome_ai/app/dist/bundle.js +1249 -0
  13. package/dist/load/import_constants.cjs +1 -0
  14. package/dist/load/import_constants.js +1 -0
  15. package/package.json +65 -6
  16. package/dist/agents/tests/agent.int.test.d.ts +0 -1
  17. package/dist/agents/tests/agent.int.test.js +0 -309
  18. package/dist/agents/tests/chat_convo_output_parser.test.d.ts +0 -1
  19. package/dist/agents/tests/chat_convo_output_parser.test.js +0 -91
  20. package/dist/agents/tests/create_openai_functions_agent.int.test.d.ts +0 -2
  21. package/dist/agents/tests/create_openai_functions_agent.int.test.js +0 -71
  22. package/dist/agents/tests/create_openai_tools_agent.int.test.d.ts +0 -1
  23. package/dist/agents/tests/create_openai_tools_agent.int.test.js +0 -75
  24. package/dist/agents/tests/create_react_agent.int.test.d.ts +0 -1
  25. package/dist/agents/tests/create_react_agent.int.test.js +0 -32
  26. package/dist/agents/tests/create_structured_chat_agent.int.test.d.ts +0 -1
  27. package/dist/agents/tests/create_structured_chat_agent.int.test.js +0 -32
  28. package/dist/agents/tests/create_tool_calling_agent.int.test.d.ts +0 -1
  29. package/dist/agents/tests/create_tool_calling_agent.int.test.js +0 -122
  30. package/dist/agents/tests/create_xml_agent.int.test.d.ts +0 -1
  31. package/dist/agents/tests/create_xml_agent.int.test.js +0 -32
  32. package/dist/agents/tests/json.test.d.ts +0 -1
  33. package/dist/agents/tests/json.test.js +0 -74
  34. package/dist/agents/tests/react.test.d.ts +0 -1
  35. package/dist/agents/tests/react.test.js +0 -44
  36. package/dist/agents/tests/runnable.int.test.d.ts +0 -1
  37. package/dist/agents/tests/runnable.int.test.js +0 -104
  38. package/dist/agents/tests/sql.test.d.ts +0 -1
  39. package/dist/agents/tests/sql.test.js +0 -133
  40. package/dist/agents/tests/structured_chat_output_parser.test.d.ts +0 -1
  41. package/dist/agents/tests/structured_chat_output_parser.test.js +0 -35
  42. package/dist/agents/tests/structured_chat_output_parser_with_retries.int.test.d.ts +0 -1
  43. package/dist/agents/tests/structured_chat_output_parser_with_retries.int.test.js +0 -44
  44. package/dist/agents/tests/structured_output_runnables.int.test.d.ts +0 -1
  45. package/dist/agents/tests/structured_output_runnables.int.test.js +0 -112
  46. package/dist/agents/toolkits/tests/conversational_retrieval.int.test.d.ts +0 -1
  47. package/dist/agents/toolkits/tests/conversational_retrieval.int.test.js +0 -41
  48. package/dist/cache/tests/file_system.int.test.d.ts +0 -1
  49. package/dist/cache/tests/file_system.int.test.js +0 -32
  50. package/dist/chains/openai_functions/tests/create_runnable_chains.int.test.d.ts +0 -1
  51. package/dist/chains/openai_functions/tests/create_runnable_chains.int.test.js +0 -139
  52. package/dist/chains/openai_functions/tests/extraction.int.test.d.ts +0 -1
  53. package/dist/chains/openai_functions/tests/extraction.int.test.js +0 -33
  54. package/dist/chains/openai_functions/tests/openapi.int.test.d.ts +0 -1
  55. package/dist/chains/openai_functions/tests/openapi.int.test.js +0 -130
  56. package/dist/chains/openai_functions/tests/openapi.test.d.ts +0 -1
  57. package/dist/chains/openai_functions/tests/openapi.test.js +0 -172
  58. package/dist/chains/openai_functions/tests/structured_output.int.test.d.ts +0 -1
  59. package/dist/chains/openai_functions/tests/structured_output.int.test.js +0 -40
  60. package/dist/chains/openai_functions/tests/structured_output.test.d.ts +0 -1
  61. package/dist/chains/openai_functions/tests/structured_output.test.js +0 -102
  62. package/dist/chains/openai_functions/tests/tagging.int.test.d.ts +0 -1
  63. package/dist/chains/openai_functions/tests/tagging.int.test.js +0 -21
  64. package/dist/chains/query_constructor/tests/query_chain.int.test.d.ts +0 -1
  65. package/dist/chains/query_constructor/tests/query_chain.int.test.js +0 -93
  66. package/dist/chains/query_constructor/tests/query_parser.test.d.ts +0 -1
  67. package/dist/chains/query_constructor/tests/query_parser.test.js +0 -28
  68. package/dist/chains/question_answering/tests/load.int.test.d.ts +0 -1
  69. package/dist/chains/question_answering/tests/load.int.test.js +0 -39
  70. package/dist/chains/router/tests/multi_prompt.int.test.d.ts +0 -1
  71. package/dist/chains/router/tests/multi_prompt.int.test.js +0 -45
  72. package/dist/chains/router/tests/multi_prompt.test.d.ts +0 -1
  73. package/dist/chains/router/tests/multi_prompt.test.js +0 -62
  74. package/dist/chains/router/tests/multi_retrieval_qa.int.test.d.ts +0 -1
  75. package/dist/chains/router/tests/multi_retrieval_qa.int.test.js +0 -67
  76. package/dist/chains/router/tests/multi_retrieval_qa.test.d.ts +0 -1
  77. package/dist/chains/router/tests/multi_retrieval_qa.test.js +0 -125
  78. package/dist/chains/summarization/tests/load.int.test.d.ts +0 -1
  79. package/dist/chains/summarization/tests/load.int.test.js +0 -37
  80. package/dist/chains/tests/api_chain.int.test.d.ts +0 -1
  81. package/dist/chains/tests/api_chain.int.test.js +0 -55
  82. package/dist/chains/tests/combine_docs_chain.int.test.d.ts +0 -1
  83. package/dist/chains/tests/combine_docs_chain.int.test.js +0 -50
  84. package/dist/chains/tests/combine_docs_chain.test.d.ts +0 -1
  85. package/dist/chains/tests/combine_docs_chain.test.js +0 -98
  86. package/dist/chains/tests/constitutional_chain.int.test.d.ts +0 -1
  87. package/dist/chains/tests/constitutional_chain.int.test.js +0 -30
  88. package/dist/chains/tests/constitutional_chain.test.d.ts +0 -1
  89. package/dist/chains/tests/constitutional_chain.test.js +0 -63
  90. package/dist/chains/tests/conversation_chain.int.test.d.ts +0 -1
  91. package/dist/chains/tests/conversation_chain.int.test.js +0 -9
  92. package/dist/chains/tests/conversational_retrieval_chain.int.test.d.ts +0 -1
  93. package/dist/chains/tests/conversational_retrieval_chain.int.test.js +0 -243
  94. package/dist/chains/tests/example_data/open_meteo_docs.d.ts +0 -1
  95. package/dist/chains/tests/example_data/open_meteo_docs.js +0 -29
  96. package/dist/chains/tests/history_aware_retriever.int.test.d.ts +0 -1
  97. package/dist/chains/tests/history_aware_retriever.int.test.js +0 -41
  98. package/dist/chains/tests/history_aware_retriever.test.d.ts +0 -1
  99. package/dist/chains/tests/history_aware_retriever.test.js +0 -27
  100. package/dist/chains/tests/llm_chain.int.test.d.ts +0 -1
  101. package/dist/chains/tests/llm_chain.int.test.js +0 -119
  102. package/dist/chains/tests/openai_moderation.int.test.d.ts +0 -1
  103. package/dist/chains/tests/openai_moderation.int.test.js +0 -30
  104. package/dist/chains/tests/retrieval_chain.int.test.d.ts +0 -1
  105. package/dist/chains/tests/retrieval_chain.int.test.js +0 -69
  106. package/dist/chains/tests/retrieval_chain.test.d.ts +0 -1
  107. package/dist/chains/tests/retrieval_chain.test.js +0 -36
  108. package/dist/chains/tests/sequential_chain.int.test.d.ts +0 -1
  109. package/dist/chains/tests/sequential_chain.int.test.js +0 -88
  110. package/dist/chains/tests/sequential_chain.test.d.ts +0 -1
  111. package/dist/chains/tests/sequential_chain.test.js +0 -295
  112. package/dist/chains/tests/simple_sequential_chain.int.test.d.ts +0 -1
  113. package/dist/chains/tests/simple_sequential_chain.int.test.js +0 -81
  114. package/dist/chains/tests/simple_sequential_chain.test.d.ts +0 -1
  115. package/dist/chains/tests/simple_sequential_chain.test.js +0 -128
  116. package/dist/chains/tests/sql_db_chain.int.test.d.ts +0 -1
  117. package/dist/chains/tests/sql_db_chain.int.test.js +0 -125
  118. package/dist/chains/tests/transform.test.d.ts +0 -1
  119. package/dist/chains/tests/transform.test.js +0 -12
  120. package/dist/chains/tests/vector_db_qa_chain.int.test.d.ts +0 -1
  121. package/dist/chains/tests/vector_db_qa_chain.int.test.js +0 -45
  122. package/dist/document_loaders/tests/assemblyai.int.test.d.ts +0 -1
  123. package/dist/document_loaders/tests/assemblyai.int.test.js +0 -111
  124. package/dist/document_loaders/tests/chatgpt-blob.test.d.ts +0 -1
  125. package/dist/document_loaders/tests/chatgpt-blob.test.js +0 -30
  126. package/dist/document_loaders/tests/chatgpt.test.d.ts +0 -1
  127. package/dist/document_loaders/tests/chatgpt.test.js +0 -29
  128. package/dist/document_loaders/tests/cheerio.int.test.d.ts +0 -1
  129. package/dist/document_loaders/tests/cheerio.int.test.js +0 -21
  130. package/dist/document_loaders/tests/college_confidential.int.test.d.ts +0 -1
  131. package/dist/document_loaders/tests/college_confidential.int.test.js +0 -6
  132. package/dist/document_loaders/tests/confluence.test.d.ts +0 -1
  133. package/dist/document_loaders/tests/confluence.test.js +0 -52
  134. package/dist/document_loaders/tests/couchbase.int.test.d.ts +0 -1
  135. package/dist/document_loaders/tests/couchbase.int.test.js +0 -28
  136. package/dist/document_loaders/tests/csv-blob.test.d.ts +0 -1
  137. package/dist/document_loaders/tests/csv-blob.test.js +0 -53
  138. package/dist/document_loaders/tests/csv.test.d.ts +0 -1
  139. package/dist/document_loaders/tests/csv.test.js +0 -41
  140. package/dist/document_loaders/tests/directory.test.d.ts +0 -1
  141. package/dist/document_loaders/tests/directory.test.js +0 -38
  142. package/dist/document_loaders/tests/docx.test.d.ts +0 -1
  143. package/dist/document_loaders/tests/docx.test.js +0 -11
  144. package/dist/document_loaders/tests/epub.test.d.ts +0 -1
  145. package/dist/document_loaders/tests/epub.test.js +0 -18
  146. package/dist/document_loaders/tests/example_data/github_api_responses.d.ts +0 -5
  147. package/dist/document_loaders/tests/example_data/github_api_responses.js +0 -91
  148. package/dist/document_loaders/tests/figma.int.test.d.ts +0 -1
  149. package/dist/document_loaders/tests/figma.int.test.js +0 -13
  150. package/dist/document_loaders/tests/firecrawl.int.test.d.ts +0 -1
  151. package/dist/document_loaders/tests/firecrawl.int.test.js +0 -30
  152. package/dist/document_loaders/tests/gitbook.int.test.d.ts +0 -1
  153. package/dist/document_loaders/tests/gitbook.int.test.js +0 -14
  154. package/dist/document_loaders/tests/github.int.test.d.ts +0 -1
  155. package/dist/document_loaders/tests/github.int.test.js +0 -86
  156. package/dist/document_loaders/tests/github.test.d.ts +0 -1
  157. package/dist/document_loaders/tests/github.test.js +0 -51
  158. package/dist/document_loaders/tests/hn.int.test.d.ts +0 -1
  159. package/dist/document_loaders/tests/hn.int.test.js +0 -6
  160. package/dist/document_loaders/tests/imsdb.test.d.ts +0 -1
  161. package/dist/document_loaders/tests/imsdb.test.js +0 -6
  162. package/dist/document_loaders/tests/json-blob.test.d.ts +0 -1
  163. package/dist/document_loaders/tests/json-blob.test.js +0 -91
  164. package/dist/document_loaders/tests/json.test.d.ts +0 -1
  165. package/dist/document_loaders/tests/json.test.js +0 -69
  166. package/dist/document_loaders/tests/jsonl-blob.test.d.ts +0 -1
  167. package/dist/document_loaders/tests/jsonl-blob.test.js +0 -46
  168. package/dist/document_loaders/tests/jsonl.test.d.ts +0 -1
  169. package/dist/document_loaders/tests/jsonl.test.js +0 -15
  170. package/dist/document_loaders/tests/multi_file.test.d.ts +0 -1
  171. package/dist/document_loaders/tests/multi_file.test.js +0 -49
  172. package/dist/document_loaders/tests/notion.test.d.ts +0 -1
  173. package/dist/document_loaders/tests/notion.test.js +0 -11
  174. package/dist/document_loaders/tests/notionapi.int.test.d.ts +0 -1
  175. package/dist/document_loaders/tests/notionapi.int.test.js +0 -80
  176. package/dist/document_loaders/tests/notionapi.test.d.ts +0 -1
  177. package/dist/document_loaders/tests/notionapi.test.js +0 -84
  178. package/dist/document_loaders/tests/notiondb.int.test.d.ts +0 -1
  179. package/dist/document_loaders/tests/notiondb.int.test.js +0 -13
  180. package/dist/document_loaders/tests/obsidian.test.d.ts +0 -1
  181. package/dist/document_loaders/tests/obsidian.test.js +0 -119
  182. package/dist/document_loaders/tests/pdf-blob.test.d.ts +0 -1
  183. package/dist/document_loaders/tests/pdf-blob.test.js +0 -44
  184. package/dist/document_loaders/tests/pdf.test.d.ts +0 -1
  185. package/dist/document_loaders/tests/pdf.test.js +0 -25
  186. package/dist/document_loaders/tests/playwright_web.int.test.d.ts +0 -1
  187. package/dist/document_loaders/tests/playwright_web.int.test.js +0 -27
  188. package/dist/document_loaders/tests/pptx.test.d.ts +0 -1
  189. package/dist/document_loaders/tests/pptx.test.js +0 -17
  190. package/dist/document_loaders/tests/puppeteer.int.test.d.ts +0 -1
  191. package/dist/document_loaders/tests/puppeteer.int.test.js +0 -47
  192. package/dist/document_loaders/tests/recursive_url.int.test.d.ts +0 -1
  193. package/dist/document_loaders/tests/recursive_url.int.test.js +0 -64
  194. package/dist/document_loaders/tests/s3.int.test.d.ts +0 -1
  195. package/dist/document_loaders/tests/s3.int.test.js +0 -48
  196. package/dist/document_loaders/tests/searchapi.test.d.ts +0 -1
  197. package/dist/document_loaders/tests/searchapi.test.js +0 -29
  198. package/dist/document_loaders/tests/serpapi.test.d.ts +0 -1
  199. package/dist/document_loaders/tests/serpapi.test.js +0 -21
  200. package/dist/document_loaders/tests/sitemap.int.test.d.ts +0 -1
  201. package/dist/document_loaders/tests/sitemap.int.test.js +0 -28
  202. package/dist/document_loaders/tests/sonix_audio.int.test.d.ts +0 -1
  203. package/dist/document_loaders/tests/sonix_audio.int.test.js +0 -55
  204. package/dist/document_loaders/tests/sort_xyz_blockchain.int.test.d.ts +0 -1
  205. package/dist/document_loaders/tests/sort_xyz_blockchain.int.test.js +0 -38
  206. package/dist/document_loaders/tests/srt-blob.test.d.ts +0 -1
  207. package/dist/document_loaders/tests/srt-blob.test.js +0 -18
  208. package/dist/document_loaders/tests/srt.test.d.ts +0 -1
  209. package/dist/document_loaders/tests/srt.test.js +0 -16
  210. package/dist/document_loaders/tests/text-blob.test.d.ts +0 -1
  211. package/dist/document_loaders/tests/text-blob.test.js +0 -14
  212. package/dist/document_loaders/tests/text.test.d.ts +0 -1
  213. package/dist/document_loaders/tests/text.test.js +0 -22
  214. package/dist/document_loaders/tests/unstructured.int.test.d.ts +0 -1
  215. package/dist/document_loaders/tests/unstructured.int.test.js +0 -58
  216. package/dist/document_loaders/tests/webpdf.int.test.d.ts +0 -1
  217. package/dist/document_loaders/tests/webpdf.int.test.js +0 -90
  218. package/dist/document_transformers/tests/openai_functions.int.test.d.ts +0 -1
  219. package/dist/document_transformers/tests/openai_functions.int.test.js +0 -40
  220. package/dist/embeddings/tests/cache.test.d.ts +0 -1
  221. package/dist/embeddings/tests/cache.test.js +0 -24
  222. package/dist/embeddings/tests/fake.test.d.ts +0 -1
  223. package/dist/embeddings/tests/fake.test.js +0 -34
  224. package/dist/evaluation/agents/tests/trajectory_eval_chain.int.test.d.ts +0 -1
  225. package/dist/evaluation/agents/tests/trajectory_eval_chain.int.test.js +0 -33
  226. package/dist/evaluation/comparison/tests/pairwise_eval_chain.int.test.d.ts +0 -1
  227. package/dist/evaluation/comparison/tests/pairwise_eval_chain.int.test.js +0 -46
  228. package/dist/evaluation/criteria/tests/criteria_eval_chain.int.test.d.ts +0 -1
  229. package/dist/evaluation/criteria/tests/criteria_eval_chain.int.test.js +0 -108
  230. package/dist/evaluation/embedding_distance/tests/embedding_distance_eval_chain.int.test.d.ts +0 -1
  231. package/dist/evaluation/embedding_distance/tests/embedding_distance_eval_chain.int.test.js +0 -26
  232. package/dist/evaluation/qa/tests/eval_chain.int.test.d.ts +0 -1
  233. package/dist/evaluation/qa/tests/eval_chain.int.test.js +0 -27
  234. package/dist/experimental/autogpt/tests/output_parser.test.d.ts +0 -1
  235. package/dist/experimental/autogpt/tests/output_parser.test.js +0 -8
  236. package/dist/experimental/autogpt/tests/prompt.test.d.ts +0 -1
  237. package/dist/experimental/autogpt/tests/prompt.test.js +0 -69
  238. package/dist/experimental/autogpt/tests/prompt_generator.test.d.ts +0 -1
  239. package/dist/experimental/autogpt/tests/prompt_generator.test.js +0 -91
  240. package/dist/experimental/chains/tests/violation_of_expectations_chain.int.test.d.ts +0 -1
  241. package/dist/experimental/chains/tests/violation_of_expectations_chain.int.test.js +0 -26
  242. package/dist/experimental/generative_agents/tests/generative_agent.int.test.d.ts +0 -1
  243. package/dist/experimental/generative_agents/tests/generative_agent.int.test.js +0 -304
  244. package/dist/experimental/masking/tests/masking-extended.test.d.ts +0 -1
  245. package/dist/experimental/masking/tests/masking-extended.test.js +0 -58
  246. package/dist/experimental/masking/tests/masking.test.d.ts +0 -1
  247. package/dist/experimental/masking/tests/masking.test.js +0 -388
  248. package/dist/experimental/openai_assistant/tests/openai_assistant.int.test.d.ts +0 -1
  249. package/dist/experimental/openai_assistant/tests/openai_assistant.int.test.js +0 -203
  250. package/dist/experimental/openai_files/tests/openai_file.int.test.d.ts +0 -1
  251. package/dist/experimental/openai_files/tests/openai_file.int.test.js +0 -87
  252. package/dist/experimental/plan_and_execute/tests/plan_and_execute.int.test.d.ts +0 -1
  253. package/dist/experimental/plan_and_execute/tests/plan_and_execute.int.test.js +0 -54
  254. package/dist/experimental/prompts/tests/handlebars.test.d.ts +0 -1
  255. package/dist/experimental/prompts/tests/handlebars.test.js +0 -24
  256. package/dist/experimental/tools/tests/pyinterpreter.int.test.d.ts +0 -1
  257. package/dist/experimental/tools/tests/pyinterpreter.int.test.js +0 -22
  258. package/dist/load/tests/cross_language.test.d.ts +0 -1
  259. package/dist/load/tests/cross_language.test.js +0 -83
  260. package/dist/load/tests/load.int.test.d.ts +0 -1
  261. package/dist/load/tests/load.int.test.js +0 -9
  262. package/dist/load/tests/load.test.d.ts +0 -1
  263. package/dist/load/tests/load.test.js +0 -412
  264. package/dist/memory/tests/buffer_memory.test.d.ts +0 -1
  265. package/dist/memory/tests/buffer_memory.test.js +0 -34
  266. package/dist/memory/tests/buffer_token_memory.int.test.d.ts +0 -1
  267. package/dist/memory/tests/buffer_token_memory.int.test.js +0 -47
  268. package/dist/memory/tests/buffer_window_memory.test.d.ts +0 -1
  269. package/dist/memory/tests/buffer_window_memory.test.js +0 -42
  270. package/dist/memory/tests/combined_memory.int.test.d.ts +0 -1
  271. package/dist/memory/tests/combined_memory.int.test.js +0 -74
  272. package/dist/memory/tests/entity_memory.int.test.d.ts +0 -1
  273. package/dist/memory/tests/entity_memory.int.test.js +0 -79
  274. package/dist/memory/tests/entity_memory.test.d.ts +0 -1
  275. package/dist/memory/tests/entity_memory.test.js +0 -48
  276. package/dist/memory/tests/summary.int.test.d.ts +0 -1
  277. package/dist/memory/tests/summary.int.test.js +0 -50
  278. package/dist/memory/tests/summary_buffer.int.test.d.ts +0 -1
  279. package/dist/memory/tests/summary_buffer.int.test.js +0 -55
  280. package/dist/memory/tests/vector_store_memory.int.test.d.ts +0 -1
  281. package/dist/memory/tests/vector_store_memory.int.test.js +0 -55
  282. package/dist/output_parsers/tests/combining.int.test.d.ts +0 -1
  283. package/dist/output_parsers/tests/combining.int.test.js +0 -26
  284. package/dist/output_parsers/tests/combining.test.d.ts +0 -1
  285. package/dist/output_parsers/tests/combining.test.js +0 -54
  286. package/dist/output_parsers/tests/datetime.test.d.ts +0 -1
  287. package/dist/output_parsers/tests/datetime.test.js +0 -14
  288. package/dist/output_parsers/tests/expression.test.d.ts +0 -1
  289. package/dist/output_parsers/tests/expression.test.js +0 -339
  290. package/dist/output_parsers/tests/http_response.test.d.ts +0 -1
  291. package/dist/output_parsers/tests/http_response.test.js +0 -39
  292. package/dist/output_parsers/tests/list.test.d.ts +0 -1
  293. package/dist/output_parsers/tests/list.test.js +0 -27
  294. package/dist/output_parsers/tests/openai_functions.int.test.d.ts +0 -1
  295. package/dist/output_parsers/tests/openai_functions.int.test.js +0 -89
  296. package/dist/output_parsers/tests/openai_tools.int.test.d.ts +0 -1
  297. package/dist/output_parsers/tests/openai_tools.int.test.js +0 -36
  298. package/dist/output_parsers/tests/structured.int.test.d.ts +0 -1
  299. package/dist/output_parsers/tests/structured.int.test.js +0 -150
  300. package/dist/prompts/tests/selectors.test.d.ts +0 -1
  301. package/dist/prompts/tests/selectors.test.js +0 -59
  302. package/dist/retrievers/self_query/tests/memory_self_query.int.test.d.ts +0 -1
  303. package/dist/retrievers/self_query/tests/memory_self_query.int.test.js +0 -330
  304. package/dist/retrievers/tests/chain_extract.int.test.d.ts +0 -1
  305. package/dist/retrievers/tests/chain_extract.int.test.js +0 -32
  306. package/dist/retrievers/tests/ensemble_retriever.int.test.d.ts +0 -1
  307. package/dist/retrievers/tests/ensemble_retriever.int.test.js +0 -74
  308. package/dist/retrievers/tests/hyde.int.test.d.ts +0 -1
  309. package/dist/retrievers/tests/hyde.int.test.js +0 -44
  310. package/dist/retrievers/tests/matryoshka_retriever.int.test.d.ts +0 -1
  311. package/dist/retrievers/tests/matryoshka_retriever.int.test.js +0 -113
  312. package/dist/retrievers/tests/multi_query.int.test.d.ts +0 -1
  313. package/dist/retrievers/tests/multi_query.int.test.js +0 -45
  314. package/dist/retrievers/tests/parent_document.int.test.d.ts +0 -1
  315. package/dist/retrievers/tests/parent_document.int.test.js +0 -122
  316. package/dist/retrievers/tests/score_threshold.int.test.d.ts +0 -1
  317. package/dist/retrievers/tests/score_threshold.int.test.js +0 -83
  318. package/dist/retrievers/tests/time_weighted.test.d.ts +0 -1
  319. package/dist/retrievers/tests/time_weighted.test.js +0 -320
  320. package/dist/retrievers/tests/vectorstores.test.d.ts +0 -1
  321. package/dist/retrievers/tests/vectorstores.test.js +0 -50
  322. package/dist/smith/tests/run_on_dataset.int.test.d.ts +0 -1
  323. package/dist/smith/tests/run_on_dataset.int.test.js +0 -257
  324. package/dist/smith/tests/runner_utils.int.test.d.ts +0 -9
  325. package/dist/smith/tests/runner_utils.int.test.js +0 -234
  326. package/dist/storage/tests/file_system.test.d.ts +0 -1
  327. package/dist/storage/tests/file_system.test.js +0 -81
  328. package/dist/tools/tests/chain.test.d.ts +0 -1
  329. package/dist/tools/tests/chain.test.js +0 -136
  330. package/dist/tools/tests/webbrowser.int.test.d.ts +0 -1
  331. package/dist/tools/tests/webbrowser.int.test.js +0 -80
  332. package/dist/tools/tests/webbrowser.test.d.ts +0 -1
  333. package/dist/tools/tests/webbrowser.test.js +0 -21
  334. package/dist/util/tests/async_caller.int.test.d.ts +0 -1
  335. package/dist/util/tests/async_caller.int.test.js +0 -34
  336. package/dist/util/tests/azure.test.d.ts +0 -1
  337. package/dist/util/tests/azure.test.js +0 -42
  338. package/dist/util/tests/openai-stream.test.d.ts +0 -1
  339. package/dist/util/tests/openai-stream.test.js +0 -135
  340. package/dist/util/tests/set.test.d.ts +0 -1
  341. package/dist/util/tests/set.test.js +0 -36
  342. package/dist/util/tests/sql_utils.test.d.ts +0 -1
  343. package/dist/util/tests/sql_utils.test.js +0 -50
  344. package/dist/vectorstores/tests/memory.test.d.ts +0 -1
  345. package/dist/vectorstores/tests/memory.test.js +0 -78
@@ -1,412 +0,0 @@
1
- import { test, expect } from "@jest/globals";
2
- import { stringify } from "yaml";
3
- import { z } from "zod";
4
- import { RunnableSequence } from "@langchain/core/runnables";
5
- import { OpenAI, ChatOpenAI } from "@langchain/openai";
6
- import { HumanMessagePromptTemplate, SystemMessagePromptTemplate, ChatPromptTemplate, FewShotPromptTemplate, PromptTemplate, } from "@langchain/core/prompts";
7
- import { LengthBasedExampleSelector } from "@langchain/core/example_selectors";
8
- import { Serializable } from "@langchain/core/load/serializable";
9
- import { ConsoleCallbackHandler } from "@langchain/core/tracers/console";
10
- import { CommaSeparatedListOutputParser } from "@langchain/core/output_parsers";
11
- import { LLMChain } from "../../chains/llm_chain.js";
12
- import { initializeAgentExecutorWithOptions } from "../../agents/initialize.js";
13
- import { Calculator } from "../../util/testing/tools/calculator.js";
14
- import { RequestsGetTool } from "../../tools/requests.js";
15
- import { JsonListKeysTool, JsonSpec } from "../../tools/json.js";
16
- import { AgentExecutor } from "../../agents/executor.js";
17
- import { StructuredOutputParser } from "../../output_parsers/structured.js";
18
- import { RegexParser } from "../../output_parsers/regex.js";
19
- import { load } from "../index.js";
20
- test("serialize + deserialize custom classes", async () => {
21
- class Person extends Serializable {
22
- get lc_secrets() {
23
- return { apiKey: "PERSON_API_KEY" };
24
- }
25
- get lc_attributes() {
26
- return { hello: this.hello };
27
- }
28
- constructor(fields) {
29
- super(fields);
30
- Object.defineProperty(this, "lc_namespace", {
31
- enumerable: true,
32
- configurable: true,
33
- writable: true,
34
- value: ["langchain", "tests"]
35
- });
36
- Object.defineProperty(this, "lc_serializable", {
37
- enumerable: true,
38
- configurable: true,
39
- writable: true,
40
- value: true
41
- });
42
- Object.defineProperty(this, "hello", {
43
- enumerable: true,
44
- configurable: true,
45
- writable: true,
46
- value: 3
47
- });
48
- }
49
- }
50
- class SpecialPerson extends Person {
51
- get lc_secrets() {
52
- return {
53
- anotherApiKey: "SPECIAL_PERSON_API_KEY",
54
- inherited: "SPECIAL_PERSON_INHERITED_API_KEY",
55
- "nested.api.key": "SPECIAL_PERSON_NESTED_API_KEY",
56
- };
57
- }
58
- get lc_attributes() {
59
- return { by: this.bye };
60
- }
61
- constructor(fields) {
62
- super(fields);
63
- Object.defineProperty(this, "bye", {
64
- enumerable: true,
65
- configurable: true,
66
- writable: true,
67
- value: 4
68
- });
69
- Object.defineProperty(this, "inherited", {
70
- enumerable: true,
71
- configurable: true,
72
- writable: true,
73
- value: void 0
74
- });
75
- Object.defineProperty(this, "nested", {
76
- enumerable: true,
77
- configurable: true,
78
- writable: true,
79
- value: void 0
80
- });
81
- this.inherited = fields.inehrited ?? "i-key";
82
- this.nested = fields.nested ?? { api: { key: "n-key" } };
83
- }
84
- }
85
- const person = new Person({ aField: "hello", apiKey: "a-key" });
86
- const lc_argumentsBefore = person.lc_kwargs;
87
- const str = JSON.stringify(person, null, 2);
88
- expect(person.lc_kwargs).toEqual(lc_argumentsBefore);
89
- expect(stringify(JSON.parse(str))).toMatchSnapshot();
90
- const person2 = await load(str, {
91
- PERSON_API_KEY: "a-key",
92
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
- }, {
94
- "langchain/tests": { Person },
95
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
- });
97
- expect(person2).toBeInstanceOf(Person);
98
- expect(JSON.stringify(person2, null, 2)).toBe(str);
99
- const sperson = new SpecialPerson({
100
- aField: "hello",
101
- apiKey: "a-key",
102
- anotherApiKey: "b-key",
103
- // We explicitly do not provide the inherited and nested key
104
- // to test that it has been extracted during serialisation
105
- // simulating obtaining value from environment value
106
- // inherited: "i-key",
107
- // nested: { api: { key: "n-key" } },
108
- });
109
- const sstr = JSON.stringify(sperson, null, 2);
110
- expect(stringify(JSON.parse(sstr))).toMatchSnapshot();
111
- const sperson2 = await load(sstr, {
112
- PERSON_API_KEY: "a-key",
113
- SPECIAL_PERSON_API_KEY: "b-key",
114
- SPECIAL_PERSON_NESTED_API_KEY: "n-key",
115
- SPECIAL_PERSON_INHERITED_API_KEY: "i-key",
116
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
- }, {
118
- "langchain/tests": { SpecialPerson },
119
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
- });
121
- expect(sperson2).toBeInstanceOf(SpecialPerson);
122
- expect(JSON.stringify(sperson2, null, 2)).toBe(sstr);
123
- });
124
- test("serialize + deserialize llm", async () => {
125
- // eslint-disable-next-line no-process-env
126
- process.env.OPENAI_API_KEY = "openai-key";
127
- const llm = new OpenAI({
128
- temperature: 0.5,
129
- modelName: "davinci",
130
- });
131
- llm.temperature = 0.7;
132
- const lc_argumentsBefore = llm.lc_kwargs;
133
- const str = JSON.stringify(llm, null, 2);
134
- expect(llm.lc_kwargs).toEqual(lc_argumentsBefore);
135
- expect(stringify(JSON.parse(str))).toMatchSnapshot();
136
- expect(JSON.parse(str).kwargs.temperature).toBe(0.7);
137
- expect(JSON.parse(str).kwargs.model).toBe("davinci");
138
- expect(JSON.parse(str).kwargs.openai_api_key.type).toBe("secret");
139
- // Accept secret in secret map
140
- const llm2 = await load(str, {
141
- OPENAI_API_KEY: "openai-key",
142
- });
143
- expect(llm2).toBeInstanceOf(OpenAI);
144
- expect(JSON.stringify(llm2, null, 2)).toBe(str);
145
- // Accept secret as env var
146
- const llm3 = await load(str);
147
- expect(llm3).toBeInstanceOf(OpenAI);
148
- expect(llm.openAIApiKey).toBe(llm3.openAIApiKey);
149
- expect(JSON.stringify(llm3, null, 2)).toBe(str);
150
- });
151
- test("serialize + deserialize llm chain string prompt", async () => {
152
- const llm = new OpenAI({
153
- temperature: 0.5,
154
- modelName: "davinci",
155
- openAIApiKey: "openai-key",
156
- verbose: true,
157
- callbacks: [
158
- new ConsoleCallbackHandler(),
159
- {
160
- handleLLMEnd(output) {
161
- console.log(output);
162
- },
163
- },
164
- ],
165
- });
166
- const prompt = PromptTemplate.fromTemplate("Hello, {name}!");
167
- const chain = new LLMChain({ llm, prompt });
168
- const str = JSON.stringify(chain, null, 2);
169
- expect(JSON.parse(str).kwargs.callbacks).toBeUndefined();
170
- expect(JSON.parse(str).kwargs.verbose).toBeUndefined();
171
- expect(stringify(JSON.parse(str))).toMatchSnapshot();
172
- const chain2 = await load(str, {
173
- OPENAI_API_KEY: "openai-key",
174
- });
175
- expect(chain2).toBeInstanceOf(LLMChain);
176
- expect(JSON.stringify(chain2, null, 2)).toBe(str);
177
- });
178
- test("serialize + deserialize with new and old ids", async () => {
179
- const prompt = PromptTemplate.fromTemplate("Hello, {name}!");
180
- const strWithNewId = JSON.stringify(prompt, null, 2);
181
- expect(stringify(JSON.parse(strWithNewId))).toMatchSnapshot();
182
- expect(JSON.parse(strWithNewId).id).toEqual([
183
- "langchain_core",
184
- "prompts",
185
- "prompt",
186
- "PromptTemplate",
187
- ]);
188
- const strWithOldId = JSON.stringify({
189
- ...JSON.parse(strWithNewId),
190
- id: ["langchain", "prompts", "prompt", "PromptTemplate"],
191
- });
192
- const prompt2 = await load(strWithOldId);
193
- expect(prompt2).toBeInstanceOf(PromptTemplate);
194
- const prompt3 = await load(strWithNewId);
195
- expect(prompt3).toBeInstanceOf(PromptTemplate);
196
- });
197
- test("serialize + deserialize runnable sequence with new and old ids", async () => {
198
- const runnable = RunnableSequence.from([
199
- ChatPromptTemplate.fromTemplate("hi there"),
200
- new ChatOpenAI(),
201
- ]);
202
- const strWithNewId = JSON.stringify(runnable, null, 2);
203
- expect(stringify(JSON.parse(strWithNewId))).toMatchSnapshot();
204
- expect(JSON.parse(strWithNewId).id).toEqual([
205
- "langchain_core",
206
- "runnables",
207
- "RunnableSequence",
208
- ]);
209
- const strWithOldId = JSON.stringify({
210
- ...JSON.parse(strWithNewId),
211
- id: ["langchain", "schema", "runnable", "RunnableSequence"],
212
- });
213
- const runnable2 = await load(strWithOldId);
214
- expect(runnable2).toBeInstanceOf(RunnableSequence);
215
- const runnable3 = await load(strWithNewId);
216
- expect(runnable3).toBeInstanceOf(RunnableSequence);
217
- });
218
- test("serialize + deserialize llm chain chat prompt", async () => {
219
- // eslint-disable-next-line no-process-env
220
- process.env.OPENAI_API_KEY = undefined;
221
- const llm = new ChatOpenAI({
222
- temperature: 0.5,
223
- modelName: "gpt-4",
224
- streaming: true,
225
- azureOpenAIApiKey: "openai-key",
226
- azureOpenAIApiInstanceName: "openai-instance",
227
- azureOpenAIApiDeploymentName: "openai-deployment",
228
- azureOpenAIApiVersion: "openai-version",
229
- prefixMessages: [
230
- {
231
- role: "system",
232
- content: "You're a nice assistant",
233
- },
234
- ],
235
- });
236
- const prompt = ChatPromptTemplate.fromMessages([
237
- SystemMessagePromptTemplate.fromTemplate("You are talking to {name}."),
238
- HumanMessagePromptTemplate.fromTemplate("Hello, nice model."),
239
- ]);
240
- const chain = new LLMChain({ llm, prompt });
241
- const str = JSON.stringify(chain, null, 2);
242
- expect(stringify(JSON.parse(str))).toMatchSnapshot();
243
- const chain2 = await load(str, {
244
- AZURE_OPENAI_API_KEY: "openai-key",
245
- });
246
- expect(chain2).toBeInstanceOf(LLMChain);
247
- expect(JSON.stringify(chain2, null, 2)).toBe(str);
248
- });
249
- test("serialize + deserialize llm chain few shot prompt w/ examples", async () => {
250
- const llm = new OpenAI({
251
- temperature: 0.5,
252
- modelName: "davinci",
253
- openAIApiKey: "openai-key",
254
- callbacks: [new ConsoleCallbackHandler()],
255
- });
256
- const prompt = new FewShotPromptTemplate({
257
- examples: [{ yo: "1" }, { yo: "2" }],
258
- prefix: "You are a nice assistant",
259
- examplePrompt: PromptTemplate.fromTemplate("An example about {yo}"),
260
- suffix: "My name is {name}",
261
- inputVariables: ["yo", "name"],
262
- });
263
- const chain = new LLMChain({ llm, prompt });
264
- const str = JSON.stringify(chain, null, 2);
265
- expect(stringify(JSON.parse(str))).toMatchSnapshot();
266
- await expect(load(str, {
267
- OPENAI_API_KEY: "openai-key",
268
- })).rejects.toThrowError('Trying to load an object that doesn\'t implement serialization: $.kwargs.prompt -> {"lc":1,"type":"not_implemented","id":["langchain_core","prompts","few_shot","FewShotPromptTemplate"]}');
269
- });
270
- test("serialize + deserialize llm chain few shot prompt w/ selector", async () => {
271
- const llm = new OpenAI({
272
- temperature: 0.5,
273
- modelName: "davinci",
274
- openAIApiKey: "openai-key",
275
- });
276
- const examplePrompt = PromptTemplate.fromTemplate("An example about {yo}");
277
- const prompt = new FewShotPromptTemplate({
278
- exampleSelector: await LengthBasedExampleSelector.fromExamples([{ yo: "1" }, { yo: "2" }], { examplePrompt }),
279
- prefix: "You are a nice assistant",
280
- examplePrompt,
281
- suffix: "My name is {name}",
282
- inputVariables: ["yo", "name"],
283
- });
284
- const chain = new LLMChain({ llm, prompt });
285
- const str = JSON.stringify(chain, null, 2);
286
- expect(stringify(JSON.parse(str))).toMatchSnapshot();
287
- await expect(load(str, {
288
- OPENAI_API_KEY: "openai-key",
289
- })).rejects.toThrow('Trying to load an object that doesn\'t implement serialization: $.kwargs.prompt -> {"lc":1,"type":"not_implemented","id":["langchain_core","prompts","few_shot","FewShotPromptTemplate"]}');
290
- });
291
- test("serialize + deserialize llmchain with list output parser", async () => {
292
- const llm = new OpenAI({
293
- temperature: 0.5,
294
- modelName: "davinci",
295
- openAIApiKey: "openai-key",
296
- callbacks: [new ConsoleCallbackHandler()],
297
- });
298
- const prompt = PromptTemplate.fromTemplate("An example about {yo} {format_instructions}");
299
- const outputParser = new CommaSeparatedListOutputParser();
300
- const chain = new LLMChain({ llm, prompt, outputParser });
301
- const str = JSON.stringify(chain, null, 2);
302
- expect(stringify(JSON.parse(str))).toMatchSnapshot();
303
- const chain2 = await load(str, {
304
- OPENAI_API_KEY: "openai-key",
305
- });
306
- expect(chain2).toBeInstanceOf(LLMChain);
307
- expect(JSON.stringify(chain2, null, 2)).toBe(str);
308
- expect(await chain2.outputParser?.parseResult([{ text: "a, b, c" }])).toEqual(["a", "b", "c"]);
309
- });
310
- test("serialize + deserialize llmchain with regex output parser", async () => {
311
- const llm = new OpenAI({
312
- temperature: 0.5,
313
- modelName: "davinci",
314
- openAIApiKey: "openai-key",
315
- callbacks: [new ConsoleCallbackHandler()],
316
- });
317
- const prompt = PromptTemplate.fromTemplate("An example about {yo} {format_instructions}");
318
- const outputParser = new RegexParser({
319
- regex: /Confidence: (A|B|C), Explanation: (.*)/,
320
- outputKeys: ["confidence", "explanation"],
321
- });
322
- const chain = new LLMChain({ llm, prompt, outputParser });
323
- const str = JSON.stringify(chain, null, 2);
324
- expect(stringify(JSON.parse(str))).toMatchSnapshot();
325
- const chain2 = await load(str, {
326
- OPENAI_API_KEY: "openai-key",
327
- });
328
- expect(chain2).toBeInstanceOf(LLMChain);
329
- expect(JSON.stringify(chain2, null, 2)).toBe(str);
330
- expect(await chain2.outputParser?.parseResult([
331
- {
332
- text: "Confidence: A, Explanation: Because it is the capital of France.",
333
- },
334
- ])).toEqual({
335
- confidence: "A",
336
- explanation: "Because it is the capital of France.",
337
- });
338
- });
339
- test("serialize + deserialize llmchain with struct output parser throws", async () => {
340
- const llm = new OpenAI({
341
- temperature: 0.5,
342
- modelName: "davinci",
343
- openAIApiKey: "openai-key",
344
- callbacks: [new ConsoleCallbackHandler({})],
345
- });
346
- const prompt = PromptTemplate.fromTemplate("An example about {yo} {format_instructions}");
347
- const outputParser = new StructuredOutputParser(z.object({
348
- a: z.string(),
349
- }));
350
- const chain = new LLMChain({ llm, prompt, outputParser });
351
- const str = JSON.stringify(chain, null, 2);
352
- expect(stringify(JSON.parse(str))).toMatchSnapshot();
353
- await expect(load(str, {
354
- OPENAI_API_KEY: "openai-key",
355
- })).rejects.toThrow('Trying to load an object that doesn\'t implement serialization: $.kwargs.output_parser -> {"lc":1,"type":"not_implemented","id":["langchain","output_parsers","structured","StructuredOutputParser"]}');
356
- });
357
- test.skip("serialize + deserialize agent", async () => {
358
- const llm = new ChatOpenAI({
359
- temperature: 0,
360
- modelName: "gpt-4",
361
- openAIApiKey: "openai-key",
362
- });
363
- const executor = await initializeAgentExecutorWithOptions([
364
- new Calculator(),
365
- new RequestsGetTool(),
366
- new JsonListKeysTool(new JsonSpec({ a: "b" })),
367
- ], llm, {
368
- agentType: "chat-conversational-react-description",
369
- });
370
- const str = JSON.stringify(executor, null, 2);
371
- expect(stringify(JSON.parse(str))).toMatchSnapshot();
372
- const executor2 = await load(str, { OPENAI_API_KEY: "openai-key" }, {
373
- "langchain/tools/calculator": { Calculator },
374
- });
375
- expect(executor2).toBeInstanceOf(AgentExecutor);
376
- expect(JSON.stringify(executor2, null, 2)).toBe(str);
377
- });
378
- test("override name of objects when serialising", async () => {
379
- const llm = new OpenAI({ temperature: 0.5, apiKey: "openai-key" });
380
- const str = JSON.stringify(llm, null, 2);
381
- class MangledName extends OpenAI {
382
- }
383
- const llm2 = await load(str, { OPENAI_API_KEY: "openai-key" }, { "langchain/llms/openai": { OpenAI: MangledName } });
384
- expect(JSON.stringify(llm2, null, 2)).toBe(str);
385
- });
386
- test("Should load traces even if the constructor name changes (minified environments)", async () => {
387
- const llm = new OpenAI({ temperature: 0.5, apiKey: "openai-key" });
388
- Object.defineProperty(llm.constructor, "name", {
389
- value: "x",
390
- });
391
- const str = JSON.stringify(llm, null, 2);
392
- console.log(str);
393
- const llm2 = await load(str, { COHERE_API_KEY: "cohere-key" }, { "langchain/llms/openai": { OpenAI } });
394
- console.log(JSON.stringify(llm2, null, 2));
395
- expect(JSON.stringify(llm2, null, 2)).toBe(str);
396
- });
397
- test("Should load a real-world serialized chain", async () => {
398
- const serializedValue = `{"lc": 1, "type": "constructor", "id": ["langchain_core", "runnables", "RunnableSequence"], "kwargs": {"first": {"lc": 1, "type": "constructor", "id": ["langchain_core", "runnables", "RunnableParallel"], "kwargs": {"steps": {"equation_statement": {"lc": 1, "type": "constructor", "id": ["langchain_core", "runnables", "RunnablePassthrough"], "kwargs": {"func": null, "afunc": null, "input_type": null}}}}}, "middle": [{"lc": 1, "type": "constructor", "id": ["langchain_core", "prompts", "chat", "ChatPromptTemplate"], "kwargs": {"input_variables": ["equation_statement"], "messages": [{"lc": 1, "type": "constructor", "id": ["langchain_core", "prompts", "chat", "SystemMessagePromptTemplate"], "kwargs": {"prompt": {"lc": 1, "type": "constructor", "id": ["langchain_core", "prompts", "prompt", "PromptTemplate"], "kwargs": {"input_variables": [], "template": "Write out the following equation using algebraic symbols then solve it. Use the format\\n\\nEQUATION:...\\nSOLUTION:...\\n\\n", "template_format": "f-string", "partial_variables": {}}}}}, {"lc": 1, "type": "constructor", "id": ["langchain_core", "prompts", "chat", "HumanMessagePromptTemplate"], "kwargs": {"prompt": {"lc": 1, "type": "constructor", "id": ["langchain_core", "prompts", "prompt", "PromptTemplate"], "kwargs": {"input_variables": ["equation_statement"], "template": "{equation_statement}", "template_format": "f-string", "partial_variables": {}}}}}]}}, {"lc": 1, "type": "constructor", "id": ["langchain", "chat_models", "openai", "ChatOpenAI"], "kwargs": {"temperature": 0.0, "openai_api_key": {"lc": 1, "type": "secret", "id": ["OPENAI_API_KEY"]}}}], "last": {"lc": 1, "type": "constructor", "id": ["langchain_core", "output_parsers", "string", "StrOutputParser"], "kwargs": {}}}}`;
399
- const chain = await load(serializedValue, {
400
- OPENAI_API_KEY: "openai-key",
401
- });
402
- // @ts-expect-error testing
403
- expect(chain.first.constructor.lc_name()).toBe("RunnableMap");
404
- // @ts-expect-error testing
405
- expect(chain.middle.length).toBe(2);
406
- // @ts-expect-error testing
407
- expect(chain.middle[0].constructor.lc_name()).toBe(`ChatPromptTemplate`);
408
- // @ts-expect-error testing
409
- expect(chain.middle[1].constructor.lc_name()).toBe(`ChatOpenAI`);
410
- // @ts-expect-error testing
411
- expect(chain.last.constructor.lc_name()).toBe(`StrOutputParser`);
412
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,34 +0,0 @@
1
- import { test, expect } from "@jest/globals";
2
- import { HumanMessage, AIMessage } from "@langchain/core/messages";
3
- import { InMemoryChatMessageHistory as ChatMessageHistory } from "@langchain/core/chat_history";
4
- import { BufferMemory } from "../buffer_memory.js";
5
- test("Test buffer memory", async () => {
6
- const memory = new BufferMemory();
7
- const result1 = await memory.loadMemoryVariables({});
8
- expect(result1).toStrictEqual({ history: "" });
9
- await memory.saveContext({ foo: "bar" }, { bar: "foo" });
10
- const expectedString = "Human: bar\nAI: foo";
11
- const result2 = await memory.loadMemoryVariables({});
12
- expect(result2).toStrictEqual({ history: expectedString });
13
- });
14
- test("Test buffer memory return messages", async () => {
15
- const memory = new BufferMemory({ returnMessages: true });
16
- const result1 = await memory.loadMemoryVariables({});
17
- expect(result1).toStrictEqual({ history: [] });
18
- await memory.saveContext({ foo: "bar" }, { bar: "foo" });
19
- const expectedResult = [new HumanMessage("bar"), new AIMessage("foo")];
20
- const result2 = await memory.loadMemoryVariables({});
21
- expect(result2).toStrictEqual({ history: expectedResult });
22
- });
23
- test("Test buffer memory with pre-loaded history", async () => {
24
- const pastMessages = [
25
- new HumanMessage("My name's Jonas"),
26
- new AIMessage("Nice to meet you, Jonas!"),
27
- ];
28
- const memory = new BufferMemory({
29
- returnMessages: true,
30
- chatHistory: new ChatMessageHistory(pastMessages),
31
- });
32
- const result = await memory.loadMemoryVariables({});
33
- expect(result).toStrictEqual({ history: pastMessages });
34
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,47 +0,0 @@
1
- import { test, expect } from "@jest/globals";
2
- import { OpenAI } from "@langchain/openai";
3
- import { HumanMessage, AIMessage } from "@langchain/core/messages";
4
- import { InMemoryChatMessageHistory as ChatMessageHistory } from "@langchain/core/chat_history";
5
- import { ConversationTokenBufferMemory } from "../buffer_token_memory.js";
6
- test("Test buffer token memory with LLM", async () => {
7
- const memory = new ConversationTokenBufferMemory({
8
- llm: new OpenAI(),
9
- maxTokenLimit: 10,
10
- });
11
- const result1 = await memory.loadMemoryVariables({});
12
- expect(result1).toStrictEqual({ history: "" });
13
- await memory.saveContext({ input: "foo" }, { output: "bar" });
14
- const expectedString = "Human: foo\nAI: bar";
15
- const result2 = await memory.loadMemoryVariables({});
16
- expect(result2).toStrictEqual({ history: expectedString });
17
- await memory.saveContext({ foo: "foo" }, { bar: "bar" });
18
- await memory.saveContext({ foo: "bar" }, { bar: "foo" });
19
- const expectedString3 = "Human: bar\nAI: foo";
20
- const result3 = await memory.loadMemoryVariables({});
21
- expect(result3).toStrictEqual({ history: expectedString3 });
22
- });
23
- test("Test buffer token memory return messages", async () => {
24
- const memory = new ConversationTokenBufferMemory({
25
- llm: new OpenAI(),
26
- returnMessages: true,
27
- });
28
- const result1 = await memory.loadMemoryVariables({});
29
- expect(result1).toStrictEqual({ history: [] });
30
- await memory.saveContext({ foo: "bar" }, { bar: "foo" });
31
- const expectedResult = [new HumanMessage("bar"), new AIMessage("foo")];
32
- const result2 = await memory.loadMemoryVariables({});
33
- expect(result2).toStrictEqual({ history: expectedResult });
34
- });
35
- test("Test buffer token memory with pre-loaded history", async () => {
36
- const pastMessages = [
37
- new HumanMessage("My name's Jonas"),
38
- new AIMessage("Nice to meet you, Jonas!"),
39
- ];
40
- const memory = new ConversationTokenBufferMemory({
41
- llm: new OpenAI(),
42
- returnMessages: true,
43
- chatHistory: new ChatMessageHistory(pastMessages),
44
- });
45
- const result = await memory.loadMemoryVariables({});
46
- expect(result).toStrictEqual({ history: pastMessages });
47
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,42 +0,0 @@
1
- import { test, expect } from "@jest/globals";
2
- import { HumanMessage, AIMessage } from "@langchain/core/messages";
3
- import { InMemoryChatMessageHistory as ChatMessageHistory } from "@langchain/core/chat_history";
4
- import { BufferWindowMemory } from "../buffer_window_memory.js";
5
- test("Test buffer window memory", async () => {
6
- const memory = new BufferWindowMemory({ k: 1 });
7
- const result1 = await memory.loadMemoryVariables({});
8
- expect(result1).toStrictEqual({ history: "" });
9
- await memory.saveContext({ foo: "bar" }, { bar: "foo" });
10
- const expectedString = "Human: bar\nAI: foo";
11
- const result2 = await memory.loadMemoryVariables({});
12
- expect(result2).toStrictEqual({ history: expectedString });
13
- await memory.saveContext({ foo: "bar1" }, { bar: "foo" });
14
- const expectedString3 = "Human: bar1\nAI: foo";
15
- const result3 = await memory.loadMemoryVariables({});
16
- expect(result3).toStrictEqual({ history: expectedString3 });
17
- });
18
- test("Test buffer window memory return messages", async () => {
19
- const memory = new BufferWindowMemory({ k: 1, returnMessages: true });
20
- const result1 = await memory.loadMemoryVariables({});
21
- expect(result1).toStrictEqual({ history: [] });
22
- await memory.saveContext({ foo: "bar" }, { bar: "foo" });
23
- const expectedResult = [new HumanMessage("bar"), new AIMessage("foo")];
24
- const result2 = await memory.loadMemoryVariables({});
25
- expect(result2).toStrictEqual({ history: expectedResult });
26
- await memory.saveContext({ foo: "bar1" }, { bar: "foo" });
27
- const expectedResult2 = [new HumanMessage("bar1"), new AIMessage("foo")];
28
- const result3 = await memory.loadMemoryVariables({});
29
- expect(result3).toStrictEqual({ history: expectedResult2 });
30
- });
31
- test("Test buffer window memory with pre-loaded history", async () => {
32
- const pastMessages = [
33
- new HumanMessage("My name's Jonas"),
34
- new AIMessage("Nice to meet you, Jonas!"),
35
- ];
36
- const memory = new BufferWindowMemory({
37
- returnMessages: true,
38
- chatHistory: new ChatMessageHistory(pastMessages),
39
- });
40
- const result = await memory.loadMemoryVariables({});
41
- expect(result).toStrictEqual({ history: pastMessages });
42
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,74 +0,0 @@
1
- import { test, expect } from "@jest/globals";
2
- import { AIMessage, HumanMessage, SystemMessage, } from "@langchain/core/messages";
3
- import { OpenAI } from "@langchain/openai";
4
- import { BufferMemory } from "../buffer_memory.js";
5
- import { CombinedMemory } from "../combined_memory.js";
6
- import { ConversationSummaryMemory } from "../summary.js";
7
- test("Test combined memory", async () => {
8
- // buffer memory
9
- const bufferMemory = new BufferMemory({
10
- memoryKey: "chat_history_lines",
11
- inputKey: "input",
12
- });
13
- // summary memory
14
- const conversationSummaryMemory = new ConversationSummaryMemory({
15
- llm: new OpenAI({
16
- modelName: "gpt-3.5-turbo",
17
- temperature: 0,
18
- verbose: true,
19
- }),
20
- inputKey: "input",
21
- });
22
- const memory = new CombinedMemory({
23
- memories: [bufferMemory, conversationSummaryMemory],
24
- });
25
- const result1 = await memory.loadMemoryVariables({});
26
- expect(result1).toStrictEqual({ chat_history_lines: "", history: "" });
27
- await memory.saveContext({ input: "bar" }, { output: "foo" });
28
- const expectedString = "Human: bar\nAI: foo";
29
- const result2 = await memory.loadMemoryVariables({});
30
- console.log("result2", result2);
31
- expect(result2.chat_history_lines).toStrictEqual(expectedString);
32
- await memory.clear();
33
- expect(await memory.loadMemoryVariables({})).toEqual({
34
- chat_history_lines: "",
35
- history: "",
36
- });
37
- });
38
- test("Test combined memory return messages", async () => {
39
- // buffer memory
40
- const conv_memory = new BufferMemory({
41
- memoryKey: "chat_history_lines",
42
- inputKey: "input",
43
- returnMessages: true,
44
- });
45
- // summary memory
46
- const summary_memory = new ConversationSummaryMemory({
47
- llm: new OpenAI({
48
- modelName: "gpt-3.5-turbo",
49
- temperature: 0,
50
- verbose: true,
51
- }),
52
- inputKey: "input",
53
- returnMessages: true,
54
- });
55
- const memory = new CombinedMemory({
56
- memories: [conv_memory, summary_memory],
57
- });
58
- const result1 = await memory.loadMemoryVariables({});
59
- console.log("result1", result1);
60
- expect(result1).toStrictEqual({
61
- chat_history_lines: [],
62
- history: [new SystemMessage("")],
63
- });
64
- await memory.saveContext({ input: "bar" }, { output: "foo" });
65
- const expectedResult = [new HumanMessage("bar"), new AIMessage("foo")];
66
- const result2 = await memory.loadMemoryVariables({});
67
- console.log("result2", result2);
68
- expect(result2.chat_history_lines).toStrictEqual(expectedResult);
69
- await memory.clear();
70
- expect(await memory.loadMemoryVariables({})).toEqual({
71
- chat_history_lines: [],
72
- history: [new SystemMessage("")],
73
- });
74
- });
@@ -1 +0,0 @@
1
- export {};