langchain 0.2.2 → 0.2.3-rc.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 (329) hide show
  1. package/dist/agents/tests/agent.int.test.d.ts +1 -0
  2. package/dist/agents/tests/agent.int.test.js +309 -0
  3. package/dist/agents/tests/chat_convo_output_parser.test.d.ts +1 -0
  4. package/dist/agents/tests/chat_convo_output_parser.test.js +91 -0
  5. package/dist/agents/tests/create_openai_functions_agent.int.test.d.ts +2 -0
  6. package/dist/agents/tests/create_openai_functions_agent.int.test.js +71 -0
  7. package/dist/agents/tests/create_openai_tools_agent.int.test.d.ts +1 -0
  8. package/dist/agents/tests/create_openai_tools_agent.int.test.js +75 -0
  9. package/dist/agents/tests/create_react_agent.int.test.d.ts +1 -0
  10. package/dist/agents/tests/create_react_agent.int.test.js +32 -0
  11. package/dist/agents/tests/create_structured_chat_agent.int.test.d.ts +1 -0
  12. package/dist/agents/tests/create_structured_chat_agent.int.test.js +32 -0
  13. package/dist/agents/tests/create_tool_calling_agent.int.test.d.ts +1 -0
  14. package/dist/agents/tests/create_tool_calling_agent.int.test.js +71 -0
  15. package/dist/agents/tests/create_xml_agent.int.test.d.ts +1 -0
  16. package/dist/agents/tests/create_xml_agent.int.test.js +32 -0
  17. package/dist/agents/tests/json.test.d.ts +1 -0
  18. package/dist/agents/tests/json.test.js +74 -0
  19. package/dist/agents/tests/react.test.d.ts +1 -0
  20. package/dist/agents/tests/react.test.js +44 -0
  21. package/dist/agents/tests/runnable.int.test.d.ts +1 -0
  22. package/dist/agents/tests/runnable.int.test.js +104 -0
  23. package/dist/agents/tests/sql.test.d.ts +1 -0
  24. package/dist/agents/tests/sql.test.js +133 -0
  25. package/dist/agents/tests/structured_chat_output_parser.test.d.ts +1 -0
  26. package/dist/agents/tests/structured_chat_output_parser.test.js +35 -0
  27. package/dist/agents/tests/structured_chat_output_parser_with_retries.int.test.d.ts +1 -0
  28. package/dist/agents/tests/structured_chat_output_parser_with_retries.int.test.js +44 -0
  29. package/dist/agents/tests/structured_output_runnables.int.test.d.ts +1 -0
  30. package/dist/agents/tests/structured_output_runnables.int.test.js +112 -0
  31. package/dist/agents/toolkits/tests/conversational_retrieval.int.test.d.ts +1 -0
  32. package/dist/agents/toolkits/tests/conversational_retrieval.int.test.js +41 -0
  33. package/dist/cache/tests/file_system.int.test.d.ts +1 -0
  34. package/dist/cache/tests/file_system.int.test.js +32 -0
  35. package/dist/chains/openai_functions/tests/create_runnable_chains.int.test.d.ts +1 -0
  36. package/dist/chains/openai_functions/tests/create_runnable_chains.int.test.js +139 -0
  37. package/dist/chains/openai_functions/tests/extraction.int.test.d.ts +1 -0
  38. package/dist/chains/openai_functions/tests/extraction.int.test.js +33 -0
  39. package/dist/chains/openai_functions/tests/openapi.int.test.d.ts +1 -0
  40. package/dist/chains/openai_functions/tests/openapi.int.test.js +130 -0
  41. package/dist/chains/openai_functions/tests/openapi.test.d.ts +1 -0
  42. package/dist/chains/openai_functions/tests/openapi.test.js +172 -0
  43. package/dist/chains/openai_functions/tests/structured_output.int.test.d.ts +1 -0
  44. package/dist/chains/openai_functions/tests/structured_output.int.test.js +40 -0
  45. package/dist/chains/openai_functions/tests/structured_output.test.d.ts +1 -0
  46. package/dist/chains/openai_functions/tests/structured_output.test.js +102 -0
  47. package/dist/chains/openai_functions/tests/tagging.int.test.d.ts +1 -0
  48. package/dist/chains/openai_functions/tests/tagging.int.test.js +21 -0
  49. package/dist/chains/query_constructor/tests/query_chain.int.test.d.ts +1 -0
  50. package/dist/chains/query_constructor/tests/query_chain.int.test.js +93 -0
  51. package/dist/chains/query_constructor/tests/query_parser.test.d.ts +1 -0
  52. package/dist/chains/query_constructor/tests/query_parser.test.js +28 -0
  53. package/dist/chains/question_answering/tests/load.int.test.d.ts +1 -0
  54. package/dist/chains/question_answering/tests/load.int.test.js +39 -0
  55. package/dist/chains/router/tests/multi_prompt.int.test.d.ts +1 -0
  56. package/dist/chains/router/tests/multi_prompt.int.test.js +45 -0
  57. package/dist/chains/router/tests/multi_prompt.test.d.ts +1 -0
  58. package/dist/chains/router/tests/multi_prompt.test.js +62 -0
  59. package/dist/chains/router/tests/multi_retrieval_qa.int.test.d.ts +1 -0
  60. package/dist/chains/router/tests/multi_retrieval_qa.int.test.js +67 -0
  61. package/dist/chains/router/tests/multi_retrieval_qa.test.d.ts +1 -0
  62. package/dist/chains/router/tests/multi_retrieval_qa.test.js +125 -0
  63. package/dist/chains/summarization/tests/load.int.test.d.ts +1 -0
  64. package/dist/chains/summarization/tests/load.int.test.js +37 -0
  65. package/dist/chains/tests/api_chain.int.test.d.ts +1 -0
  66. package/dist/chains/tests/api_chain.int.test.js +55 -0
  67. package/dist/chains/tests/combine_docs_chain.int.test.d.ts +1 -0
  68. package/dist/chains/tests/combine_docs_chain.int.test.js +50 -0
  69. package/dist/chains/tests/combine_docs_chain.test.d.ts +1 -0
  70. package/dist/chains/tests/combine_docs_chain.test.js +98 -0
  71. package/dist/chains/tests/constitutional_chain.int.test.d.ts +1 -0
  72. package/dist/chains/tests/constitutional_chain.int.test.js +30 -0
  73. package/dist/chains/tests/constitutional_chain.test.d.ts +1 -0
  74. package/dist/chains/tests/constitutional_chain.test.js +63 -0
  75. package/dist/chains/tests/conversation_chain.int.test.d.ts +1 -0
  76. package/dist/chains/tests/conversation_chain.int.test.js +9 -0
  77. package/dist/chains/tests/conversational_retrieval_chain.int.test.d.ts +1 -0
  78. package/dist/chains/tests/conversational_retrieval_chain.int.test.js +243 -0
  79. package/dist/chains/tests/example_data/open_meteo_docs.d.ts +1 -0
  80. package/dist/chains/tests/example_data/open_meteo_docs.js +29 -0
  81. package/dist/chains/tests/history_aware_retriever.int.test.d.ts +1 -0
  82. package/dist/chains/tests/history_aware_retriever.int.test.js +41 -0
  83. package/dist/chains/tests/history_aware_retriever.test.d.ts +1 -0
  84. package/dist/chains/tests/history_aware_retriever.test.js +27 -0
  85. package/dist/chains/tests/llm_chain.int.test.d.ts +1 -0
  86. package/dist/chains/tests/llm_chain.int.test.js +119 -0
  87. package/dist/chains/tests/openai_moderation.int.test.d.ts +1 -0
  88. package/dist/chains/tests/openai_moderation.int.test.js +30 -0
  89. package/dist/chains/tests/retrieval_chain.int.test.d.ts +1 -0
  90. package/dist/chains/tests/retrieval_chain.int.test.js +69 -0
  91. package/dist/chains/tests/retrieval_chain.test.d.ts +1 -0
  92. package/dist/chains/tests/retrieval_chain.test.js +36 -0
  93. package/dist/chains/tests/sequential_chain.int.test.d.ts +1 -0
  94. package/dist/chains/tests/sequential_chain.int.test.js +88 -0
  95. package/dist/chains/tests/sequential_chain.test.d.ts +1 -0
  96. package/dist/chains/tests/sequential_chain.test.js +295 -0
  97. package/dist/chains/tests/simple_sequential_chain.int.test.d.ts +1 -0
  98. package/dist/chains/tests/simple_sequential_chain.int.test.js +81 -0
  99. package/dist/chains/tests/simple_sequential_chain.test.d.ts +1 -0
  100. package/dist/chains/tests/simple_sequential_chain.test.js +128 -0
  101. package/dist/chains/tests/sql_db_chain.int.test.d.ts +1 -0
  102. package/dist/chains/tests/sql_db_chain.int.test.js +125 -0
  103. package/dist/chains/tests/transform.test.d.ts +1 -0
  104. package/dist/chains/tests/transform.test.js +12 -0
  105. package/dist/chains/tests/vector_db_qa_chain.int.test.d.ts +1 -0
  106. package/dist/chains/tests/vector_db_qa_chain.int.test.js +45 -0
  107. package/dist/document_loaders/tests/assemblyai.int.test.d.ts +1 -0
  108. package/dist/document_loaders/tests/assemblyai.int.test.js +111 -0
  109. package/dist/document_loaders/tests/chatgpt-blob.test.d.ts +1 -0
  110. package/dist/document_loaders/tests/chatgpt-blob.test.js +30 -0
  111. package/dist/document_loaders/tests/chatgpt.test.d.ts +1 -0
  112. package/dist/document_loaders/tests/chatgpt.test.js +29 -0
  113. package/dist/document_loaders/tests/cheerio.int.test.d.ts +1 -0
  114. package/dist/document_loaders/tests/cheerio.int.test.js +21 -0
  115. package/dist/document_loaders/tests/college_confidential.int.test.d.ts +1 -0
  116. package/dist/document_loaders/tests/college_confidential.int.test.js +6 -0
  117. package/dist/document_loaders/tests/confluence.test.d.ts +1 -0
  118. package/dist/document_loaders/tests/confluence.test.js +52 -0
  119. package/dist/document_loaders/tests/couchbase.int.test.d.ts +1 -0
  120. package/dist/document_loaders/tests/couchbase.int.test.js +28 -0
  121. package/dist/document_loaders/tests/csv-blob.test.d.ts +1 -0
  122. package/dist/document_loaders/tests/csv-blob.test.js +51 -0
  123. package/dist/document_loaders/tests/csv.test.d.ts +1 -0
  124. package/dist/document_loaders/tests/csv.test.js +41 -0
  125. package/dist/document_loaders/tests/directory.test.d.ts +1 -0
  126. package/dist/document_loaders/tests/directory.test.js +38 -0
  127. package/dist/document_loaders/tests/docx.test.d.ts +1 -0
  128. package/dist/document_loaders/tests/docx.test.js +11 -0
  129. package/dist/document_loaders/tests/epub.test.d.ts +1 -0
  130. package/dist/document_loaders/tests/epub.test.js +18 -0
  131. package/dist/document_loaders/tests/example_data/github_api_responses.d.ts +5 -0
  132. package/dist/document_loaders/tests/example_data/github_api_responses.js +91 -0
  133. package/dist/document_loaders/tests/figma.int.test.d.ts +1 -0
  134. package/dist/document_loaders/tests/figma.int.test.js +13 -0
  135. package/dist/document_loaders/tests/firecrawl.int.test.d.ts +1 -0
  136. package/dist/document_loaders/tests/firecrawl.int.test.js +30 -0
  137. package/dist/document_loaders/tests/gitbook.int.test.d.ts +1 -0
  138. package/dist/document_loaders/tests/gitbook.int.test.js +14 -0
  139. package/dist/document_loaders/tests/github.int.test.d.ts +1 -0
  140. package/dist/document_loaders/tests/github.int.test.js +86 -0
  141. package/dist/document_loaders/tests/github.test.d.ts +1 -0
  142. package/dist/document_loaders/tests/github.test.js +51 -0
  143. package/dist/document_loaders/tests/hn.int.test.d.ts +1 -0
  144. package/dist/document_loaders/tests/hn.int.test.js +6 -0
  145. package/dist/document_loaders/tests/imsdb.test.d.ts +1 -0
  146. package/dist/document_loaders/tests/imsdb.test.js +6 -0
  147. package/dist/document_loaders/tests/json-blob.test.d.ts +1 -0
  148. package/dist/document_loaders/tests/json-blob.test.js +87 -0
  149. package/dist/document_loaders/tests/json.test.d.ts +1 -0
  150. package/dist/document_loaders/tests/json.test.js +69 -0
  151. package/dist/document_loaders/tests/jsonl-blob.test.d.ts +1 -0
  152. package/dist/document_loaders/tests/jsonl-blob.test.js +44 -0
  153. package/dist/document_loaders/tests/jsonl.test.d.ts +1 -0
  154. package/dist/document_loaders/tests/jsonl.test.js +15 -0
  155. package/dist/document_loaders/tests/notion.test.d.ts +1 -0
  156. package/dist/document_loaders/tests/notion.test.js +11 -0
  157. package/dist/document_loaders/tests/notionapi.int.test.d.ts +1 -0
  158. package/dist/document_loaders/tests/notionapi.int.test.js +80 -0
  159. package/dist/document_loaders/tests/notionapi.test.d.ts +1 -0
  160. package/dist/document_loaders/tests/notionapi.test.js +84 -0
  161. package/dist/document_loaders/tests/notiondb.int.test.d.ts +1 -0
  162. package/dist/document_loaders/tests/notiondb.int.test.js +13 -0
  163. package/dist/document_loaders/tests/obsidian.test.d.ts +1 -0
  164. package/dist/document_loaders/tests/obsidian.test.js +119 -0
  165. package/dist/document_loaders/tests/pdf-blob.test.d.ts +1 -0
  166. package/dist/document_loaders/tests/pdf-blob.test.js +44 -0
  167. package/dist/document_loaders/tests/pdf.test.d.ts +1 -0
  168. package/dist/document_loaders/tests/pdf.test.js +25 -0
  169. package/dist/document_loaders/tests/playwright_web.int.test.d.ts +1 -0
  170. package/dist/document_loaders/tests/playwright_web.int.test.js +27 -0
  171. package/dist/document_loaders/tests/pptx.test.d.ts +1 -0
  172. package/dist/document_loaders/tests/pptx.test.js +17 -0
  173. package/dist/document_loaders/tests/puppeteer.int.test.d.ts +1 -0
  174. package/dist/document_loaders/tests/puppeteer.int.test.js +47 -0
  175. package/dist/document_loaders/tests/recursive_url.int.test.d.ts +1 -0
  176. package/dist/document_loaders/tests/recursive_url.int.test.js +64 -0
  177. package/dist/document_loaders/tests/s3.int.test.d.ts +1 -0
  178. package/dist/document_loaders/tests/s3.int.test.js +48 -0
  179. package/dist/document_loaders/tests/searchapi.test.d.ts +1 -0
  180. package/dist/document_loaders/tests/searchapi.test.js +29 -0
  181. package/dist/document_loaders/tests/serpapi.test.d.ts +1 -0
  182. package/dist/document_loaders/tests/serpapi.test.js +21 -0
  183. package/dist/document_loaders/tests/sitemap.int.test.d.ts +1 -0
  184. package/dist/document_loaders/tests/sitemap.int.test.js +28 -0
  185. package/dist/document_loaders/tests/sonix_audio.int.test.d.ts +1 -0
  186. package/dist/document_loaders/tests/sonix_audio.int.test.js +55 -0
  187. package/dist/document_loaders/tests/sort_xyz_blockchain.int.test.d.ts +1 -0
  188. package/dist/document_loaders/tests/sort_xyz_blockchain.int.test.js +38 -0
  189. package/dist/document_loaders/tests/srt-blob.test.d.ts +1 -0
  190. package/dist/document_loaders/tests/srt-blob.test.js +18 -0
  191. package/dist/document_loaders/tests/srt.test.d.ts +1 -0
  192. package/dist/document_loaders/tests/srt.test.js +16 -0
  193. package/dist/document_loaders/tests/text-blob.test.d.ts +1 -0
  194. package/dist/document_loaders/tests/text-blob.test.js +14 -0
  195. package/dist/document_loaders/tests/text.test.d.ts +1 -0
  196. package/dist/document_loaders/tests/text.test.js +22 -0
  197. package/dist/document_loaders/tests/unstructured.int.test.d.ts +1 -0
  198. package/dist/document_loaders/tests/unstructured.int.test.js +40 -0
  199. package/dist/document_loaders/tests/webpdf.int.test.d.ts +1 -0
  200. package/dist/document_loaders/tests/webpdf.int.test.js +90 -0
  201. package/dist/document_transformers/tests/openai_functions.int.test.d.ts +1 -0
  202. package/dist/document_transformers/tests/openai_functions.int.test.js +40 -0
  203. package/dist/embeddings/tests/cache.test.d.ts +1 -0
  204. package/dist/embeddings/tests/cache.test.js +24 -0
  205. package/dist/embeddings/tests/fake.test.d.ts +1 -0
  206. package/dist/embeddings/tests/fake.test.js +34 -0
  207. package/dist/evaluation/agents/tests/trajectory_eval_chain.int.test.d.ts +1 -0
  208. package/dist/evaluation/agents/tests/trajectory_eval_chain.int.test.js +33 -0
  209. package/dist/evaluation/comparison/tests/pairwise_eval_chain.int.test.d.ts +1 -0
  210. package/dist/evaluation/comparison/tests/pairwise_eval_chain.int.test.js +46 -0
  211. package/dist/evaluation/criteria/tests/criteria_eval_chain.int.test.d.ts +1 -0
  212. package/dist/evaluation/criteria/tests/criteria_eval_chain.int.test.js +108 -0
  213. package/dist/evaluation/embedding_distance/tests/embedding_distance_eval_chain.int.test.d.ts +1 -0
  214. package/dist/evaluation/embedding_distance/tests/embedding_distance_eval_chain.int.test.js +26 -0
  215. package/dist/evaluation/qa/tests/eval_chain.int.test.d.ts +1 -0
  216. package/dist/evaluation/qa/tests/eval_chain.int.test.js +27 -0
  217. package/dist/experimental/autogpt/tests/output_parser.test.d.ts +1 -0
  218. package/dist/experimental/autogpt/tests/output_parser.test.js +8 -0
  219. package/dist/experimental/autogpt/tests/prompt.test.d.ts +1 -0
  220. package/dist/experimental/autogpt/tests/prompt.test.js +69 -0
  221. package/dist/experimental/autogpt/tests/prompt_generator.test.d.ts +1 -0
  222. package/dist/experimental/autogpt/tests/prompt_generator.test.js +91 -0
  223. package/dist/experimental/chains/tests/violation_of_expectations_chain.int.test.d.ts +1 -0
  224. package/dist/experimental/chains/tests/violation_of_expectations_chain.int.test.js +26 -0
  225. package/dist/experimental/generative_agents/tests/generative_agent.int.test.d.ts +1 -0
  226. package/dist/experimental/generative_agents/tests/generative_agent.int.test.js +304 -0
  227. package/dist/experimental/masking/tests/masking-extended.test.d.ts +1 -0
  228. package/dist/experimental/masking/tests/masking-extended.test.js +58 -0
  229. package/dist/experimental/masking/tests/masking.test.d.ts +1 -0
  230. package/dist/experimental/masking/tests/masking.test.js +388 -0
  231. package/dist/experimental/openai_assistant/tests/openai_assistant.int.test.d.ts +1 -0
  232. package/dist/experimental/openai_assistant/tests/openai_assistant.int.test.js +203 -0
  233. package/dist/experimental/openai_files/tests/openai_file.int.test.d.ts +1 -0
  234. package/dist/experimental/openai_files/tests/openai_file.int.test.js +87 -0
  235. package/dist/experimental/plan_and_execute/tests/plan_and_execute.int.test.d.ts +1 -0
  236. package/dist/experimental/plan_and_execute/tests/plan_and_execute.int.test.js +54 -0
  237. package/dist/experimental/prompts/tests/handlebars.test.d.ts +1 -0
  238. package/dist/experimental/prompts/tests/handlebars.test.js +24 -0
  239. package/dist/experimental/tools/tests/pyinterpreter.int.test.d.ts +1 -0
  240. package/dist/experimental/tools/tests/pyinterpreter.int.test.js +22 -0
  241. package/dist/load/import_map.cjs +1 -1
  242. package/dist/load/import_map.js +1 -1
  243. package/dist/load/tests/cross_language.test.d.ts +1 -0
  244. package/dist/load/tests/cross_language.test.js +83 -0
  245. package/dist/load/tests/load.int.test.d.ts +1 -0
  246. package/dist/load/tests/load.int.test.js +9 -0
  247. package/dist/load/tests/load.test.d.ts +1 -0
  248. package/dist/load/tests/load.test.js +412 -0
  249. package/dist/memory/tests/buffer_memory.test.d.ts +1 -0
  250. package/dist/memory/tests/buffer_memory.test.js +34 -0
  251. package/dist/memory/tests/buffer_token_memory.int.test.d.ts +1 -0
  252. package/dist/memory/tests/buffer_token_memory.int.test.js +47 -0
  253. package/dist/memory/tests/buffer_window_memory.test.d.ts +1 -0
  254. package/dist/memory/tests/buffer_window_memory.test.js +42 -0
  255. package/dist/memory/tests/combined_memory.int.test.d.ts +1 -0
  256. package/dist/memory/tests/combined_memory.int.test.js +74 -0
  257. package/dist/memory/tests/entity_memory.int.test.d.ts +1 -0
  258. package/dist/memory/tests/entity_memory.int.test.js +79 -0
  259. package/dist/memory/tests/entity_memory.test.d.ts +1 -0
  260. package/dist/memory/tests/entity_memory.test.js +48 -0
  261. package/dist/memory/tests/summary.int.test.d.ts +1 -0
  262. package/dist/memory/tests/summary.int.test.js +50 -0
  263. package/dist/memory/tests/summary_buffer.int.test.d.ts +1 -0
  264. package/dist/memory/tests/summary_buffer.int.test.js +55 -0
  265. package/dist/memory/tests/vector_store_memory.int.test.d.ts +1 -0
  266. package/dist/memory/tests/vector_store_memory.int.test.js +55 -0
  267. package/dist/output_parsers/tests/combining.int.test.d.ts +1 -0
  268. package/dist/output_parsers/tests/combining.int.test.js +26 -0
  269. package/dist/output_parsers/tests/combining.test.d.ts +1 -0
  270. package/dist/output_parsers/tests/combining.test.js +54 -0
  271. package/dist/output_parsers/tests/datetime.test.d.ts +1 -0
  272. package/dist/output_parsers/tests/datetime.test.js +14 -0
  273. package/dist/output_parsers/tests/expression.test.d.ts +1 -0
  274. package/dist/output_parsers/tests/expression.test.js +339 -0
  275. package/dist/output_parsers/tests/http_response.test.d.ts +1 -0
  276. package/dist/output_parsers/tests/http_response.test.js +39 -0
  277. package/dist/output_parsers/tests/list.test.d.ts +1 -0
  278. package/dist/output_parsers/tests/list.test.js +27 -0
  279. package/dist/output_parsers/tests/openai_functions.int.test.d.ts +1 -0
  280. package/dist/output_parsers/tests/openai_functions.int.test.js +89 -0
  281. package/dist/output_parsers/tests/openai_tools.int.test.d.ts +1 -0
  282. package/dist/output_parsers/tests/openai_tools.int.test.js +36 -0
  283. package/dist/output_parsers/tests/structured.int.test.d.ts +1 -0
  284. package/dist/output_parsers/tests/structured.int.test.js +150 -0
  285. package/dist/prompts/tests/selectors.test.d.ts +1 -0
  286. package/dist/prompts/tests/selectors.test.js +59 -0
  287. package/dist/retrievers/self_query/tests/memory_self_query.int.test.d.ts +1 -0
  288. package/dist/retrievers/self_query/tests/memory_self_query.int.test.js +330 -0
  289. package/dist/retrievers/tests/chain_extract.int.test.d.ts +1 -0
  290. package/dist/retrievers/tests/chain_extract.int.test.js +32 -0
  291. package/dist/retrievers/tests/hyde.int.test.d.ts +1 -0
  292. package/dist/retrievers/tests/hyde.int.test.js +44 -0
  293. package/dist/retrievers/tests/matryoshka_retriever.int.test.d.ts +1 -0
  294. package/dist/retrievers/tests/matryoshka_retriever.int.test.js +113 -0
  295. package/dist/retrievers/tests/multi_query.int.test.d.ts +1 -0
  296. package/dist/retrievers/tests/multi_query.int.test.js +45 -0
  297. package/dist/retrievers/tests/parent_document.int.test.d.ts +1 -0
  298. package/dist/retrievers/tests/parent_document.int.test.js +122 -0
  299. package/dist/retrievers/tests/score_threshold.int.test.d.ts +1 -0
  300. package/dist/retrievers/tests/score_threshold.int.test.js +83 -0
  301. package/dist/retrievers/tests/time_weighted.test.d.ts +1 -0
  302. package/dist/retrievers/tests/time_weighted.test.js +320 -0
  303. package/dist/retrievers/tests/vectorstores.test.d.ts +1 -0
  304. package/dist/retrievers/tests/vectorstores.test.js +50 -0
  305. package/dist/smith/tests/run_on_dataset.int.test.d.ts +1 -0
  306. package/dist/smith/tests/run_on_dataset.int.test.js +257 -0
  307. package/dist/smith/tests/runner_utils.int.test.d.ts +9 -0
  308. package/dist/smith/tests/runner_utils.int.test.js +234 -0
  309. package/dist/storage/tests/file_system.test.d.ts +1 -0
  310. package/dist/storage/tests/file_system.test.js +81 -0
  311. package/dist/tools/tests/chain.test.d.ts +1 -0
  312. package/dist/tools/tests/chain.test.js +136 -0
  313. package/dist/tools/tests/webbrowser.int.test.d.ts +1 -0
  314. package/dist/tools/tests/webbrowser.int.test.js +80 -0
  315. package/dist/tools/tests/webbrowser.test.d.ts +1 -0
  316. package/dist/tools/tests/webbrowser.test.js +21 -0
  317. package/dist/util/tests/async_caller.int.test.d.ts +1 -0
  318. package/dist/util/tests/async_caller.int.test.js +34 -0
  319. package/dist/util/tests/azure.test.d.ts +1 -0
  320. package/dist/util/tests/azure.test.js +42 -0
  321. package/dist/util/tests/openai-stream.test.d.ts +1 -0
  322. package/dist/util/tests/openai-stream.test.js +135 -0
  323. package/dist/util/tests/set.test.d.ts +1 -0
  324. package/dist/util/tests/set.test.js +36 -0
  325. package/dist/util/tests/sql_utils.test.d.ts +1 -0
  326. package/dist/util/tests/sql_utils.test.js +50 -0
  327. package/dist/vectorstores/tests/memory.test.d.ts +1 -0
  328. package/dist/vectorstores/tests/memory.test.js +78 -0
  329. package/package.json +5 -4
