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.
- package/dist/agents/tests/agent.int.test.d.ts +1 -0
- package/dist/agents/tests/agent.int.test.js +309 -0
- package/dist/agents/tests/chat_convo_output_parser.test.d.ts +1 -0
- package/dist/agents/tests/chat_convo_output_parser.test.js +91 -0
- package/dist/agents/tests/create_openai_functions_agent.int.test.d.ts +2 -0
- package/dist/agents/tests/create_openai_functions_agent.int.test.js +71 -0
- package/dist/agents/tests/create_openai_tools_agent.int.test.d.ts +1 -0
- package/dist/agents/tests/create_openai_tools_agent.int.test.js +75 -0
- package/dist/agents/tests/create_react_agent.int.test.d.ts +1 -0
- package/dist/agents/tests/create_react_agent.int.test.js +32 -0
- package/dist/agents/tests/create_structured_chat_agent.int.test.d.ts +1 -0
- package/dist/agents/tests/create_structured_chat_agent.int.test.js +32 -0
- package/dist/agents/tests/create_tool_calling_agent.int.test.d.ts +1 -0
- package/dist/agents/tests/create_tool_calling_agent.int.test.js +71 -0
- package/dist/agents/tests/create_xml_agent.int.test.d.ts +1 -0
- package/dist/agents/tests/create_xml_agent.int.test.js +32 -0
- package/dist/agents/tests/json.test.d.ts +1 -0
- package/dist/agents/tests/json.test.js +74 -0
- package/dist/agents/tests/react.test.d.ts +1 -0
- package/dist/agents/tests/react.test.js +44 -0
- package/dist/agents/tests/runnable.int.test.d.ts +1 -0
- package/dist/agents/tests/runnable.int.test.js +104 -0
- package/dist/agents/tests/sql.test.d.ts +1 -0
- package/dist/agents/tests/sql.test.js +133 -0
- package/dist/agents/tests/structured_chat_output_parser.test.d.ts +1 -0
- package/dist/agents/tests/structured_chat_output_parser.test.js +35 -0
- package/dist/agents/tests/structured_chat_output_parser_with_retries.int.test.d.ts +1 -0
- package/dist/agents/tests/structured_chat_output_parser_with_retries.int.test.js +44 -0
- package/dist/agents/tests/structured_output_runnables.int.test.d.ts +1 -0
- package/dist/agents/tests/structured_output_runnables.int.test.js +112 -0
- package/dist/agents/toolkits/tests/conversational_retrieval.int.test.d.ts +1 -0
- package/dist/agents/toolkits/tests/conversational_retrieval.int.test.js +41 -0
- package/dist/cache/tests/file_system.int.test.d.ts +1 -0
- package/dist/cache/tests/file_system.int.test.js +32 -0
- package/dist/chains/openai_functions/tests/create_runnable_chains.int.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/create_runnable_chains.int.test.js +139 -0
- package/dist/chains/openai_functions/tests/extraction.int.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/extraction.int.test.js +33 -0
- package/dist/chains/openai_functions/tests/openapi.int.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/openapi.int.test.js +130 -0
- package/dist/chains/openai_functions/tests/openapi.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/openapi.test.js +172 -0
- package/dist/chains/openai_functions/tests/structured_output.int.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/structured_output.int.test.js +40 -0
- package/dist/chains/openai_functions/tests/structured_output.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/structured_output.test.js +102 -0
- package/dist/chains/openai_functions/tests/tagging.int.test.d.ts +1 -0
- package/dist/chains/openai_functions/tests/tagging.int.test.js +21 -0
- package/dist/chains/query_constructor/tests/query_chain.int.test.d.ts +1 -0
- package/dist/chains/query_constructor/tests/query_chain.int.test.js +93 -0
- package/dist/chains/query_constructor/tests/query_parser.test.d.ts +1 -0
- package/dist/chains/query_constructor/tests/query_parser.test.js +28 -0
- package/dist/chains/question_answering/tests/load.int.test.d.ts +1 -0
- package/dist/chains/question_answering/tests/load.int.test.js +39 -0
- package/dist/chains/router/tests/multi_prompt.int.test.d.ts +1 -0
- package/dist/chains/router/tests/multi_prompt.int.test.js +45 -0
- package/dist/chains/router/tests/multi_prompt.test.d.ts +1 -0
- package/dist/chains/router/tests/multi_prompt.test.js +62 -0
- package/dist/chains/router/tests/multi_retrieval_qa.int.test.d.ts +1 -0
- package/dist/chains/router/tests/multi_retrieval_qa.int.test.js +67 -0
- package/dist/chains/router/tests/multi_retrieval_qa.test.d.ts +1 -0
- package/dist/chains/router/tests/multi_retrieval_qa.test.js +125 -0
- package/dist/chains/summarization/tests/load.int.test.d.ts +1 -0
- package/dist/chains/summarization/tests/load.int.test.js +37 -0
- package/dist/chains/tests/api_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/api_chain.int.test.js +55 -0
- package/dist/chains/tests/combine_docs_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/combine_docs_chain.int.test.js +50 -0
- package/dist/chains/tests/combine_docs_chain.test.d.ts +1 -0
- package/dist/chains/tests/combine_docs_chain.test.js +98 -0
- package/dist/chains/tests/constitutional_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/constitutional_chain.int.test.js +30 -0
- package/dist/chains/tests/constitutional_chain.test.d.ts +1 -0
- package/dist/chains/tests/constitutional_chain.test.js +63 -0
- package/dist/chains/tests/conversation_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/conversation_chain.int.test.js +9 -0
- package/dist/chains/tests/conversational_retrieval_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/conversational_retrieval_chain.int.test.js +243 -0
- package/dist/chains/tests/example_data/open_meteo_docs.d.ts +1 -0
- package/dist/chains/tests/example_data/open_meteo_docs.js +29 -0
- package/dist/chains/tests/history_aware_retriever.int.test.d.ts +1 -0
- package/dist/chains/tests/history_aware_retriever.int.test.js +41 -0
- package/dist/chains/tests/history_aware_retriever.test.d.ts +1 -0
- package/dist/chains/tests/history_aware_retriever.test.js +27 -0
- package/dist/chains/tests/llm_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/llm_chain.int.test.js +119 -0
- package/dist/chains/tests/openai_moderation.int.test.d.ts +1 -0
- package/dist/chains/tests/openai_moderation.int.test.js +30 -0
- package/dist/chains/tests/retrieval_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/retrieval_chain.int.test.js +69 -0
- package/dist/chains/tests/retrieval_chain.test.d.ts +1 -0
- package/dist/chains/tests/retrieval_chain.test.js +36 -0
- package/dist/chains/tests/sequential_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/sequential_chain.int.test.js +88 -0
- package/dist/chains/tests/sequential_chain.test.d.ts +1 -0
- package/dist/chains/tests/sequential_chain.test.js +295 -0
- package/dist/chains/tests/simple_sequential_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/simple_sequential_chain.int.test.js +81 -0
- package/dist/chains/tests/simple_sequential_chain.test.d.ts +1 -0
- package/dist/chains/tests/simple_sequential_chain.test.js +128 -0
- package/dist/chains/tests/sql_db_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/sql_db_chain.int.test.js +125 -0
- package/dist/chains/tests/transform.test.d.ts +1 -0
- package/dist/chains/tests/transform.test.js +12 -0
- package/dist/chains/tests/vector_db_qa_chain.int.test.d.ts +1 -0
- package/dist/chains/tests/vector_db_qa_chain.int.test.js +45 -0
- package/dist/document_loaders/tests/assemblyai.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/assemblyai.int.test.js +111 -0
- package/dist/document_loaders/tests/chatgpt-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/chatgpt-blob.test.js +30 -0
- package/dist/document_loaders/tests/chatgpt.test.d.ts +1 -0
- package/dist/document_loaders/tests/chatgpt.test.js +29 -0
- package/dist/document_loaders/tests/cheerio.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/cheerio.int.test.js +21 -0
- package/dist/document_loaders/tests/college_confidential.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/college_confidential.int.test.js +6 -0
- package/dist/document_loaders/tests/confluence.test.d.ts +1 -0
- package/dist/document_loaders/tests/confluence.test.js +52 -0
- package/dist/document_loaders/tests/couchbase.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/couchbase.int.test.js +28 -0
- package/dist/document_loaders/tests/csv-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/csv-blob.test.js +51 -0
- package/dist/document_loaders/tests/csv.test.d.ts +1 -0
- package/dist/document_loaders/tests/csv.test.js +41 -0
- package/dist/document_loaders/tests/directory.test.d.ts +1 -0
- package/dist/document_loaders/tests/directory.test.js +38 -0
- package/dist/document_loaders/tests/docx.test.d.ts +1 -0
- package/dist/document_loaders/tests/docx.test.js +11 -0
- package/dist/document_loaders/tests/epub.test.d.ts +1 -0
- package/dist/document_loaders/tests/epub.test.js +18 -0
- package/dist/document_loaders/tests/example_data/github_api_responses.d.ts +5 -0
- package/dist/document_loaders/tests/example_data/github_api_responses.js +91 -0
- package/dist/document_loaders/tests/figma.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/figma.int.test.js +13 -0
- package/dist/document_loaders/tests/firecrawl.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/firecrawl.int.test.js +30 -0
- package/dist/document_loaders/tests/gitbook.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/gitbook.int.test.js +14 -0
- package/dist/document_loaders/tests/github.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/github.int.test.js +86 -0
- package/dist/document_loaders/tests/github.test.d.ts +1 -0
- package/dist/document_loaders/tests/github.test.js +51 -0
- package/dist/document_loaders/tests/hn.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/hn.int.test.js +6 -0
- package/dist/document_loaders/tests/imsdb.test.d.ts +1 -0
- package/dist/document_loaders/tests/imsdb.test.js +6 -0
- package/dist/document_loaders/tests/json-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/json-blob.test.js +87 -0
- package/dist/document_loaders/tests/json.test.d.ts +1 -0
- package/dist/document_loaders/tests/json.test.js +69 -0
- package/dist/document_loaders/tests/jsonl-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/jsonl-blob.test.js +44 -0
- package/dist/document_loaders/tests/jsonl.test.d.ts +1 -0
- package/dist/document_loaders/tests/jsonl.test.js +15 -0
- package/dist/document_loaders/tests/notion.test.d.ts +1 -0
- package/dist/document_loaders/tests/notion.test.js +11 -0
- package/dist/document_loaders/tests/notionapi.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/notionapi.int.test.js +80 -0
- package/dist/document_loaders/tests/notionapi.test.d.ts +1 -0
- package/dist/document_loaders/tests/notionapi.test.js +84 -0
- package/dist/document_loaders/tests/notiondb.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/notiondb.int.test.js +13 -0
- package/dist/document_loaders/tests/obsidian.test.d.ts +1 -0
- package/dist/document_loaders/tests/obsidian.test.js +119 -0
- package/dist/document_loaders/tests/pdf-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/pdf-blob.test.js +44 -0
- package/dist/document_loaders/tests/pdf.test.d.ts +1 -0
- package/dist/document_loaders/tests/pdf.test.js +25 -0
- package/dist/document_loaders/tests/playwright_web.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/playwright_web.int.test.js +27 -0
- package/dist/document_loaders/tests/pptx.test.d.ts +1 -0
- package/dist/document_loaders/tests/pptx.test.js +17 -0
- package/dist/document_loaders/tests/puppeteer.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/puppeteer.int.test.js +47 -0
- package/dist/document_loaders/tests/recursive_url.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/recursive_url.int.test.js +64 -0
- package/dist/document_loaders/tests/s3.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/s3.int.test.js +48 -0
- package/dist/document_loaders/tests/searchapi.test.d.ts +1 -0
- package/dist/document_loaders/tests/searchapi.test.js +29 -0
- package/dist/document_loaders/tests/serpapi.test.d.ts +1 -0
- package/dist/document_loaders/tests/serpapi.test.js +21 -0
- package/dist/document_loaders/tests/sitemap.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/sitemap.int.test.js +28 -0
- package/dist/document_loaders/tests/sonix_audio.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/sonix_audio.int.test.js +55 -0
- package/dist/document_loaders/tests/sort_xyz_blockchain.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/sort_xyz_blockchain.int.test.js +38 -0
- package/dist/document_loaders/tests/srt-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/srt-blob.test.js +18 -0
- package/dist/document_loaders/tests/srt.test.d.ts +1 -0
- package/dist/document_loaders/tests/srt.test.js +16 -0
- package/dist/document_loaders/tests/text-blob.test.d.ts +1 -0
- package/dist/document_loaders/tests/text-blob.test.js +14 -0
- package/dist/document_loaders/tests/text.test.d.ts +1 -0
- package/dist/document_loaders/tests/text.test.js +22 -0
- package/dist/document_loaders/tests/unstructured.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/unstructured.int.test.js +40 -0
- package/dist/document_loaders/tests/webpdf.int.test.d.ts +1 -0
- package/dist/document_loaders/tests/webpdf.int.test.js +90 -0
- package/dist/document_transformers/tests/openai_functions.int.test.d.ts +1 -0
- package/dist/document_transformers/tests/openai_functions.int.test.js +40 -0
- package/dist/embeddings/tests/cache.test.d.ts +1 -0
- package/dist/embeddings/tests/cache.test.js +24 -0
- package/dist/embeddings/tests/fake.test.d.ts +1 -0
- package/dist/embeddings/tests/fake.test.js +34 -0
- package/dist/evaluation/agents/tests/trajectory_eval_chain.int.test.d.ts +1 -0
- package/dist/evaluation/agents/tests/trajectory_eval_chain.int.test.js +33 -0
- package/dist/evaluation/comparison/tests/pairwise_eval_chain.int.test.d.ts +1 -0
- package/dist/evaluation/comparison/tests/pairwise_eval_chain.int.test.js +46 -0
- package/dist/evaluation/criteria/tests/criteria_eval_chain.int.test.d.ts +1 -0
- package/dist/evaluation/criteria/tests/criteria_eval_chain.int.test.js +108 -0
- package/dist/evaluation/embedding_distance/tests/embedding_distance_eval_chain.int.test.d.ts +1 -0
- package/dist/evaluation/embedding_distance/tests/embedding_distance_eval_chain.int.test.js +26 -0
- package/dist/evaluation/qa/tests/eval_chain.int.test.d.ts +1 -0
- package/dist/evaluation/qa/tests/eval_chain.int.test.js +27 -0
- package/dist/experimental/autogpt/tests/output_parser.test.d.ts +1 -0
- package/dist/experimental/autogpt/tests/output_parser.test.js +8 -0
- package/dist/experimental/autogpt/tests/prompt.test.d.ts +1 -0
- package/dist/experimental/autogpt/tests/prompt.test.js +69 -0
- package/dist/experimental/autogpt/tests/prompt_generator.test.d.ts +1 -0
- package/dist/experimental/autogpt/tests/prompt_generator.test.js +91 -0
- package/dist/experimental/chains/tests/violation_of_expectations_chain.int.test.d.ts +1 -0
- package/dist/experimental/chains/tests/violation_of_expectations_chain.int.test.js +26 -0
- package/dist/experimental/generative_agents/tests/generative_agent.int.test.d.ts +1 -0
- package/dist/experimental/generative_agents/tests/generative_agent.int.test.js +304 -0
- package/dist/experimental/masking/tests/masking-extended.test.d.ts +1 -0
- package/dist/experimental/masking/tests/masking-extended.test.js +58 -0
- package/dist/experimental/masking/tests/masking.test.d.ts +1 -0
- package/dist/experimental/masking/tests/masking.test.js +388 -0
- package/dist/experimental/openai_assistant/tests/openai_assistant.int.test.d.ts +1 -0
- package/dist/experimental/openai_assistant/tests/openai_assistant.int.test.js +203 -0
- package/dist/experimental/openai_files/tests/openai_file.int.test.d.ts +1 -0
- package/dist/experimental/openai_files/tests/openai_file.int.test.js +87 -0
- package/dist/experimental/plan_and_execute/tests/plan_and_execute.int.test.d.ts +1 -0
- package/dist/experimental/plan_and_execute/tests/plan_and_execute.int.test.js +54 -0
- package/dist/experimental/prompts/tests/handlebars.test.d.ts +1 -0
- package/dist/experimental/prompts/tests/handlebars.test.js +24 -0
- package/dist/experimental/tools/tests/pyinterpreter.int.test.d.ts +1 -0
- package/dist/experimental/tools/tests/pyinterpreter.int.test.js +22 -0
- package/dist/load/import_map.cjs +1 -1
- package/dist/load/import_map.js +1 -1
- package/dist/load/tests/cross_language.test.d.ts +1 -0
- package/dist/load/tests/cross_language.test.js +83 -0
- package/dist/load/tests/load.int.test.d.ts +1 -0
- package/dist/load/tests/load.int.test.js +9 -0
- package/dist/load/tests/load.test.d.ts +1 -0
- package/dist/load/tests/load.test.js +412 -0
- package/dist/memory/tests/buffer_memory.test.d.ts +1 -0
- package/dist/memory/tests/buffer_memory.test.js +34 -0
- package/dist/memory/tests/buffer_token_memory.int.test.d.ts +1 -0
- package/dist/memory/tests/buffer_token_memory.int.test.js +47 -0
- package/dist/memory/tests/buffer_window_memory.test.d.ts +1 -0
- package/dist/memory/tests/buffer_window_memory.test.js +42 -0
- package/dist/memory/tests/combined_memory.int.test.d.ts +1 -0
- package/dist/memory/tests/combined_memory.int.test.js +74 -0
- package/dist/memory/tests/entity_memory.int.test.d.ts +1 -0
- package/dist/memory/tests/entity_memory.int.test.js +79 -0
- package/dist/memory/tests/entity_memory.test.d.ts +1 -0
- package/dist/memory/tests/entity_memory.test.js +48 -0
- package/dist/memory/tests/summary.int.test.d.ts +1 -0
- package/dist/memory/tests/summary.int.test.js +50 -0
- package/dist/memory/tests/summary_buffer.int.test.d.ts +1 -0
- package/dist/memory/tests/summary_buffer.int.test.js +55 -0
- package/dist/memory/tests/vector_store_memory.int.test.d.ts +1 -0
- package/dist/memory/tests/vector_store_memory.int.test.js +55 -0
- package/dist/output_parsers/tests/combining.int.test.d.ts +1 -0
- package/dist/output_parsers/tests/combining.int.test.js +26 -0
- package/dist/output_parsers/tests/combining.test.d.ts +1 -0
- package/dist/output_parsers/tests/combining.test.js +54 -0
- package/dist/output_parsers/tests/datetime.test.d.ts +1 -0
- package/dist/output_parsers/tests/datetime.test.js +14 -0
- package/dist/output_parsers/tests/expression.test.d.ts +1 -0
- package/dist/output_parsers/tests/expression.test.js +339 -0
- package/dist/output_parsers/tests/http_response.test.d.ts +1 -0
- package/dist/output_parsers/tests/http_response.test.js +39 -0
- package/dist/output_parsers/tests/list.test.d.ts +1 -0
- package/dist/output_parsers/tests/list.test.js +27 -0
- package/dist/output_parsers/tests/openai_functions.int.test.d.ts +1 -0
- package/dist/output_parsers/tests/openai_functions.int.test.js +89 -0
- package/dist/output_parsers/tests/openai_tools.int.test.d.ts +1 -0
- package/dist/output_parsers/tests/openai_tools.int.test.js +36 -0
- package/dist/output_parsers/tests/structured.int.test.d.ts +1 -0
- package/dist/output_parsers/tests/structured.int.test.js +150 -0
- package/dist/prompts/tests/selectors.test.d.ts +1 -0
- package/dist/prompts/tests/selectors.test.js +59 -0
- package/dist/retrievers/self_query/tests/memory_self_query.int.test.d.ts +1 -0
- package/dist/retrievers/self_query/tests/memory_self_query.int.test.js +330 -0
- package/dist/retrievers/tests/chain_extract.int.test.d.ts +1 -0
- package/dist/retrievers/tests/chain_extract.int.test.js +32 -0
- package/dist/retrievers/tests/hyde.int.test.d.ts +1 -0
- package/dist/retrievers/tests/hyde.int.test.js +44 -0
- package/dist/retrievers/tests/matryoshka_retriever.int.test.d.ts +1 -0
- package/dist/retrievers/tests/matryoshka_retriever.int.test.js +113 -0
- package/dist/retrievers/tests/multi_query.int.test.d.ts +1 -0
- package/dist/retrievers/tests/multi_query.int.test.js +45 -0
- package/dist/retrievers/tests/parent_document.int.test.d.ts +1 -0
- package/dist/retrievers/tests/parent_document.int.test.js +122 -0
- package/dist/retrievers/tests/score_threshold.int.test.d.ts +1 -0
- package/dist/retrievers/tests/score_threshold.int.test.js +83 -0
- package/dist/retrievers/tests/time_weighted.test.d.ts +1 -0
- package/dist/retrievers/tests/time_weighted.test.js +320 -0
- package/dist/retrievers/tests/vectorstores.test.d.ts +1 -0
- package/dist/retrievers/tests/vectorstores.test.js +50 -0
- package/dist/smith/tests/run_on_dataset.int.test.d.ts +1 -0
- package/dist/smith/tests/run_on_dataset.int.test.js +257 -0
- package/dist/smith/tests/runner_utils.int.test.d.ts +9 -0
- package/dist/smith/tests/runner_utils.int.test.js +234 -0
- package/dist/storage/tests/file_system.test.d.ts +1 -0
- package/dist/storage/tests/file_system.test.js +81 -0
- package/dist/tools/tests/chain.test.d.ts +1 -0
- package/dist/tools/tests/chain.test.js +136 -0
- package/dist/tools/tests/webbrowser.int.test.d.ts +1 -0
- package/dist/tools/tests/webbrowser.int.test.js +80 -0
- package/dist/tools/tests/webbrowser.test.d.ts +1 -0
- package/dist/tools/tests/webbrowser.test.js +21 -0
- package/dist/util/tests/async_caller.int.test.d.ts +1 -0
- package/dist/util/tests/async_caller.int.test.js +34 -0
- package/dist/util/tests/azure.test.d.ts +1 -0
- package/dist/util/tests/azure.test.js +42 -0
- package/dist/util/tests/openai-stream.test.d.ts +1 -0
- package/dist/util/tests/openai-stream.test.js +135 -0
- package/dist/util/tests/set.test.d.ts +1 -0
- package/dist/util/tests/set.test.js +36 -0
- package/dist/util/tests/sql_utils.test.d.ts +1 -0
- package/dist/util/tests/sql_utils.test.js +50 -0
- package/dist/vectorstores/tests/memory.test.d.ts +1 -0
- package/dist/vectorstores/tests/memory.test.js +78 -0
- package/package.json +5 -4
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { test } from "@jest/globals";
|
|
2
|
+
import { OpenAI, ChatOpenAI } from "@langchain/openai";
|
|
3
|
+
import { PromptTemplate } from "@langchain/core/prompts";
|
|
4
|
+
import { LLMChain } from "../llm_chain.js";
|
|
5
|
+
import { SequentialChain } from "../sequential_chain.js";
|
|
6
|
+
test("Test SequentialChain example usage", async () => {
|
|
7
|
+
// This is an LLMChain to write a synopsis given a title of a play and the era it is set in.
|
|
8
|
+
const llm = new OpenAI({ temperature: 0 });
|
|
9
|
+
const template = `You are a playwright. Given the title of play and the era it is set in, it is your job to write a synopsis for that title.
|
|
10
|
+
|
|
11
|
+
Title: {title}
|
|
12
|
+
Era: {era}
|
|
13
|
+
Playwright: This is a synopsis for the above play:`;
|
|
14
|
+
const promptTemplate = new PromptTemplate({
|
|
15
|
+
template,
|
|
16
|
+
inputVariables: ["title", "era"],
|
|
17
|
+
});
|
|
18
|
+
const synopsisChain = new LLMChain({
|
|
19
|
+
llm,
|
|
20
|
+
prompt: promptTemplate,
|
|
21
|
+
outputKey: "synopsis",
|
|
22
|
+
});
|
|
23
|
+
// This is an LLMChain to write a review of a play given a synopsis.
|
|
24
|
+
const reviewLLM = new OpenAI({ temperature: 0 });
|
|
25
|
+
const reviewTemplate = `You are a play critic from the New York Times. Given the synopsis of play, it is your job to write a review for that play.
|
|
26
|
+
|
|
27
|
+
Play Synopsis:
|
|
28
|
+
{synopsis}
|
|
29
|
+
Review from a New York Times play critic of the above play:`;
|
|
30
|
+
const reviewPromptTemplate = new PromptTemplate({
|
|
31
|
+
template: reviewTemplate,
|
|
32
|
+
inputVariables: ["synopsis"],
|
|
33
|
+
});
|
|
34
|
+
const reviewChain = new LLMChain({
|
|
35
|
+
llm: reviewLLM,
|
|
36
|
+
prompt: reviewPromptTemplate,
|
|
37
|
+
outputKey: "review",
|
|
38
|
+
});
|
|
39
|
+
const overallChain = new SequentialChain({
|
|
40
|
+
chains: [synopsisChain, reviewChain],
|
|
41
|
+
inputVariables: ["era", "title"],
|
|
42
|
+
// Here we return multiple variables
|
|
43
|
+
outputVariables: ["synopsis", "review"],
|
|
44
|
+
verbose: true,
|
|
45
|
+
});
|
|
46
|
+
const review = await overallChain.call({
|
|
47
|
+
title: "Tragedy at sunset on the beach",
|
|
48
|
+
era: "Victorian England",
|
|
49
|
+
});
|
|
50
|
+
expect(review.review.toLowerCase()).toContain("tragedy at sunset on the beach");
|
|
51
|
+
});
|
|
52
|
+
test.skip("Test SequentialChain serialize/deserialize", async () => {
|
|
53
|
+
const llm1 = new ChatOpenAI();
|
|
54
|
+
const template1 = `Echo back "{foo} {bar}"`;
|
|
55
|
+
const promptTemplate1 = new PromptTemplate({
|
|
56
|
+
template: template1,
|
|
57
|
+
inputVariables: ["foo", "bar"],
|
|
58
|
+
});
|
|
59
|
+
const chain1 = new LLMChain({
|
|
60
|
+
llm: llm1,
|
|
61
|
+
prompt: promptTemplate1,
|
|
62
|
+
outputKey: "baz",
|
|
63
|
+
});
|
|
64
|
+
const llm2 = new ChatOpenAI();
|
|
65
|
+
const template2 = `Echo back "{baz}"`;
|
|
66
|
+
const promptTemplate2 = new PromptTemplate({
|
|
67
|
+
template: template2,
|
|
68
|
+
inputVariables: ["baz"],
|
|
69
|
+
});
|
|
70
|
+
const chain2 = new LLMChain({
|
|
71
|
+
llm: llm2,
|
|
72
|
+
prompt: promptTemplate2,
|
|
73
|
+
});
|
|
74
|
+
const sampleSequentialChain = new SequentialChain({
|
|
75
|
+
chains: [chain1, chain2],
|
|
76
|
+
inputVariables: ["foo", "bar"],
|
|
77
|
+
outputVariables: ["text"],
|
|
78
|
+
verbose: true,
|
|
79
|
+
});
|
|
80
|
+
const serializedChain = sampleSequentialChain.serialize();
|
|
81
|
+
expect(serializedChain._type).toEqual("sequential_chain");
|
|
82
|
+
expect(serializedChain.chains.length).toEqual(2);
|
|
83
|
+
const deserializedChain = await SequentialChain.deserialize(serializedChain);
|
|
84
|
+
expect(deserializedChain.chains.length).toEqual(2);
|
|
85
|
+
expect(deserializedChain._chainType).toEqual("sequential_chain");
|
|
86
|
+
const review = await deserializedChain.call({ foo: "test1", bar: "test2" });
|
|
87
|
+
expect(review.trim()).toMatchInlineSnapshot(`"test1 test2"`);
|
|
88
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { test, expect } from "@jest/globals";
|
|
2
|
+
import { BaseLLM } from "@langchain/core/language_models/llms";
|
|
3
|
+
import { PromptTemplate } from "@langchain/core/prompts";
|
|
4
|
+
import { AIMessage, HumanMessage } from "@langchain/core/messages";
|
|
5
|
+
import { ChatMessageHistory } from "../../stores/message/in_memory.js";
|
|
6
|
+
import { LLMChain } from "../llm_chain.js";
|
|
7
|
+
import { SequentialChain } from "../sequential_chain.js";
|
|
8
|
+
import { BufferMemory } from "../../memory/buffer_memory.js";
|
|
9
|
+
class FakeLLM1 extends BaseLLM {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
Object.defineProperty(this, "nrMapCalls", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: 0
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "nrReduceCalls", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: 0
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
_llmType() {
|
|
26
|
+
return "fake_1";
|
|
27
|
+
}
|
|
28
|
+
async _generate(_prompts) {
|
|
29
|
+
return {
|
|
30
|
+
generations: [
|
|
31
|
+
[
|
|
32
|
+
{
|
|
33
|
+
text: "The answer is XXX.",
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class FakeLLM2 extends BaseLLM {
|
|
41
|
+
constructor() {
|
|
42
|
+
super(...arguments);
|
|
43
|
+
Object.defineProperty(this, "nrMapCalls", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
writable: true,
|
|
47
|
+
value: 0
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(this, "nrReduceCalls", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: 0
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
_llmType() {
|
|
57
|
+
return "fake_2";
|
|
58
|
+
}
|
|
59
|
+
async _generate(prompts) {
|
|
60
|
+
let response = "I don't know what you are talking about.";
|
|
61
|
+
if (prompts[0].includes("XXX")) {
|
|
62
|
+
response = "final answer";
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
generations: [
|
|
66
|
+
[
|
|
67
|
+
{
|
|
68
|
+
text: response,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
class FakeLLM3 extends BaseLLM {
|
|
76
|
+
constructor() {
|
|
77
|
+
super(...arguments);
|
|
78
|
+
Object.defineProperty(this, "nrMapCalls", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
value: 0
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(this, "nrReduceCalls", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
configurable: true,
|
|
87
|
+
writable: true,
|
|
88
|
+
value: 0
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
_llmType() {
|
|
92
|
+
return "fake_2";
|
|
93
|
+
}
|
|
94
|
+
async _generate(prompts) {
|
|
95
|
+
const inputNumber = +prompts[0];
|
|
96
|
+
let response = "Not a number!!!";
|
|
97
|
+
if (prompts[0].startsWith("Final Answer: ")) {
|
|
98
|
+
[response] = prompts;
|
|
99
|
+
}
|
|
100
|
+
else if (!Number.isNaN(inputNumber)) {
|
|
101
|
+
response = (inputNumber + 1).toString();
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
generations: [
|
|
105
|
+
[
|
|
106
|
+
{
|
|
107
|
+
text: response,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
],
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
test("Test SequentialChain", async () => {
|
|
115
|
+
const model1 = new FakeLLM1({});
|
|
116
|
+
const model2 = new FakeLLM2({});
|
|
117
|
+
const template1 = "Some arbitrary template with fake {input1} and {input2}.";
|
|
118
|
+
const template2 = "Some arbitrary template with fake {input3}.";
|
|
119
|
+
const prompt1 = new PromptTemplate({
|
|
120
|
+
template: template1,
|
|
121
|
+
inputVariables: ["input1", "input2"],
|
|
122
|
+
});
|
|
123
|
+
const prompt2 = new PromptTemplate({
|
|
124
|
+
template: template2,
|
|
125
|
+
inputVariables: ["input3"],
|
|
126
|
+
});
|
|
127
|
+
const chain1 = new LLMChain({
|
|
128
|
+
llm: model1,
|
|
129
|
+
prompt: prompt1,
|
|
130
|
+
outputKey: "input3",
|
|
131
|
+
});
|
|
132
|
+
const chain2 = new LLMChain({ llm: model2, prompt: prompt2 });
|
|
133
|
+
const combinedChain = new SequentialChain({
|
|
134
|
+
chains: [chain1, chain2],
|
|
135
|
+
inputVariables: ["input1", "input2"],
|
|
136
|
+
outputVariables: ["text"],
|
|
137
|
+
});
|
|
138
|
+
const response = await combinedChain.invoke({
|
|
139
|
+
input1: "test1",
|
|
140
|
+
input2: "test2",
|
|
141
|
+
});
|
|
142
|
+
expect(response).toMatchInlineSnapshot(`
|
|
143
|
+
{
|
|
144
|
+
"text": "final answer",
|
|
145
|
+
}
|
|
146
|
+
`);
|
|
147
|
+
});
|
|
148
|
+
test("Test SequentialChain input/output chains' validation", () => {
|
|
149
|
+
const model1 = new FakeLLM1({});
|
|
150
|
+
const template1 = "Some arbitrary template with fake {input1} and {input2}.";
|
|
151
|
+
const prompt1 = new PromptTemplate({
|
|
152
|
+
template: template1,
|
|
153
|
+
inputVariables: ["input1", "input2"],
|
|
154
|
+
});
|
|
155
|
+
const chain1 = new LLMChain({
|
|
156
|
+
llm: model1,
|
|
157
|
+
prompt: prompt1,
|
|
158
|
+
outputKey: "input3",
|
|
159
|
+
});
|
|
160
|
+
const model2 = new FakeLLM2({});
|
|
161
|
+
const template2 = "Some arbitrary template with fake {input3}.";
|
|
162
|
+
const prompt2 = new PromptTemplate({
|
|
163
|
+
template: template2,
|
|
164
|
+
inputVariables: ["input3"],
|
|
165
|
+
});
|
|
166
|
+
const chain2 = new LLMChain({ llm: model2, prompt: prompt2 });
|
|
167
|
+
expect(() => {
|
|
168
|
+
/* eslint-disable no-new */
|
|
169
|
+
new SequentialChain({
|
|
170
|
+
chains: [chain1, chain2],
|
|
171
|
+
inputVariables: ["input1"],
|
|
172
|
+
outputVariables: ["text"],
|
|
173
|
+
});
|
|
174
|
+
}).toThrowErrorMatchingInlineSnapshot(`"Missing variables for chain "llm": "input2". Only got the following variables: "input1"."`);
|
|
175
|
+
expect(() => {
|
|
176
|
+
/* eslint-disable no-new */
|
|
177
|
+
new SequentialChain({
|
|
178
|
+
chains: [chain1, chain2],
|
|
179
|
+
inputVariables: ["input1", "input2"],
|
|
180
|
+
outputVariables: ["nonexistent"],
|
|
181
|
+
});
|
|
182
|
+
}).toThrowErrorMatchingInlineSnapshot(`"The following output variables were expected to be in the final chain output but were not found: "nonexistent"."`);
|
|
183
|
+
});
|
|
184
|
+
test("Test SequentialChain chains' intermediate variables validation", () => {
|
|
185
|
+
const model1 = new FakeLLM1({});
|
|
186
|
+
const template1 = "Some arbitrary template with fake {input1} and {input2}.";
|
|
187
|
+
const prompt1 = new PromptTemplate({
|
|
188
|
+
template: template1,
|
|
189
|
+
inputVariables: ["input1", "input2"],
|
|
190
|
+
});
|
|
191
|
+
const chain1 = new LLMChain({
|
|
192
|
+
llm: model1,
|
|
193
|
+
prompt: prompt1,
|
|
194
|
+
outputKey: "nonexistent",
|
|
195
|
+
});
|
|
196
|
+
const model2 = new FakeLLM2({});
|
|
197
|
+
const template2 = "Some arbitrary template with fake {input3}.";
|
|
198
|
+
const prompt2 = new PromptTemplate({
|
|
199
|
+
template: template2,
|
|
200
|
+
inputVariables: ["input3"],
|
|
201
|
+
});
|
|
202
|
+
const chain2 = new LLMChain({ llm: model2, prompt: prompt2 });
|
|
203
|
+
expect(() => {
|
|
204
|
+
/* eslint-disable no-new */
|
|
205
|
+
new SequentialChain({
|
|
206
|
+
chains: [chain1, chain2],
|
|
207
|
+
inputVariables: ["input1", "input2"],
|
|
208
|
+
outputVariables: ["text"],
|
|
209
|
+
});
|
|
210
|
+
}).toThrowErrorMatchingInlineSnapshot(`"Missing variables for chain "llm": "input3". Only got the following variables: "input1", "input2", "nonexistent"."`);
|
|
211
|
+
});
|
|
212
|
+
test("Test SequentialChain chains passes all outputs", async () => {
|
|
213
|
+
const model1 = new FakeLLM3({});
|
|
214
|
+
const template1 = "{input1}";
|
|
215
|
+
const prompt1 = new PromptTemplate({
|
|
216
|
+
template: template1,
|
|
217
|
+
inputVariables: ["input1"],
|
|
218
|
+
});
|
|
219
|
+
const chain1 = new LLMChain({
|
|
220
|
+
llm: model1,
|
|
221
|
+
prompt: prompt1,
|
|
222
|
+
outputKey: "input2",
|
|
223
|
+
});
|
|
224
|
+
const model2 = new FakeLLM3({});
|
|
225
|
+
const template2 = "{input2}";
|
|
226
|
+
const prompt2 = new PromptTemplate({
|
|
227
|
+
template: template2,
|
|
228
|
+
inputVariables: ["input2"],
|
|
229
|
+
});
|
|
230
|
+
const chain2 = new LLMChain({
|
|
231
|
+
llm: model2,
|
|
232
|
+
prompt: prompt2,
|
|
233
|
+
outputKey: "input3",
|
|
234
|
+
});
|
|
235
|
+
const model3 = new FakeLLM3({});
|
|
236
|
+
const template3 = "Final Answer: {input1} {input2} {input3}.";
|
|
237
|
+
const prompt3 = new PromptTemplate({
|
|
238
|
+
template: template3,
|
|
239
|
+
inputVariables: ["input1", "input2", "input3"],
|
|
240
|
+
});
|
|
241
|
+
const chain3 = new LLMChain({ llm: model3, prompt: prompt3 });
|
|
242
|
+
const combinedChain = new SequentialChain({
|
|
243
|
+
chains: [chain1, chain2, chain3],
|
|
244
|
+
inputVariables: ["input1"],
|
|
245
|
+
outputVariables: ["text"],
|
|
246
|
+
});
|
|
247
|
+
expect(await combinedChain.invoke({
|
|
248
|
+
input1: "1",
|
|
249
|
+
})).toMatchInlineSnapshot(`
|
|
250
|
+
{
|
|
251
|
+
"text": "Final Answer: 1 2 3.",
|
|
252
|
+
}
|
|
253
|
+
`);
|
|
254
|
+
});
|
|
255
|
+
test("Test SequentialChain for memory on one of the sub-chains", async () => {
|
|
256
|
+
const model1 = new FakeLLM1({});
|
|
257
|
+
const template1 = "Some arbitrary template with fake {input1}.";
|
|
258
|
+
const prompt1 = new PromptTemplate({
|
|
259
|
+
template: template1,
|
|
260
|
+
inputVariables: ["input1"],
|
|
261
|
+
});
|
|
262
|
+
const chain1 = new LLMChain({
|
|
263
|
+
llm: model1,
|
|
264
|
+
prompt: prompt1,
|
|
265
|
+
outputKey: "input2",
|
|
266
|
+
});
|
|
267
|
+
const memory = new BufferMemory({
|
|
268
|
+
memoryKey: "chat",
|
|
269
|
+
chatHistory: new ChatMessageHistory([
|
|
270
|
+
new HumanMessage("Hello"),
|
|
271
|
+
new AIMessage("Hi"),
|
|
272
|
+
]),
|
|
273
|
+
inputKey: "input2",
|
|
274
|
+
});
|
|
275
|
+
const model2 = new FakeLLM3({});
|
|
276
|
+
const template2 = "Final Answer: \n{chat}\n{input2}";
|
|
277
|
+
const prompt2 = new PromptTemplate({
|
|
278
|
+
template: template2,
|
|
279
|
+
inputVariables: ["input2", "chat"],
|
|
280
|
+
});
|
|
281
|
+
const chain2 = new LLMChain({
|
|
282
|
+
llm: model2,
|
|
283
|
+
prompt: prompt2,
|
|
284
|
+
memory,
|
|
285
|
+
});
|
|
286
|
+
const combinedChain = new SequentialChain({
|
|
287
|
+
chains: [chain1, chain2],
|
|
288
|
+
inputVariables: ["input1"],
|
|
289
|
+
outputVariables: ["text"],
|
|
290
|
+
});
|
|
291
|
+
const result = await combinedChain.invoke({ input1: "test1" });
|
|
292
|
+
expect(result).toMatchObject({
|
|
293
|
+
text: "Final Answer: \nHuman: Hello\nAI: Hi\nThe answer is XXX.",
|
|
294
|
+
});
|
|
295
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { test } from "@jest/globals";
|
|
2
|
+
import { OpenAI, ChatOpenAI } from "@langchain/openai";
|
|
3
|
+
import { PromptTemplate } from "@langchain/core/prompts";
|
|
4
|
+
import { LLMChain } from "../llm_chain.js";
|
|
5
|
+
import { SimpleSequentialChain } from "../sequential_chain.js";
|
|
6
|
+
import { BufferMemory } from "../../memory/buffer_memory.js";
|
|
7
|
+
test("Test SimpleSequentialChain example usage", async () => {
|
|
8
|
+
// This is an LLMChain to write a synopsis given a title of a play.
|
|
9
|
+
const llm = new OpenAI({ temperature: 0 });
|
|
10
|
+
const template = `You are a playwright. Given the title of play, it is your job to write a synopsis for that title.
|
|
11
|
+
|
|
12
|
+
Title: {title}
|
|
13
|
+
Playwright: This is a synopsis for the above play:`;
|
|
14
|
+
const promptTemplate = new PromptTemplate({
|
|
15
|
+
template,
|
|
16
|
+
inputVariables: ["title"],
|
|
17
|
+
});
|
|
18
|
+
const synopsisChain = new LLMChain({ llm, prompt: promptTemplate });
|
|
19
|
+
// This is an LLMChain to write a review of a play given a synopsis.
|
|
20
|
+
const reviewLLM = new OpenAI({ temperature: 0 });
|
|
21
|
+
const reviewTemplate = `You are a play critic from the New York Times. Given the synopsis of play, it is your job to write a review for that play.
|
|
22
|
+
|
|
23
|
+
Play Synopsis:
|
|
24
|
+
{synopsis}
|
|
25
|
+
Review from a New York Times play critic of the above play:`;
|
|
26
|
+
const reviewPromptTemplate = new PromptTemplate({
|
|
27
|
+
template: reviewTemplate,
|
|
28
|
+
inputVariables: ["synopsis"],
|
|
29
|
+
});
|
|
30
|
+
const reviewChain = new LLMChain({
|
|
31
|
+
llm: reviewLLM,
|
|
32
|
+
prompt: reviewPromptTemplate,
|
|
33
|
+
});
|
|
34
|
+
const overallChain = new SimpleSequentialChain({
|
|
35
|
+
chains: [synopsisChain, reviewChain],
|
|
36
|
+
verbose: true,
|
|
37
|
+
});
|
|
38
|
+
const review = await overallChain.run("Tragedy at sunset on the beach");
|
|
39
|
+
expect(review.trim().toLowerCase()).toContain("tragedy at sunset on the beach");
|
|
40
|
+
});
|
|
41
|
+
test("Test SimpleSequentialChain example usage", async () => {
|
|
42
|
+
// This is an LLMChain to write a synopsis given a title of a play.
|
|
43
|
+
const llm = new ChatOpenAI({ temperature: 0 });
|
|
44
|
+
const template = `You are a playwright. Given the title of play, it is your job to write a synopsis for that title.
|
|
45
|
+
|
|
46
|
+
{history}
|
|
47
|
+
Title: {title}
|
|
48
|
+
Playwright: This is a synopsis for the above play:`;
|
|
49
|
+
const promptTemplate = new PromptTemplate({
|
|
50
|
+
template,
|
|
51
|
+
inputVariables: ["title", "history"],
|
|
52
|
+
});
|
|
53
|
+
const synopsisChain = new LLMChain({
|
|
54
|
+
llm,
|
|
55
|
+
prompt: promptTemplate,
|
|
56
|
+
memory: new BufferMemory(),
|
|
57
|
+
});
|
|
58
|
+
// This is an LLMChain to write a review of a play given a synopsis.
|
|
59
|
+
const reviewLLM = new ChatOpenAI({ temperature: 0 });
|
|
60
|
+
const reviewTemplate = `You are a play critic from the New York Times. Given the synopsis of play, it is your job to write a review for that play.
|
|
61
|
+
|
|
62
|
+
Play Synopsis:
|
|
63
|
+
{synopsis}
|
|
64
|
+
Review from a New York Times play critic of the above play:`;
|
|
65
|
+
const reviewPromptTemplate = new PromptTemplate({
|
|
66
|
+
template: reviewTemplate,
|
|
67
|
+
inputVariables: ["synopsis"],
|
|
68
|
+
});
|
|
69
|
+
const reviewChain = new LLMChain({
|
|
70
|
+
llm: reviewLLM,
|
|
71
|
+
prompt: reviewPromptTemplate,
|
|
72
|
+
});
|
|
73
|
+
const overallChain = new SimpleSequentialChain({
|
|
74
|
+
chains: [synopsisChain, reviewChain],
|
|
75
|
+
verbose: true,
|
|
76
|
+
});
|
|
77
|
+
await expect(() => overallChain.call({
|
|
78
|
+
input: "Tragedy at sunset on the beach",
|
|
79
|
+
signal: AbortSignal.timeout(1000),
|
|
80
|
+
})).rejects.toThrow("AbortError");
|
|
81
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { test, expect } from "@jest/globals";
|
|
2
|
+
import { BaseLLM } from "@langchain/core/language_models/llms";
|
|
3
|
+
import { PromptTemplate } from "@langchain/core/prompts";
|
|
4
|
+
import { VectorStoreRetriever } from "@langchain/core/vectorstores";
|
|
5
|
+
import { FakeEmbeddings } from "@langchain/core/utils/testing";
|
|
6
|
+
import { LLMChain } from "../llm_chain.js";
|
|
7
|
+
import { SimpleSequentialChain } from "../sequential_chain.js";
|
|
8
|
+
import { AnalyzeDocumentChain } from "../analyze_documents_chain.js";
|
|
9
|
+
import { ConversationalRetrievalQAChain } from "../conversational_retrieval_chain.js";
|
|
10
|
+
import { MemoryVectorStore } from "../../vectorstores/memory.js";
|
|
11
|
+
class FakeLLM1 extends BaseLLM {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
Object.defineProperty(this, "nrMapCalls", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: 0
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "nrReduceCalls", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: 0
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
_llmType() {
|
|
28
|
+
return "fake_1";
|
|
29
|
+
}
|
|
30
|
+
async _generate(_prompts) {
|
|
31
|
+
return {
|
|
32
|
+
generations: [
|
|
33
|
+
[
|
|
34
|
+
{
|
|
35
|
+
text: "The answer is XXX.",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
class FakeLLM2 extends BaseLLM {
|
|
43
|
+
constructor() {
|
|
44
|
+
super(...arguments);
|
|
45
|
+
Object.defineProperty(this, "nrMapCalls", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: 0
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(this, "nrReduceCalls", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: 0
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
_llmType() {
|
|
59
|
+
return "fake_2";
|
|
60
|
+
}
|
|
61
|
+
async _generate(prompts) {
|
|
62
|
+
let response = "I don't know what you are talking about.";
|
|
63
|
+
if (prompts[0].includes("XXX")) {
|
|
64
|
+
response = "final answer";
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
generations: [
|
|
68
|
+
[
|
|
69
|
+
{
|
|
70
|
+
text: response,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
test("Test SimpleSequentialChain", async () => {
|
|
78
|
+
const model1 = new FakeLLM1({});
|
|
79
|
+
const model2 = new FakeLLM2({});
|
|
80
|
+
const template = "Some arbitrary template with fake {input}.";
|
|
81
|
+
const prompt = new PromptTemplate({ template, inputVariables: ["input"] });
|
|
82
|
+
const chain1 = new LLMChain({ llm: model1, prompt });
|
|
83
|
+
const chain2 = new LLMChain({ llm: model2, prompt });
|
|
84
|
+
const combinedChain = new SimpleSequentialChain({ chains: [chain1, chain2] });
|
|
85
|
+
const response = await combinedChain.run("initial question");
|
|
86
|
+
expect(response).toEqual("final answer");
|
|
87
|
+
});
|
|
88
|
+
test("Test SimpleSequentialChain input chains' single input validation", async () => {
|
|
89
|
+
const model1 = new FakeLLM1({});
|
|
90
|
+
const model2 = new FakeLLM2({});
|
|
91
|
+
const template = "Some arbitrary template with fake {input1} and {input2}.";
|
|
92
|
+
const prompt = new PromptTemplate({
|
|
93
|
+
template,
|
|
94
|
+
inputVariables: ["input1", "input2"],
|
|
95
|
+
});
|
|
96
|
+
const chain1 = new LLMChain({ llm: model1, prompt });
|
|
97
|
+
const chain2 = new LLMChain({ llm: model2, prompt });
|
|
98
|
+
expect(() => {
|
|
99
|
+
/* eslint-disable no-new */
|
|
100
|
+
new SimpleSequentialChain({ chains: [chain1, chain2] });
|
|
101
|
+
}).toThrowErrorMatchingInlineSnapshot(`"Chains used in SimpleSequentialChain should all have one input, got 2 for llm."`);
|
|
102
|
+
});
|
|
103
|
+
test("Test SimpleSequentialChain input chains' single ouput validation", async () => {
|
|
104
|
+
const model1 = new FakeLLM1({});
|
|
105
|
+
const fakeEmbeddings = new FakeEmbeddings();
|
|
106
|
+
const anyStore = new MemoryVectorStore(fakeEmbeddings);
|
|
107
|
+
const retriever = new VectorStoreRetriever({
|
|
108
|
+
vectorStore: anyStore,
|
|
109
|
+
});
|
|
110
|
+
const template = "Some arbitrary template with fake {input}.";
|
|
111
|
+
const prompt = new PromptTemplate({ template, inputVariables: ["input"] });
|
|
112
|
+
const chain1 = new LLMChain({ llm: model1, prompt });
|
|
113
|
+
const chain2 = new ConversationalRetrievalQAChain({
|
|
114
|
+
retriever,
|
|
115
|
+
combineDocumentsChain: chain1,
|
|
116
|
+
questionGeneratorChain: chain1,
|
|
117
|
+
returnSourceDocuments: true,
|
|
118
|
+
});
|
|
119
|
+
// Chain below is is not meant to work in a real-life scenario.
|
|
120
|
+
// It's only combined this way to get one input/multiple outputs chain.
|
|
121
|
+
const multipleOutputChain = new AnalyzeDocumentChain({
|
|
122
|
+
combineDocumentsChain: chain2,
|
|
123
|
+
});
|
|
124
|
+
expect(() => {
|
|
125
|
+
/* eslint-disable no-new */
|
|
126
|
+
new SimpleSequentialChain({ chains: [chain1, multipleOutputChain] });
|
|
127
|
+
}).toThrowErrorMatchingInlineSnapshot(`"Chains used in SimpleSequentialChain should all have one output, got 2 for analyze_document_chain."`);
|
|
128
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|