langchain 0.2.2 → 0.2.3
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/sql_utils.cjs +2 -1
- package/dist/util/sql_utils.js +2 -1
- 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 +4 -8
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { expect, test } from "@jest/globals";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { OpenAI, ChatOpenAI } from "@langchain/openai";
|
|
4
|
+
import { ChatPromptTemplate, PromptTemplate, SystemMessagePromptTemplate, } from "@langchain/core/prompts";
|
|
5
|
+
import { LLMChain } from "../../chains/index.js";
|
|
6
|
+
import { StructuredOutputParser } from "../structured.js";
|
|
7
|
+
test("StructuredOutputParser deals special chars in prompt with llm model", async () => {
|
|
8
|
+
const model = new OpenAI({
|
|
9
|
+
temperature: 0,
|
|
10
|
+
});
|
|
11
|
+
const parser = StructuredOutputParser.fromNamesAndDescriptions({
|
|
12
|
+
question1: "a very on-topic question",
|
|
13
|
+
question2: "a super weird question",
|
|
14
|
+
question3: "an on-topic, but slightly creative",
|
|
15
|
+
});
|
|
16
|
+
const prompt = new PromptTemplate({
|
|
17
|
+
template: "context:\n{context}\n---{format_instructions}",
|
|
18
|
+
inputVariables: ["context"],
|
|
19
|
+
partialVariables: {
|
|
20
|
+
format_instructions: parser.getFormatInstructions(),
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
const chain = new LLMChain({
|
|
24
|
+
llm: model,
|
|
25
|
+
prompt,
|
|
26
|
+
outputParser: parser,
|
|
27
|
+
outputKey: "questions",
|
|
28
|
+
});
|
|
29
|
+
const result = await chain.call({
|
|
30
|
+
context: `The U2 ur-myth begins in 1976, when drummer Larry Mullen wanted to form a band.
|
|
31
|
+
He picked four school friends from Mount Temple Comprehensive School in Dublin.
|
|
32
|
+
“Larry formed U2,” says Paul McGuinness, U2’s manager from the beginning. “He
|
|
33
|
+
auditioned the other three and he chose them. The first name of U2 was the Larry
|
|
34
|
+
Mullen band,” McGuinness laughs. “And he never lets us forget it.” `,
|
|
35
|
+
});
|
|
36
|
+
console.log("response", result);
|
|
37
|
+
expect(result.questions).toHaveProperty("question1");
|
|
38
|
+
expect(result.questions).toHaveProperty("question2");
|
|
39
|
+
expect(result.questions).toHaveProperty("question3");
|
|
40
|
+
});
|
|
41
|
+
test("StructuredOutputParser deals special chars in prompt with chat model", async () => {
|
|
42
|
+
const model = new ChatOpenAI({
|
|
43
|
+
temperature: 0,
|
|
44
|
+
});
|
|
45
|
+
const parser = StructuredOutputParser.fromNamesAndDescriptions({
|
|
46
|
+
question1: "a very on-topic question",
|
|
47
|
+
question2: "a super weird question",
|
|
48
|
+
question3: "an on-topic, but slightly creative",
|
|
49
|
+
});
|
|
50
|
+
const prompt = new ChatPromptTemplate({
|
|
51
|
+
promptMessages: [
|
|
52
|
+
SystemMessagePromptTemplate.fromTemplate("context:\n{context}\n---"),
|
|
53
|
+
SystemMessagePromptTemplate.fromTemplate(`{format_instructions}`),
|
|
54
|
+
],
|
|
55
|
+
inputVariables: ["context"],
|
|
56
|
+
partialVariables: {
|
|
57
|
+
format_instructions: parser.getFormatInstructions(),
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
const chain = new LLMChain({
|
|
61
|
+
llm: model,
|
|
62
|
+
prompt,
|
|
63
|
+
outputParser: parser,
|
|
64
|
+
outputKey: "questions",
|
|
65
|
+
});
|
|
66
|
+
const result = await chain.call({
|
|
67
|
+
context: `The U2 ur-myth begins in 1976, when drummer Larry Mullen wanted to form a band.
|
|
68
|
+
He picked four school friends from Mount Temple Comprehensive School in Dublin.
|
|
69
|
+
“Larry formed U2,” says Paul McGuinness, U2’s manager from the beginning. “He
|
|
70
|
+
auditioned the other three and he chose them. The first name of U2 was the Larry
|
|
71
|
+
Mullen band,” McGuinness laughs. “And he never lets us forget it.” `,
|
|
72
|
+
});
|
|
73
|
+
console.log("response", result);
|
|
74
|
+
expect(result.questions).toHaveProperty("question1");
|
|
75
|
+
expect(result.questions).toHaveProperty("question2");
|
|
76
|
+
expect(result.questions).toHaveProperty("question3");
|
|
77
|
+
});
|
|
78
|
+
test("StructuredOutputParser deals special chars in prompt with chat model 2", async () => {
|
|
79
|
+
const model = new ChatOpenAI({
|
|
80
|
+
temperature: 0,
|
|
81
|
+
});
|
|
82
|
+
const parser = StructuredOutputParser.fromNamesAndDescriptions({
|
|
83
|
+
question1: "a very on-topic question",
|
|
84
|
+
question2: "a super weird question",
|
|
85
|
+
question3: "an on-topic, but slightly creative",
|
|
86
|
+
});
|
|
87
|
+
const prompt = new ChatPromptTemplate({
|
|
88
|
+
promptMessages: [
|
|
89
|
+
SystemMessagePromptTemplate.fromTemplate("context:\n{context}\n---"),
|
|
90
|
+
SystemMessagePromptTemplate.fromTemplate(`{format_instructions}`),
|
|
91
|
+
],
|
|
92
|
+
inputVariables: ["context"],
|
|
93
|
+
partialVariables: {
|
|
94
|
+
format_instructions: parser.getFormatInstructions(),
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
const chain = new LLMChain({
|
|
98
|
+
llm: model,
|
|
99
|
+
prompt,
|
|
100
|
+
outputKey: "questions",
|
|
101
|
+
});
|
|
102
|
+
const result = await chain.call({
|
|
103
|
+
context: `The U2 ur-myth begins in 1976, when drummer Larry Mullen wanted to form a band.
|
|
104
|
+
He picked four school friends from Mount Temple Comprehensive School in Dublin.
|
|
105
|
+
“Larry formed U2,” says Paul McGuinness, U2’s manager from the beginning. “He
|
|
106
|
+
auditioned the other three and he chose them. The first name of U2 was the Larry
|
|
107
|
+
Mullen band,” McGuinness laughs. “And he never lets us forget it.” `,
|
|
108
|
+
});
|
|
109
|
+
console.log("response", result);
|
|
110
|
+
const parsed = await parser.parse(result.questions);
|
|
111
|
+
expect(parsed).toHaveProperty("question1");
|
|
112
|
+
expect(parsed).toHaveProperty("question2");
|
|
113
|
+
expect(parsed).toHaveProperty("question3");
|
|
114
|
+
});
|
|
115
|
+
test("StructuredOutputParser handles a longer and more complex schema", async () => {
|
|
116
|
+
const parser = StructuredOutputParser.fromZodSchema(z.object({
|
|
117
|
+
name: z.string().describe("Human name"),
|
|
118
|
+
surname: z.string().describe("Human surname"),
|
|
119
|
+
age: z.number().describe("Human age"),
|
|
120
|
+
appearance: z.string().describe("Human appearance description"),
|
|
121
|
+
shortBio: z.string().describe("Short bio secription"),
|
|
122
|
+
university: z.string().optional().describe("University name if attended"),
|
|
123
|
+
gender: z.string().describe("Gender of the human"),
|
|
124
|
+
interests: z
|
|
125
|
+
.array(z.string())
|
|
126
|
+
.describe("json array of strings human interests"),
|
|
127
|
+
}));
|
|
128
|
+
const formatInstructions = parser.getFormatInstructions();
|
|
129
|
+
const prompt = new PromptTemplate({
|
|
130
|
+
template: "Generate details of a hypothetical person.\n{format_instructions}\nPerson description: {inputText}",
|
|
131
|
+
inputVariables: ["inputText"],
|
|
132
|
+
partialVariables: { format_instructions: formatInstructions },
|
|
133
|
+
});
|
|
134
|
+
const model = new OpenAI({ temperature: 0.5, modelName: "gpt-3.5-turbo" });
|
|
135
|
+
const input = await prompt.format({
|
|
136
|
+
inputText: "A man, living in Poland.",
|
|
137
|
+
});
|
|
138
|
+
const response = await model.invoke(input);
|
|
139
|
+
console.log("response", response);
|
|
140
|
+
const parsed = await parser.parse(response);
|
|
141
|
+
expect(parsed).toHaveProperty("name");
|
|
142
|
+
expect(parsed).toHaveProperty("surname");
|
|
143
|
+
expect(parsed).toHaveProperty("age");
|
|
144
|
+
expect(parsed).toHaveProperty("appearance");
|
|
145
|
+
expect(parsed).toHaveProperty("shortBio");
|
|
146
|
+
expect(parsed).toHaveProperty("age");
|
|
147
|
+
expect(parsed).toHaveProperty("gender");
|
|
148
|
+
expect(parsed).toHaveProperty("interests");
|
|
149
|
+
expect(parsed.interests.length).toBeGreaterThan(0);
|
|
150
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { expect, test } from "@jest/globals";
|
|
2
|
+
import { LengthBasedExampleSelector, SemanticSimilarityExampleSelector, } from "@langchain/core/example_selectors";
|
|
3
|
+
import { PromptTemplate } from "@langchain/core/prompts";
|
|
4
|
+
import { FakeEmbeddings } from "@langchain/core/utils/testing";
|
|
5
|
+
import { MemoryVectorStore } from "../../vectorstores/memory.js";
|
|
6
|
+
test("Test using LengthBasedExampleSelector", async () => {
|
|
7
|
+
const prompt = new PromptTemplate({
|
|
8
|
+
template: "{foo} {bar}",
|
|
9
|
+
inputVariables: ["foo"],
|
|
10
|
+
partialVariables: { bar: "baz" },
|
|
11
|
+
});
|
|
12
|
+
const selector = await LengthBasedExampleSelector.fromExamples([{ foo: "one one one" }], {
|
|
13
|
+
examplePrompt: prompt,
|
|
14
|
+
maxLength: 10,
|
|
15
|
+
});
|
|
16
|
+
await selector.addExample({ foo: "one two three" });
|
|
17
|
+
await selector.addExample({ foo: "four five six" });
|
|
18
|
+
await selector.addExample({ foo: "seven eight nine" });
|
|
19
|
+
await selector.addExample({ foo: "ten eleven twelve" });
|
|
20
|
+
const chosen = await selector.selectExamples({ foo: "hello", bar: "world" });
|
|
21
|
+
expect(chosen).toStrictEqual([
|
|
22
|
+
{ foo: "one one one" },
|
|
23
|
+
{ foo: "one two three" },
|
|
24
|
+
]);
|
|
25
|
+
});
|
|
26
|
+
test("Test using SemanticSimilarityExampleSelector", async () => {
|
|
27
|
+
const vectorStore = await MemoryVectorStore.fromTexts(["Hello world", "Bye bye", "hello nice world", "bye", "hi"], [{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }, { id: 5 }], new FakeEmbeddings() // not using OpenAIEmbeddings() because would be extra dependency
|
|
28
|
+
);
|
|
29
|
+
const selector = new SemanticSimilarityExampleSelector({
|
|
30
|
+
vectorStore,
|
|
31
|
+
});
|
|
32
|
+
const chosen = await selector.selectExamples({ id: 1 });
|
|
33
|
+
expect(chosen).toEqual([{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }]);
|
|
34
|
+
});
|
|
35
|
+
test("Test using SemanticSimilarityExampleSelector with metadata filtering", async () => {
|
|
36
|
+
const vectorStore = await MemoryVectorStore.fromTexts(["Hello world", "Bye bye", "hello nice world", "bye", "hi"], [{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }, { id: 5 }], new FakeEmbeddings() // not using OpenAIEmbeddings() because would be extra dependency
|
|
37
|
+
);
|
|
38
|
+
const selector = new SemanticSimilarityExampleSelector({
|
|
39
|
+
vectorStore,
|
|
40
|
+
filter: (doc) => doc.metadata.id === 2,
|
|
41
|
+
});
|
|
42
|
+
const chosen = await selector.selectExamples({ id: 1 });
|
|
43
|
+
expect(chosen).toEqual([{ id: 2 }]);
|
|
44
|
+
});
|
|
45
|
+
test("Test using SemanticSimilarityExampleSelector with a passed in retriever", async () => {
|
|
46
|
+
const vectorStore = await MemoryVectorStore.fromTexts(["Hello world", "Bye bye", "hello nice world", "bye", "hi"], [{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }, { id: 5 }], new FakeEmbeddings() // not using OpenAIEmbeddings() because would be extra dependency
|
|
47
|
+
);
|
|
48
|
+
const selector = new SemanticSimilarityExampleSelector({
|
|
49
|
+
vectorStoreRetriever: vectorStore.asRetriever({ k: 5 }),
|
|
50
|
+
});
|
|
51
|
+
const chosen = await selector.selectExamples({ id: 1 });
|
|
52
|
+
expect(chosen).toEqual([
|
|
53
|
+
{ id: 2 },
|
|
54
|
+
{ id: 1 },
|
|
55
|
+
{ id: 3 },
|
|
56
|
+
{ id: 4 },
|
|
57
|
+
{ id: 5 },
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { test } from "@jest/globals";
|
|
2
|
+
import { Document } from "@langchain/core/documents";
|
|
3
|
+
import { OpenAIEmbeddings, OpenAI } from "@langchain/openai";
|
|
4
|
+
import { SelfQueryRetriever } from "../index.js";
|
|
5
|
+
import { FunctionalTranslator } from "../functional.js";
|
|
6
|
+
import { MemoryVectorStore } from "../../../vectorstores/memory.js";
|
|
7
|
+
test("Memory Vector Store Self Query Retriever Test", async () => {
|
|
8
|
+
const docs = [
|
|
9
|
+
new Document({
|
|
10
|
+
pageContent: "A bunch of scientists bring back dinosaurs and mayhem breaks loose",
|
|
11
|
+
metadata: { year: 1993, rating: 7.7, genre: "science fiction" },
|
|
12
|
+
}),
|
|
13
|
+
new Document({
|
|
14
|
+
pageContent: "Leo DiCaprio gets lost in a dream within a dream within a dream within a ...",
|
|
15
|
+
metadata: { year: 2010, director: "Christopher Nolan", rating: 8.2 },
|
|
16
|
+
}),
|
|
17
|
+
new Document({
|
|
18
|
+
pageContent: "A psychologist / detective gets lost in a series of dreams within dreams within dreams and Inception reused the idea",
|
|
19
|
+
metadata: { year: 2006, director: "Satoshi Kon", rating: 8.6 },
|
|
20
|
+
}),
|
|
21
|
+
new Document({
|
|
22
|
+
pageContent: "A bunch of normal-sized women are supremely wholesome and some men pine after them",
|
|
23
|
+
metadata: { year: 2019, director: "Greta Gerwig", rating: 8.3 },
|
|
24
|
+
}),
|
|
25
|
+
new Document({
|
|
26
|
+
pageContent: "Toys come alive and have a blast doing so",
|
|
27
|
+
metadata: { year: 1995, genre: "animated" },
|
|
28
|
+
}),
|
|
29
|
+
new Document({
|
|
30
|
+
pageContent: "Three men walk into the Zone, three men walk out of the Zone",
|
|
31
|
+
metadata: {
|
|
32
|
+
year: 1979,
|
|
33
|
+
director: "Andrei Tarkovsky",
|
|
34
|
+
genre: "science fiction",
|
|
35
|
+
rating: 9.9,
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
];
|
|
39
|
+
const attributeInfo = [
|
|
40
|
+
{
|
|
41
|
+
name: "genre",
|
|
42
|
+
description: "The genre of the movie",
|
|
43
|
+
type: "string or array of strings",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "year",
|
|
47
|
+
description: "The year the movie was released",
|
|
48
|
+
type: "number",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "director",
|
|
52
|
+
description: "The director of the movie",
|
|
53
|
+
type: "string",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "rating",
|
|
57
|
+
description: "The rating of the movie (1-10)",
|
|
58
|
+
type: "number",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "length",
|
|
62
|
+
description: "The length of the movie in minutes",
|
|
63
|
+
type: "number",
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
const embeddings = new OpenAIEmbeddings();
|
|
67
|
+
const llm = new OpenAI({
|
|
68
|
+
modelName: "gpt-3.5-turbo",
|
|
69
|
+
});
|
|
70
|
+
const documentContents = "Brief summary of a movie";
|
|
71
|
+
const vectorStore = await MemoryVectorStore.fromDocuments(docs, embeddings);
|
|
72
|
+
const selfQueryRetriever = SelfQueryRetriever.fromLLM({
|
|
73
|
+
llm,
|
|
74
|
+
vectorStore,
|
|
75
|
+
documentContents,
|
|
76
|
+
attributeInfo,
|
|
77
|
+
structuredQueryTranslator: new FunctionalTranslator(),
|
|
78
|
+
});
|
|
79
|
+
const query1 = await selfQueryRetriever.getRelevantDocuments("Which movies are less than 90 minutes?");
|
|
80
|
+
console.log(query1);
|
|
81
|
+
expect(query1.length).toEqual(0);
|
|
82
|
+
const query2 = await selfQueryRetriever.getRelevantDocuments("Which movies are rated higher than 8.5?");
|
|
83
|
+
console.log(query2);
|
|
84
|
+
expect(query2.length).toEqual(2);
|
|
85
|
+
const query3 = await selfQueryRetriever.getRelevantDocuments("Which movies are directed by Greta Gerwig?");
|
|
86
|
+
console.log(query3);
|
|
87
|
+
expect(query3.length).toEqual(1);
|
|
88
|
+
});
|
|
89
|
+
test("Memory Vector Store Self Query Retriever Test With Default Filter Or Merge Operator", async () => {
|
|
90
|
+
const docs = [
|
|
91
|
+
new Document({
|
|
92
|
+
pageContent: "A bunch of scientists bring back dinosaurs and mayhem breaks loose",
|
|
93
|
+
metadata: {
|
|
94
|
+
year: 1993,
|
|
95
|
+
rating: 7.7,
|
|
96
|
+
genre: "science fiction",
|
|
97
|
+
type: "movie",
|
|
98
|
+
},
|
|
99
|
+
}),
|
|
100
|
+
new Document({
|
|
101
|
+
pageContent: "Leo DiCaprio gets lost in a dream within a dream within a dream within a ...",
|
|
102
|
+
metadata: {
|
|
103
|
+
year: 2010,
|
|
104
|
+
director: "Christopher Nolan",
|
|
105
|
+
rating: 8.2,
|
|
106
|
+
type: "movie",
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
new Document({
|
|
110
|
+
pageContent: "A psychologist / detective gets lost in a series of dreams within dreams within dreams and Inception reused the idea",
|
|
111
|
+
metadata: {
|
|
112
|
+
year: 2006,
|
|
113
|
+
director: "Satoshi Kon",
|
|
114
|
+
rating: 8.6,
|
|
115
|
+
type: "movie",
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
new Document({
|
|
119
|
+
pageContent: "A bunch of normal-sized women are supremely wholesome and some men pine after them",
|
|
120
|
+
metadata: {
|
|
121
|
+
year: 2019,
|
|
122
|
+
director: "Greta Gerwig",
|
|
123
|
+
rating: 8.3,
|
|
124
|
+
type: "movie",
|
|
125
|
+
},
|
|
126
|
+
}),
|
|
127
|
+
new Document({
|
|
128
|
+
pageContent: "Toys come alive and have a blast doing so",
|
|
129
|
+
metadata: { year: 1995, genre: "animated", type: "movie" },
|
|
130
|
+
}),
|
|
131
|
+
new Document({
|
|
132
|
+
pageContent: "Three men walk into the Zone, three men walk out of the Zone",
|
|
133
|
+
metadata: {
|
|
134
|
+
year: 1979,
|
|
135
|
+
director: "Andrei Tarkovsky",
|
|
136
|
+
genre: "science fiction",
|
|
137
|
+
rating: 9.9,
|
|
138
|
+
type: "movie",
|
|
139
|
+
},
|
|
140
|
+
}),
|
|
141
|
+
new Document({
|
|
142
|
+
pageContent: "10x the previous gecs",
|
|
143
|
+
metadata: {
|
|
144
|
+
year: 2023,
|
|
145
|
+
title: "10000 gecs",
|
|
146
|
+
artist: "100 gecs",
|
|
147
|
+
rating: 9.9,
|
|
148
|
+
type: "album",
|
|
149
|
+
},
|
|
150
|
+
}),
|
|
151
|
+
];
|
|
152
|
+
const attributeInfo = [
|
|
153
|
+
{
|
|
154
|
+
name: "genre",
|
|
155
|
+
description: "The genre of the movie",
|
|
156
|
+
type: "string or array of strings",
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: "year",
|
|
160
|
+
description: "The year the movie was released",
|
|
161
|
+
type: "number",
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: "director",
|
|
165
|
+
description: "The director of the movie",
|
|
166
|
+
type: "string",
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
name: "rating",
|
|
170
|
+
description: "The rating of the movie (1-10)",
|
|
171
|
+
type: "number",
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: "length",
|
|
175
|
+
description: "The length of the movie in minutes",
|
|
176
|
+
type: "number",
|
|
177
|
+
},
|
|
178
|
+
];
|
|
179
|
+
const embeddings = new OpenAIEmbeddings();
|
|
180
|
+
const llm = new OpenAI({
|
|
181
|
+
modelName: "gpt-3.5-turbo",
|
|
182
|
+
});
|
|
183
|
+
const documentContents = "Brief summary of a movie";
|
|
184
|
+
const vectorStore = await MemoryVectorStore.fromDocuments(docs, embeddings);
|
|
185
|
+
const selfQueryRetriever = SelfQueryRetriever.fromLLM({
|
|
186
|
+
llm,
|
|
187
|
+
vectorStore,
|
|
188
|
+
documentContents,
|
|
189
|
+
attributeInfo,
|
|
190
|
+
structuredQueryTranslator: new FunctionalTranslator(),
|
|
191
|
+
searchParams: {
|
|
192
|
+
filter: (doc) => doc.metadata && doc.metadata.type === "movie",
|
|
193
|
+
mergeFiltersOperator: "or",
|
|
194
|
+
k: docs.length,
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
const query1 = await selfQueryRetriever.getRelevantDocuments("Which movies are less than 90 minutes?");
|
|
198
|
+
console.log(query1);
|
|
199
|
+
expect(query1.length).toEqual(6);
|
|
200
|
+
const query2 = await selfQueryRetriever.getRelevantDocuments("Which movies are rated higher than 8.5?");
|
|
201
|
+
console.log(query2);
|
|
202
|
+
expect(query2.length).toEqual(7);
|
|
203
|
+
const query3 = await selfQueryRetriever.getRelevantDocuments("Which movies are directed by Greta Gerwig?");
|
|
204
|
+
console.log(query3);
|
|
205
|
+
expect(query3.length).toEqual(6);
|
|
206
|
+
const query4 = await selfQueryRetriever.getRelevantDocuments("Awawawa au au au wawawawa hello?");
|
|
207
|
+
console.log(query4);
|
|
208
|
+
expect(query4.length).toEqual(6); // this one should return documents since default filter takes over
|
|
209
|
+
});
|
|
210
|
+
test("Memory Vector Store Self Query Retriever Test With Default Filter And Merge Operator", async () => {
|
|
211
|
+
const docs = [
|
|
212
|
+
new Document({
|
|
213
|
+
pageContent: "A bunch of scientists bring back dinosaurs and mayhem breaks loose",
|
|
214
|
+
metadata: {
|
|
215
|
+
year: 1993,
|
|
216
|
+
rating: 7.7,
|
|
217
|
+
genre: "science fiction",
|
|
218
|
+
type: "movie",
|
|
219
|
+
},
|
|
220
|
+
}),
|
|
221
|
+
new Document({
|
|
222
|
+
pageContent: "Leo DiCaprio gets lost in a dream within a dream within a dream within a ...",
|
|
223
|
+
metadata: {
|
|
224
|
+
year: 2010,
|
|
225
|
+
director: "Christopher Nolan",
|
|
226
|
+
rating: 8.2,
|
|
227
|
+
type: "movie",
|
|
228
|
+
},
|
|
229
|
+
}),
|
|
230
|
+
new Document({
|
|
231
|
+
pageContent: "A psychologist / detective gets lost in a series of dreams within dreams within dreams and Inception reused the idea",
|
|
232
|
+
metadata: {
|
|
233
|
+
year: 2006,
|
|
234
|
+
director: "Satoshi Kon",
|
|
235
|
+
rating: 8.6,
|
|
236
|
+
type: "movie",
|
|
237
|
+
},
|
|
238
|
+
}),
|
|
239
|
+
new Document({
|
|
240
|
+
pageContent: "A bunch of normal-sized women are supremely wholesome and some men pine after them",
|
|
241
|
+
metadata: {
|
|
242
|
+
year: 2019,
|
|
243
|
+
director: "Greta Gerwig",
|
|
244
|
+
rating: 8.3,
|
|
245
|
+
type: "movie",
|
|
246
|
+
},
|
|
247
|
+
}),
|
|
248
|
+
new Document({
|
|
249
|
+
pageContent: "Toys come alive and have a blast doing so",
|
|
250
|
+
metadata: { year: 1995, genre: "animated", type: "movie" },
|
|
251
|
+
}),
|
|
252
|
+
new Document({
|
|
253
|
+
pageContent: "Three men walk into the Zone, three men walk out of the Zone",
|
|
254
|
+
metadata: {
|
|
255
|
+
year: 1979,
|
|
256
|
+
director: "Andrei Tarkovsky",
|
|
257
|
+
genre: "science fiction",
|
|
258
|
+
rating: 9.9,
|
|
259
|
+
type: "movie",
|
|
260
|
+
},
|
|
261
|
+
}),
|
|
262
|
+
new Document({
|
|
263
|
+
pageContent: "10x the previous gecs",
|
|
264
|
+
metadata: {
|
|
265
|
+
year: 2023,
|
|
266
|
+
title: "10000 gecs",
|
|
267
|
+
artist: "100 gecs",
|
|
268
|
+
rating: 9.9,
|
|
269
|
+
type: "album",
|
|
270
|
+
},
|
|
271
|
+
}),
|
|
272
|
+
];
|
|
273
|
+
const attributeInfo = [
|
|
274
|
+
{
|
|
275
|
+
name: "genre",
|
|
276
|
+
description: "The genre of the movie",
|
|
277
|
+
type: "string or array of strings",
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
name: "year",
|
|
281
|
+
description: "The year the movie was released",
|
|
282
|
+
type: "number",
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: "director",
|
|
286
|
+
description: "The director of the movie",
|
|
287
|
+
type: "string",
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
name: "rating",
|
|
291
|
+
description: "The rating of the movie (1-10)",
|
|
292
|
+
type: "number",
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
name: "length",
|
|
296
|
+
description: "The length of the movie in minutes",
|
|
297
|
+
type: "number",
|
|
298
|
+
},
|
|
299
|
+
];
|
|
300
|
+
const embeddings = new OpenAIEmbeddings();
|
|
301
|
+
const llm = new OpenAI({
|
|
302
|
+
modelName: "gpt-3.5-turbo",
|
|
303
|
+
});
|
|
304
|
+
const documentContents = "Brief summary of a movie";
|
|
305
|
+
const vectorStore = await MemoryVectorStore.fromDocuments(docs, embeddings);
|
|
306
|
+
const selfQueryRetriever = SelfQueryRetriever.fromLLM({
|
|
307
|
+
llm,
|
|
308
|
+
vectorStore,
|
|
309
|
+
documentContents,
|
|
310
|
+
attributeInfo,
|
|
311
|
+
structuredQueryTranslator: new FunctionalTranslator(),
|
|
312
|
+
searchParams: {
|
|
313
|
+
filter: (doc) => doc.metadata && doc.metadata.type === "movie",
|
|
314
|
+
mergeFiltersOperator: "and",
|
|
315
|
+
k: docs.length,
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
const query1 = await selfQueryRetriever.getRelevantDocuments("Which movies are less than 90 minutes?");
|
|
319
|
+
console.log(query1);
|
|
320
|
+
expect(query1.length).toEqual(0);
|
|
321
|
+
const query2 = await selfQueryRetriever.getRelevantDocuments("Which movies are rated higher than 8.5?");
|
|
322
|
+
console.log(query2);
|
|
323
|
+
expect(query2.length).toEqual(2);
|
|
324
|
+
const query3 = await selfQueryRetriever.getRelevantDocuments("Which movies are directed by Greta Gerwig?");
|
|
325
|
+
console.log(query3);
|
|
326
|
+
expect(query3.length).toEqual(1);
|
|
327
|
+
const query4 = await selfQueryRetriever.getRelevantDocuments("Awawawa au au au wawawawa hello?");
|
|
328
|
+
console.log(query4);
|
|
329
|
+
expect(query4.length).toEqual(0); // this one should return documents since default filter takes over
|
|
330
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { test, expect } from "@jest/globals";
|
|
2
|
+
import { OpenAI, OpenAIEmbeddings } from "@langchain/openai";
|
|
3
|
+
import { PromptTemplate } from "@langchain/core/prompts";
|
|
4
|
+
import { LLMChain } from "../../chains/llm_chain.js";
|
|
5
|
+
import { StuffDocumentsChain } from "../../chains/combine_docs_chain.js";
|
|
6
|
+
import { ConversationalRetrievalQAChain } from "../../chains/conversational_retrieval_chain.js";
|
|
7
|
+
import { MemoryVectorStore } from "../../vectorstores/memory.js";
|
|
8
|
+
import { ContextualCompressionRetriever } from "../contextual_compression.js";
|
|
9
|
+
import { LLMChainExtractor } from "../document_compressors/chain_extract.js";
|
|
10
|
+
test("Test LLMChainExtractor", async () => {
|
|
11
|
+
const model = new OpenAI({ modelName: "gpt-3.5-turbo-instruct" });
|
|
12
|
+
const prompt = PromptTemplate.fromTemplate("Print {question}, and ignore {chat_history}");
|
|
13
|
+
const baseCompressor = LLMChainExtractor.fromLLM(model);
|
|
14
|
+
expect(baseCompressor).toBeDefined();
|
|
15
|
+
const retriever = new ContextualCompressionRetriever({
|
|
16
|
+
baseCompressor,
|
|
17
|
+
baseRetriever: await MemoryVectorStore.fromTexts(["Hello world", "Bye bye", "hello nice world", "bye", "hi"], [{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }, { id: 5 }], new OpenAIEmbeddings()).then((vectorStore) => vectorStore.asRetriever()),
|
|
18
|
+
});
|
|
19
|
+
const llmChain = new LLMChain({ prompt, llm: model });
|
|
20
|
+
const combineDocsChain = new StuffDocumentsChain({
|
|
21
|
+
llmChain,
|
|
22
|
+
documentVariableName: "foo",
|
|
23
|
+
});
|
|
24
|
+
const chain = new ConversationalRetrievalQAChain({
|
|
25
|
+
retriever,
|
|
26
|
+
combineDocumentsChain: combineDocsChain,
|
|
27
|
+
questionGeneratorChain: llmChain,
|
|
28
|
+
});
|
|
29
|
+
const res = await chain.call({ question: "foo", chat_history: "bar" });
|
|
30
|
+
expect(res.text.length).toBeGreaterThan(0);
|
|
31
|
+
console.log({ res });
|
|
32
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { expect, test } from "@jest/globals";
|
|
2
|
+
import { OpenAIEmbeddings, OpenAI } from "@langchain/openai";
|
|
3
|
+
import { Document } from "@langchain/core/documents";
|
|
4
|
+
import { MemoryVectorStore } from "../../vectorstores/memory.js";
|
|
5
|
+
import { HydeRetriever } from "../hyde.js";
|
|
6
|
+
test("Hyde retriever", async () => {
|
|
7
|
+
const embeddings = new OpenAIEmbeddings();
|
|
8
|
+
const vectorStore = new MemoryVectorStore(embeddings);
|
|
9
|
+
const llm = new OpenAI();
|
|
10
|
+
const retriever = new HydeRetriever({
|
|
11
|
+
vectorStore,
|
|
12
|
+
llm,
|
|
13
|
+
k: 1,
|
|
14
|
+
});
|
|
15
|
+
await vectorStore.addDocuments([
|
|
16
|
+
"My name is John.",
|
|
17
|
+
"My name is Bob.",
|
|
18
|
+
"My favourite food is pizza.",
|
|
19
|
+
"My favourite food is pasta.",
|
|
20
|
+
].map((pageContent) => new Document({ pageContent })));
|
|
21
|
+
const results = await retriever.getRelevantDocuments("What is my favourite food?");
|
|
22
|
+
expect(results.length).toBe(1);
|
|
23
|
+
console.log(results);
|
|
24
|
+
});
|
|
25
|
+
test("Hyde retriever with default prompt template", async () => {
|
|
26
|
+
const embeddings = new OpenAIEmbeddings();
|
|
27
|
+
const vectorStore = new MemoryVectorStore(embeddings);
|
|
28
|
+
const llm = new OpenAI();
|
|
29
|
+
const retriever = new HydeRetriever({
|
|
30
|
+
vectorStore,
|
|
31
|
+
llm,
|
|
32
|
+
k: 1,
|
|
33
|
+
promptTemplate: "websearch",
|
|
34
|
+
});
|
|
35
|
+
await vectorStore.addDocuments([
|
|
36
|
+
"My name is John.",
|
|
37
|
+
"My name is Bob.",
|
|
38
|
+
"My favourite food is pizza.",
|
|
39
|
+
"My favourite food is pasta.",
|
|
40
|
+
].map((pageContent) => new Document({ pageContent })));
|
|
41
|
+
const results = await retriever.getRelevantDocuments("What is my favourite food?");
|
|
42
|
+
expect(results.length).toBe(1);
|
|
43
|
+
console.log(results);
|
|
44
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|