@@ -0,0 +1,71 @@
1
+ import { test, expect } from "@jest/globals";
2
+ import { ChatOpenAI } from "@langchain/openai";
3
+ import { ChatPromptTemplate } from "@langchain/core/prompts";
4
+ import { TavilySearchResults } from "../../util/testing/tools/tavily_search.js";
5
+ import { AgentExecutor, createToolCallingAgent } from "../index.js";
6
+ const tools = [new TavilySearchResults({ maxResults: 1 })];
7
+ test("createToolCallingAgent works", async () => {
8
+ const prompt = ChatPromptTemplate.fromMessages([
9
+ ["system", "You are a helpful assistant"],
10
+ ["placeholder", "{chat_history}"],
11
+ ["human", "{input}"],
12
+ ["placeholder", "{agent_scratchpad}"],
13
+ ]);
14
+ const llm = new ChatOpenAI({
15
+ modelName: "gpt-4-turbo",
16
+ temperature: 0,
17
+ });
18
+ const agent = await createToolCallingAgent({
19
+ llm,
20
+ tools,
21
+ prompt,
22
+ });
23
+ const agentExecutor = new AgentExecutor({
24
+ agent,
25
+ tools,
26
+ });
27
+ const input = "what is the current weather in SF?";
28
+ const result = await agentExecutor.invoke({
29
+ input,
30
+ });
31
+ console.log(result);
32
+ expect(result.input).toBe(input);
33
+ expect(typeof result.output).toBe("string");
34
+ // Length greater than 10 because any less than that would warrant
35
+ // an investigation into why such a short generation was returned.
36
+ expect(result.output.length).toBeGreaterThan(10);
37
+ });
38
+ test("createToolCallingAgent stream events works", async () => {
39
+ const prompt = ChatPromptTemplate.fromMessages([
40
+ ["system", "You are a helpful assistant"],
41
+ ["placeholder", "{chat_history}"],
42
+ ["human", "{input}"],
43
+ ["placeholder", "{agent_scratchpad}"],
44
+ ]);
45
+ const llm = new ChatOpenAI({
46
+ modelName: "gpt-4o",
47
+ temperature: 0,
48
+ });
49
+ const agent = await createToolCallingAgent({
50
+ llm,
51
+ tools,
52
+ prompt,
53
+ });
54
+ const agentExecutor = new AgentExecutor({
55
+ agent,
56
+ tools,
57
+ });
58
+ const input = "what is the current weather in SF?";
59
+ const eventStream = agentExecutor.streamEvents({
60
+ input,
61
+ }, {
62
+ version: "v2",
63
+ });
64
+ for await (const event of eventStream) {
65
+ const eventType = event.event;
66
+ console.log("Event type: ", eventType);
67
+ if (eventType === "on_chat_model_stream") {
68
+ console.log("Content: ", event.data);
69
+ }
70
+ }
71
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ import { test, expect } from "@jest/globals";
2
+ import { ChatOpenAI } from "@langchain/openai";
3
+ import { TavilySearchResults } from "../../util/testing/tools/tavily_search.js";
4
+ import { pull } from "../../hub.js";
5
+ import { AgentExecutor, createXmlAgent } from "../index.js";
6
+ const tools = [new TavilySearchResults({ maxResults: 1 })];
7
+ test("createXmlAgent works", async () => {
8
+ const prompt = await pull("hwchase17/xml-agent-convo");
9
+ const llm = new ChatOpenAI({
10
+ modelName: "gpt-4-turbo",
11
+ temperature: 0,
12
+ });
13
+ const agent = await createXmlAgent({
14
+ llm,
15
+ tools,
16
+ prompt,
17
+ });
18
+ const agentExecutor = new AgentExecutor({
19
+ agent,
20
+ tools,
21
+ });
22
+ const input = "what is LangChain?";
23
+ const result = await agentExecutor.invoke({
24
+ input,
25
+ });
26
+ console.log(result);
27
+ expect(result.input).toBe(input);
28
+ expect(typeof result.output).toBe("string");
29
+ // Length greater than 10 because any less than that would warrant
30
+ // an investigation into why such a short generation was returned.
31
+ expect(result.output.length).toBeGreaterThan(10);
32
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,74 @@
1
+ import { test, expect } from "@jest/globals";
2
+ import { JsonListKeysTool, JsonSpec, JsonGetValueTool, } from "../../tools/json.js";
3
+ test("JsonListKeysTool", async () => {
4
+ const jsonSpec = new JsonSpec({
5
+ foo: "bar",
6
+ baz: { test: { foo: [1, 2, 3], qux: [{ x: 1, y: 2, z: 3 }, { a: 1 }] } },
7
+ });
8
+ const jsonListKeysTool = new JsonListKeysTool(jsonSpec);
9
+ expect(await jsonListKeysTool.invoke("")).toBe("foo, baz");
10
+ expect(await jsonListKeysTool.invoke("/foo")).toContain("not a dictionary");
11
+ expect(await jsonListKeysTool.invoke("/baz")).toBe("test");
12
+ expect(await jsonListKeysTool.invoke("/baz/test")).toBe("foo, qux");
13
+ expect(await jsonListKeysTool.invoke("/baz/test/foo")).toContain("not a dictionary");
14
+ expect(await jsonListKeysTool.invoke("/baz/test/foo/0")).toContain("not a dictionary");
15
+ expect(await jsonListKeysTool.invoke("/baz/test/qux")).toContain("not a dictionary");
16
+ expect(await jsonListKeysTool.invoke("/baz/test/qux/0")).toBe("x, y, z");
17
+ expect(await jsonListKeysTool.invoke("/baz/test/qux/1")).toBe("a");
18
+ expect(await jsonListKeysTool.invoke("/bar")).toContain("not a dictionary");
19
+ });
20
+ test("JsonListKeysTool, paths containing escaped characters", async () => {
21
+ const jsonSpec = new JsonSpec({
22
+ paths: {
23
+ "a~b": 1,
24
+ "a/b": 2,
25
+ "a~/b": 3,
26
+ "a//~b": 4,
27
+ },
28
+ });
29
+ const jsonListKeyTool = new JsonListKeysTool(jsonSpec);
30
+ expect(await jsonListKeyTool.invoke("/paths")).toBe("a~0b, a~1b, a~0~1b, a~1~1~0b");
31
+ });
32
+ test("JsonGetValueTool", async () => {
33
+ const jsonSpec = new JsonSpec({
34
+ foo: "bar",
35
+ baz: { test: { foo: [1, 2, 3], qux: [{ x: 1, y: 2, z: 3 }, { a: 1 }] } },
36
+ });
37
+ const jsonGetValueTool = new JsonGetValueTool(jsonSpec);
38
+ expect(await jsonGetValueTool.invoke("")).toBe(`{"foo":"bar","baz":{"test":{"foo":[1,2,3],"qux":[{"x":1,"y":2,"z":3},{"a":1}]}}}`);
39
+ expect(await jsonGetValueTool.invoke("/foo")).toBe("bar");
40
+ expect(await jsonGetValueTool.invoke("/baz")).toBe(`{"test":{"foo":[1,2,3],"qux":[{"x":1,"y":2,"z":3},{"a":1}]}}`);
41
+ expect(await jsonGetValueTool.invoke("/baz/test")).toBe(`{"foo":[1,2,3],"qux":[{"x":1,"y":2,"z":3},{"a":1}]}`);
42
+ expect(await jsonGetValueTool.invoke("/baz/test/foo")).toBe("[1,2,3]");
43
+ expect(await jsonGetValueTool.invoke("/baz/test/foo/0")).toBe("1");
44
+ expect(await jsonGetValueTool.invoke("/baz/test/qux")).toBe(`[{"x":1,"y":2,"z":3},{"a":1}]`);
45
+ expect(await jsonGetValueTool.invoke("/baz/test/qux/0")).toBe(`{"x":1,"y":2,"z":3}`);
46
+ expect(await jsonGetValueTool.invoke("/baz/test/qux/0/x")).toBe("1");
47
+ expect(await jsonGetValueTool.invoke("/baz/test/qux/1")).toBe(`{"a":1}`);
48
+ expect(await jsonGetValueTool.invoke("/bar")).toContain(`null`);
49
+ });
50
+ test("JsonGetValueTool, large values", async () => {
51
+ const jsonSpec = new JsonSpec({ foo: "bar", baz: { test: { foo: [1, 2, 3, 4] } } }, 5);
52
+ const jsonGetValueTool = new JsonGetValueTool(jsonSpec);
53
+ expect(await jsonGetValueTool.invoke("")).toContain("large dictionary");
54
+ expect(await jsonGetValueTool.invoke("/foo")).toBe("bar");
55
+ expect(await jsonGetValueTool.invoke("/baz")).toContain("large dictionary");
56
+ expect(await jsonGetValueTool.invoke("/baz/test")).toContain("large dictionary");
57
+ expect(await jsonGetValueTool.invoke("/baz/test/foo")).toBe("[1,2,...");
58
+ expect(await jsonGetValueTool.invoke("/baz/test/foo/0")).toBe("1");
59
+ });
60
+ test("JsonGetValueTool, paths containing escaped characters", async () => {
61
+ const jsonSpec = new JsonSpec({
62
+ paths: {
63
+ "~IDSGenericFXCrossRate": 1,
64
+ "/IDSGenericFXCrossRate": 2,
65
+ "~/IDSGenericFXCrossRate": 3,
66
+ "/~IDSGenericFXCrossRate": 4,
67
+ },
68
+ });
69
+ const jsonGetValueTool = new JsonGetValueTool(jsonSpec);
70
+ expect(await jsonGetValueTool.invoke("/paths/~0IDSGenericFXCrossRate")).toBe("1");
71
+ expect(await jsonGetValueTool.invoke("/paths/~1IDSGenericFXCrossRate")).toBe("2");
72
+ expect(await jsonGetValueTool.invoke("/paths/~0~1IDSGenericFXCrossRate")).toBe("3");
73
+ expect(await jsonGetValueTool.invoke("/paths/~1~0IDSGenericFXCrossRate")).toBe("4");
74
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ import { ReActSingleInputOutputParser } from "../react/output_parser.js";
2
+ test("ReActSingleInputOutputParser identifies final answer", async () => {
3
+ const finalAnswerText = `Observation: 2.169459462491557
4
+ Thought: I now know the final answer
5
+ Final Answer: Harry Styles, Olivia Wilde's boyfriend, is 29 years old and his age raised to the 0.23 power is 2.169459462491557.`;
6
+ const outputParser = new ReActSingleInputOutputParser({
7
+ toolNames: [],
8
+ });
9
+ const parsedOutput = await outputParser.parse(finalAnswerText);
10
+ console.log(parsedOutput);
11
+ expect(parsedOutput).toHaveProperty("returnValues");
12
+ expect("returnValues" in parsedOutput && parsedOutput.returnValues.output).toEqual("Harry Styles, Olivia Wilde's boyfriend, is 29 years old and his age raised to the 0.23 power is 2.169459462491557.");
13
+ });
14
+ test("ReActSingleInputOutputParser identifies agent actions", async () => {
15
+ const finalAnswerText = `Observation: 29 years
16
+ Thought: I need to calculate 29 raised to the 0.23 power
17
+ Action: calculator
18
+ Action Input: 29^0.23`;
19
+ const outputParser = new ReActSingleInputOutputParser({
20
+ toolNames: [],
21
+ });
22
+ const parsedOutput = await outputParser.parse(finalAnswerText);
23
+ console.log(parsedOutput);
24
+ expect(parsedOutput).toHaveProperty("toolInput");
25
+ expect(parsedOutput).toHaveProperty("tool");
26
+ });
27
+ test("ReActSingleInputOutputParser throws if no agent finish/action is passed", async () => {
28
+ const finalAnswerText = `Who is Harry Styles' girlfriend?`;
29
+ const outputParser = new ReActSingleInputOutputParser({
30
+ toolNames: [],
31
+ });
32
+ await expect(outputParser.parse(finalAnswerText)).rejects.toThrow();
33
+ });
34
+ test("ReActSingleInputOutputParser throws if agent finish and action are passed", async () => {
35
+ const finalAnswerText = `Observation: 29 years
36
+ Thought: I need to calculate 29 raised to the 0.23 power
37
+ Action: calculator
38
+ Action Input: 29^0.23
39
+ Final Answer: Harry Styles, Olivia Wilde's boyfriend, is 29 years old and his age raised to the 0.23 power is 2.169459462491557.`;
40
+ const outputParser = new ReActSingleInputOutputParser({
41
+ toolNames: [],
42
+ });
43
+ await expect(outputParser.parse(finalAnswerText)).rejects.toThrow();
44
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,104 @@
1
+ /* eslint-disable no-process-env */
2
+ import { test } from "@jest/globals";
3
+ import { ChatOpenAI } from "@langchain/openai";
4
+ import { ChatPromptTemplate, MessagesPlaceholder, } from "@langchain/core/prompts";
5
+ import { AIMessage, FunctionMessage, } from "@langchain/core/messages";
6
+ import { convertToOpenAIFunction } from "@langchain/core/utils/function_calling";
7
+ import { RunnableSequence } from "@langchain/core/runnables";
8
+ import { AgentExecutor } from "../executor.js";
9
+ import { SerpAPI } from "../../util/testing/tools/serpapi.js";
10
+ import { Calculator } from "../../util/testing/tools/calculator.js";
11
+ import { OpenAIFunctionsAgentOutputParser } from "../openai/output_parser.js";
12
+ test("Runnable variant", async () => {
13
+ const tools = [new Calculator(), new SerpAPI()];
14
+ const model = new ChatOpenAI({ modelName: "gpt-4", temperature: 0 });
15
+ const prompt = ChatPromptTemplate.fromMessages([
16
+ ["ai", "You are a helpful assistant"],
17
+ ["human", "{input}"],
18
+ new MessagesPlaceholder("agent_scratchpad"),
19
+ ]);
20
+ const modelWithTools = model.bind({
21
+ functions: [...tools.map((tool) => convertToOpenAIFunction(tool))],
22
+ });
23
+ const formatAgentSteps = (steps) => steps.flatMap(({ action, observation }) => {
24
+ if ("messageLog" in action && action.messageLog !== undefined) {
25
+ const log = action.messageLog;
26
+ return log.concat(new FunctionMessage(observation, action.tool));
27
+ }
28
+ else {
29
+ return [new AIMessage(action.log)];
30
+ }
31
+ });
32
+ const runnableAgent = RunnableSequence.from([
33
+ {
34
+ input: (i) => i.input,
35
+ agent_scratchpad: (i) => formatAgentSteps(i.steps),
36
+ },
37
+ prompt,
38
+ modelWithTools,
39
+ new OpenAIFunctionsAgentOutputParser(),
40
+ ]);
41
+ const executor = AgentExecutor.fromAgentAndTools({
42
+ agent: runnableAgent,
43
+ tools,
44
+ });
45
+ console.log("Loaded agent executor");
46
+ const query = "What is the weather in New York?";
47
+ console.log(`Calling agent executor with query: ${query}`);
48
+ const result = await executor.invoke({
49
+ input: query,
50
+ });
51
+ console.log(result);
52
+ });
53
+ test("Runnable variant executor astream log", async () => {
54
+ const tools = [new Calculator(), new SerpAPI()];
55
+ const model = new ChatOpenAI({
56
+ modelName: "gpt-4",
57
+ temperature: 0,
58
+ streaming: true,
59
+ });
60
+ const prompt = ChatPromptTemplate.fromMessages([
61
+ ["ai", "You are a helpful assistant"],
62
+ ["human", "{input}"],
63
+ new MessagesPlaceholder("agent_scratchpad"),
64
+ ]);
65
+ const modelWithTools = model.bind({
66
+ functions: [...tools.map((tool) => convertToOpenAIFunction(tool))],
67
+ });
68
+ const formatAgentSteps = (steps) => steps.flatMap(({ action, observation }) => {
69
+ if ("messageLog" in action && action.messageLog !== undefined) {
70
+ const log = action.messageLog;
71
+ return log.concat(new FunctionMessage(observation, action.tool));
72
+ }
73
+ else {
74
+ return [new AIMessage(action.log)];
75
+ }
76
+ });
77
+ const runnableAgent = RunnableSequence.from([
78
+ {
79
+ input: (i) => i.input,
80
+ agent_scratchpad: (i) => formatAgentSteps(i.steps),
81
+ },
82
+ prompt,
83
+ modelWithTools,
84
+ new OpenAIFunctionsAgentOutputParser(),
85
+ ]);
86
+ const executor = AgentExecutor.fromAgentAndTools({
87
+ agent: runnableAgent,
88
+ tools,
89
+ });
90
+ console.log("Loaded agent executor");
91
+ const query = "What is the weather in New York?";
92
+ console.log(`Calling agent executor with query: ${query}`);
93
+ const stream = await executor.streamLog({
94
+ input: query,
95
+ });
96
+ let hasSeenLLMLogPatch = false;
97
+ for await (const chunk of stream) {
98
+ console.log(JSON.stringify(chunk));
99
+ if (chunk.ops[0].path.includes("ChatOpenAI")) {
100
+ hasSeenLLMLogPatch = true;
101
+ }
102
+ }
103
+ expect(hasSeenLLMLogPatch).toBe(true);
104
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,133 @@
1
+ /* eslint-disable no-process-env */
2
+ import { test, expect, beforeEach, afterEach } from "@jest/globals";
3
+ import { DataSource } from "typeorm";
4
+ import { InfoSqlTool, QuerySqlTool, ListTablesSqlTool, QueryCheckerTool, } from "../../tools/sql.js";
5
+ import { SqlDatabase } from "../../sql_db.js";
6
+ const previousEnv = process.env;
7
+ let db;
8
+ beforeEach(async () => {
9
+ const datasource = new DataSource({
10
+ type: "sqlite",
11
+ database: ":memory:",
12
+ synchronize: true,
13
+ });
14
+ await datasource.initialize();
15
+ await datasource.query(`
16
+ CREATE TABLE products (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, price INTEGER);
17
+ `);
18
+ await datasource.query(`
19
+ INSERT INTO products (name, price) VALUES ('Apple', 100);
20
+ `);
21
+ await datasource.query(`
22
+ INSERT INTO products (name, price) VALUES ('Banana', 200);
23
+ `);
24
+ await datasource.query(`
25
+ INSERT INTO products (name, price) VALUES ('Orange', 300);
26
+ `);
27
+ await datasource.query(`
28
+ CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER);
29
+ `);
30
+ await datasource.query(`
31
+ INSERT INTO users (name, age) VALUES ('Alice', 20);
32
+ `);
33
+ await datasource.query(`
34
+ INSERT INTO users (name, age) VALUES ('Bob', 21);
35
+ `);
36
+ await datasource.query(`
37
+ INSERT INTO users (name, age) VALUES ('Charlie', 22);
38
+ `);
39
+ db = await SqlDatabase.fromDataSourceParams({
40
+ appDataSource: datasource,
41
+ });
42
+ process.env = { ...previousEnv, OPENAI_API_KEY: "test" };
43
+ });
44
+ afterEach(async () => {
45
+ process.env = previousEnv;
46
+ await db.appDataSource.destroy();
47
+ });
48
+ test.skip("QuerySqlTool", async () => {
49
+ const querySqlTool = new QuerySqlTool(db);
50
+ const result = await querySqlTool.invoke("SELECT * FROM users");
51
+ expect(result).toBe(`[{"id":1,"name":"Alice","age":20},{"id":2,"name":"Bob","age":21},{"id":3,"name":"Charlie","age":22}]`);
52
+ });
53
+ test.skip("QuerySqlTool with error", async () => {
54
+ const querySqlTool = new QuerySqlTool(db);
55
+ const result = await querySqlTool.invoke("SELECT * FROM userss");
56
+ expect(result).toBe(`QueryFailedError: SQLITE_ERROR: no such table: userss`);
57
+ });
58
+ test.skip("InfoSqlTool", async () => {
59
+ const infoSqlTool = new InfoSqlTool(db);
60
+ const result = await infoSqlTool.invoke("users, products");
61
+ const expectStr = `
62
+ CREATE TABLE products (
63
+ id INTEGER , name TEXT , price INTEGER )
64
+ SELECT * FROM "products" LIMIT 3;
65
+ id name price
66
+ 1 Apple 100
67
+ 2 Banana 200
68
+ 3 Orange 300
69
+ CREATE TABLE users (
70
+ id INTEGER , name TEXT , age INTEGER )
71
+ SELECT * FROM "users" LIMIT 3;
72
+ id name age
73
+ 1 Alice 20
74
+ 2 Bob 21
75
+ 3 Charlie 22`;
76
+ expect(result.trim()).toBe(expectStr.trim());
77
+ });
78
+ test.skip("InfoSqlTool with customDescription", async () => {
79
+ db.customDescription = {
80
+ products: "Custom Description for Products Table",
81
+ users: "Custom Description for Users Table",
82
+ userss: "Should not appear",
83
+ };
84
+ const infoSqlTool = new InfoSqlTool(db);
85
+ const result = await infoSqlTool.invoke("users, products");
86
+ const expectStr = `
87
+ Custom Description for Products Table
88
+ CREATE TABLE products (
89
+ id INTEGER , name TEXT , price INTEGER )
90
+ SELECT * FROM "products" LIMIT 3;
91
+ id name price
92
+ 1 Apple 100
93
+ 2 Banana 200
94
+ 3 Orange 300
95
+ Custom Description for Users Table
96
+ CREATE TABLE users (
97
+ id INTEGER , name TEXT , age INTEGER )
98
+ SELECT * FROM "users" LIMIT 3;
99
+ id name age
100
+ 1 Alice 20
101
+ 2 Bob 21
102
+ 3 Charlie 22`;
103
+ expect(result.trim()).toBe(expectStr.trim());
104
+ });
105
+ test.skip("InfoSqlTool with error", async () => {
106
+ const infoSqlTool = new InfoSqlTool(db);
107
+ const result = await infoSqlTool.invoke("userss, products");
108
+ expect(result).toBe(`Error: Wrong target table name: the table userss was not found in the database`);
109
+ });
110
+ test.skip("ListTablesSqlTool", async () => {
111
+ const listSqlTool = new ListTablesSqlTool(db);
112
+ const result = await listSqlTool.invoke("");
113
+ expect(result).toBe(`products, users`);
114
+ });
115
+ test.skip("QueryCheckerTool", async () => {
116
+ const queryCheckerTool = new QueryCheckerTool();
117
+ expect(queryCheckerTool.llmChain).not.toBeNull();
118
+ expect(queryCheckerTool.llmChain.inputKeys).toEqual(["query"]);
119
+ });
120
+ test.skip("ListTablesSqlTool with include tables", async () => {
121
+ const includesTables = ["users"];
122
+ db.includesTables = includesTables;
123
+ const listSqlTool = new ListTablesSqlTool(db);
124
+ const result = await listSqlTool.invoke("");
125
+ expect(result).toBe("users");
126
+ });
127
+ test.skip("ListTablesSqlTool with ignore tables", async () => {
128
+ const ignoreTables = ["products"];
129
+ db.ignoreTables = ignoreTables;
130
+ const listSqlTool = new ListTablesSqlTool(db);
131
+ const result = await listSqlTool.invoke("");
132
+ expect(result).toBe("users");
133
+ });
@@ -0,0 +1,35 @@
1
+ import { test, expect } from "@jest/globals";
2
+ import { StructuredChatOutputParser } from "../structured_chat/outputParser.js";
3
+ test("Can parse JSON with text in front of it", async () => {
4
+ const testCases = [
5
+ {
6
+ input: 'Here we have some boilerplate nonsense```json\n{\n "action": "blogpost",\n "action_input": "```sql\\nSELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = \'bud\'```"\n}\n``` and at the end there is more nonsense',
7
+ output: '{"action":"blogpost","action_input":"```sql\\nSELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = \'bud\'```"}',
8
+ tool: "blogpost",
9
+ toolInput: "```sql\nSELECT * FROM orders\nJOIN users ON users.id = orders.user_id\nWHERE users.email = 'bud'```",
10
+ },
11
+ {
12
+ input: 'Here we have some boilerplate nonsense```json\n{\n \t\r\n"action": "blogpost",\n\t\r "action_input": "```sql\\nSELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = \'bud\'```"\n\t\r}\n\n\n\t\r``` and at the end there is more nonsense',
13
+ output: '{"action":"blogpost","action_input":"```sql\\nSELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = \'bud\'```"}',
14
+ tool: "blogpost",
15
+ toolInput: "```sql\nSELECT * FROM orders\nJOIN users ON users.id = orders.user_id\nWHERE users.email = 'bud'```",
16
+ },
17
+ ];
18
+ const p = new StructuredChatOutputParser({ toolNames: ["blogpost"] });
19
+ for (const message of testCases) {
20
+ const parsed = await p.parse(message.input);
21
+ expect(parsed).toBeDefined();
22
+ if (message.tool === "Final Answer") {
23
+ expect(parsed.returnValues).toBeDefined();
24
+ }
25
+ else {
26
+ expect(parsed.tool).toEqual(message.tool);
27
+ if (typeof message.toolInput === "object") {
28
+ expect(message.toolInput).toEqual(parsed.toolInput);
29
+ }
30
+ if (typeof message.toolInput === "string") {
31
+ expect(message.toolInput).toContain(parsed.toolInput);
32
+ }
33
+ }
34
+ }
35
+ });
@@ -0,0 +1,44 @@
1
+ import { test, expect } from "@jest/globals";
2
+ import { ChatOpenAI } from "@langchain/openai";
3
+ import { StructuredChatOutputParserWithRetries } from "../structured_chat/outputParser.js";
4
+ test("Can parse JSON with text in front of it", async () => {
5
+ const testCases = [
6
+ {
7
+ input: 'Here we have an invalid format (missing markdown block) that the parser should retry and fix: {\n \t\r\n"action": "blogpost",\n\t\r "action_input": "```sql\\nSELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = \'bud\'```"\n\t\r}\n\n\n\t\r and at the end there is more nonsense',
8
+ tool: "blogpost",
9
+ toolInput: "```sql\nSELECT * FROM orders\nJOIN users ON users.id = orders.user_id\nWHERE users.email = 'bud'```",
10
+ },
11
+ {
12
+ input: 'Here we have an invalid format (missing markdown block) with a structured tool that the parser should retry and fix: {\n \t\r\n"action": "blogpost",\n\t\r "action_input": {"query": "SELECT * FROM orders\\nJOIN users ON users.id = orders.user_id\\nWHERE users.email = $1",\n\t"parameters": ["bud"]\n\t}\n\t\r}\n\n\n\t\r and at the end there is more nonsense',
13
+ tool: "blogpost",
14
+ toolInput: {
15
+ query: "SELECT * FROM orders\nJOIN users ON users.id = orders.user_id\nWHERE users.email = $1",
16
+ parameters: ["bud"],
17
+ },
18
+ },
19
+ {
20
+ input: `I don't know the answer.`,
21
+ tool: "Final Answer",
22
+ toolInput: "I don't know the answer.",
23
+ },
24
+ ];
25
+ const p = StructuredChatOutputParserWithRetries.fromLLM(new ChatOpenAI({ temperature: 0, modelName: "gpt-3.5-turbo" }), {
26
+ toolNames: ["blogpost"],
27
+ });
28
+ for (const message of testCases) {
29
+ const parsed = await p.parse(message.input);
30
+ expect(parsed).toBeDefined();
31
+ if (message.tool === "Final Answer") {
32
+ expect(parsed.returnValues).toBeDefined();
33
+ }
34
+ else {
35
+ expect(parsed.tool).toEqual(message.tool);
36
+ if (typeof message.toolInput === "object") {
37
+ expect(message.toolInput).toEqual(parsed.toolInput);
38
+ }
39
+ if (typeof message.toolInput === "string") {
40
+ expect(message.toolInput).toContain(parsed.toolInput);
41
+ }
42
+ }
43
+ }
44
+ });